1 | import itertools |
||
2 | import os |
||
3 | import shlex |
||
4 | import sys |
||
5 | |||
6 | if sys.version_info >= (3, 9): |
||
7 | List = list |
||
8 | Tuple = tuple |
||
9 | else: |
||
10 | from typing import List |
||
11 | from typing import Tuple |
||
12 | |||
13 | from pathlib import Path |
||
14 | from setuptools import setup |
||
15 | from subprocess import check_output |
||
16 | from typing import Optional |
||
17 | |||
18 | |||
19 | __here__ = Path(__file__).absolute().parent |
||
20 | |||
21 | |||
22 | version_file_path = __here__ / "candv" / "version.py" |
||
23 | exec(compile(version_file_path.read_text(), version_file_path, "exec")) |
||
24 | |||
25 | |||
26 | def maybe_get_shell_output(command: str) -> str: |
||
27 | try: |
||
28 | args = shlex.split(command) |
||
29 | with open(os.devnull, "w") as devnull: |
||
30 | return check_output(args, stderr=devnull).strip().decode() |
||
31 | except Exception: |
||
32 | pass |
||
33 | |||
34 | |||
35 | def maybe_get_current_branch_name() -> Optional[str]: |
||
36 | return maybe_get_shell_output("git rev-parse --abbrev-ref HEAD") |
||
37 | |||
38 | |||
39 | def maybe_get_current_commit_hash() -> Optional[str]: |
||
40 | return maybe_get_shell_output("git rev-parse --short HEAD") |
||
41 | |||
42 | |||
43 | def parse_requirements(file_path: Path) -> Tuple[List[str], List[str]]: |
||
44 | requirements, dependencies = list(), list() |
||
45 | |||
46 | if not file_path.exists(): |
||
47 | return requirements, dependencies |
||
48 | |||
49 | with file_path.open("rt") as f: |
||
50 | for line in f: |
||
51 | line = line.strip() |
||
52 | |||
53 | # check if is comment or empty |
||
54 | if not line or line.startswith("#"): |
||
55 | continue |
||
56 | |||
57 | # check if is URL |
||
58 | if "://" in line: |
||
59 | dependencies.append(line) |
||
60 | |||
61 | egg = line.split("#egg=", 1)[1] |
||
62 | |||
63 | # check if version is specified |
||
64 | if "-" in egg: |
||
65 | egg = egg.rsplit("-", 1)[0] |
||
66 | |||
67 | requirements.append(egg) |
||
68 | |||
69 | # check if is inclusion of other requirements file |
||
70 | elif line.startswith("-r"): |
||
71 | name = Path(line.split(" ", 1)[1]) |
||
72 | path = file_path.parent / name |
||
73 | subrequirements, subdependencies = parse_requirements(path) |
||
74 | requirements.extend(subrequirements) |
||
75 | dependencies.extend(subdependencies) |
||
76 | |||
77 | # assume is a standard requirement |
||
78 | else: |
||
79 | requirements.append(line) |
||
80 | |||
81 | return requirements, dependencies |
||
82 | |||
83 | |||
84 | README = (__here__ / "README.rst").read_text() |
||
85 | |||
86 | STABLE_BRANCH_NAME = "master" |
||
87 | CURRENT_COMMIT_HASH = maybe_get_current_commit_hash() |
||
88 | CURRENT_BRANCH_NAME = maybe_get_current_branch_name() |
||
89 | IS_CURRENT_BRANCH_STABLE = (CURRENT_BRANCH_NAME == STABLE_BRANCH_NAME) |
||
90 | BUILD_TAG = ( |
||
91 | f".{CURRENT_BRANCH_NAME}.{CURRENT_COMMIT_HASH}" |
||
92 | if not IS_CURRENT_BRANCH_STABLE and CURRENT_COMMIT_HASH |
||
93 | else "" |
||
94 | ) |
||
95 | |||
96 | REQUIREMENTS_DIR_PATH = __here__ / "requirements" |
||
97 | |||
98 | INSTALL_REQUIREMENTS, INSTALL_DEPENDENCIES = parse_requirements( |
||
99 | file_path=(REQUIREMENTS_DIR_PATH / "dist.txt"), |
||
100 | ) |
||
101 | SETUP_REQUIREMENTS, SETUP_DEPENDENCIES = parse_requirements( |
||
102 | file_path=(REQUIREMENTS_DIR_PATH / "setup.txt"), |
||
103 | ) |
||
104 | TEST_REQUIREMENTS, TEST_DEPENDENCIES = parse_requirements( |
||
105 | file_path=(REQUIREMENTS_DIR_PATH / "test.txt"), |
||
106 | ) |
||
107 | |||
108 | setup( |
||
109 | name="candv", |
||
110 | version=VERSION, |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
![]() |
|||
111 | description=( |
||
112 | "Constants and Values: create enum-like complext constants with the " |
||
113 | "ability to attach arbitrary attributes to them, e.g. values, " |
||
114 | "human-readable names, help texts and so on" |
||
115 | ), |
||
116 | long_description=README, |
||
117 | long_description_content_type="text/x-rst", |
||
118 | keywords=[ |
||
119 | "constants", "values", "structures", "choices", "enum", |
||
120 | ], |
||
121 | license="MIT", |
||
122 | url=f"https://github.com/oblalex/candv/tree/v{VERSION}", |
||
123 | |||
124 | author="Oleksandr Oblovatnyi", |
||
125 | author_email="[email protected]", |
||
126 | |||
127 | packages=[ |
||
128 | "candv", |
||
129 | ], |
||
130 | |||
131 | python_requires=">=3.7", |
||
132 | dependency_links=list(set(itertools.chain( |
||
133 | INSTALL_DEPENDENCIES, |
||
134 | SETUP_DEPENDENCIES, |
||
135 | TEST_DEPENDENCIES, |
||
136 | ))), |
||
137 | install_requires=INSTALL_REQUIREMENTS, |
||
138 | setup_requires=SETUP_REQUIREMENTS, |
||
139 | tests_require=TEST_REQUIREMENTS, |
||
140 | test_suite="tests", |
||
141 | |||
142 | classifiers=[ |
||
143 | "Development Status :: 5 - Production/Stable", |
||
144 | "Intended Audience :: Developers", |
||
145 | "License :: OSI Approved :: MIT License", |
||
146 | "Natural Language :: English", |
||
147 | "Operating System :: MacOS :: MacOS X", |
||
148 | "Operating System :: Microsoft :: Windows", |
||
149 | "Operating System :: POSIX", |
||
150 | "Programming Language :: Python :: 3", |
||
151 | "Topic :: Software Development :: Libraries", |
||
152 | ], |
||
153 | |||
154 | options={ |
||
155 | 'egg_info': { |
||
156 | 'tag_build': BUILD_TAG, |
||
157 | 'tag_date': False, |
||
158 | }, |
||
159 | }, |
||
160 | |||
161 | zip_safe=True, |
||
162 | ) |
||
163 |