-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_utils.py
50 lines (39 loc) · 1.47 KB
/
setup_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# -*- coding: utf-8 -*-
# pylint: disable=duplicate-code
# pylint: disable=duplicate-code
"""Lawrence McDaniel https://lawrencemcdaniel.com."""
import importlib.util
import os
import re
from typing import Dict
HERE = os.path.abspath(os.path.dirname(__file__))
PROJECT_ROOT = os.path.abspath(os.path.join(HERE, "grader"))
# allow setup.py to be run from any path
os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir)))
def load_version() -> Dict[str, str]:
"""Stringify the __version__ module."""
version_file_path = os.path.join(PROJECT_ROOT, "__version__.py")
spec = importlib.util.spec_from_file_location("__version__", version_file_path)
version_module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(version_module)
return version_module.__dict__
VERSION = load_version()
def get_semantic_version() -> str:
"""
Return the semantic version number.
Example valid values of __version__.py are:
0.1.17
0.1.17-next.1
0.1.17-next.2
0.1.17-next.123456
0.1.17-next-major.1
0.1.17-next-major.2
0.1.17-next-major.123456
Note:
- pypi does not allow semantic version numbers to contain a dash.
- pypi does not allow semantic version numbers to contain a 'v' prefix.
- pypi does not allow semantic version numbers to contain a 'next' suffix.
"""
version = VERSION["__version__"]
version = re.sub(r"-next\.\d+", "", version)
return re.sub(r"-next-major\.\d+", "", version)