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