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__ / "il2fb" / "commons" / "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="il2fb-commons", |
110
|
|
|
version=VERSION, |
|
|
|
|
111
|
|
|
description=( |
112
|
|
|
"Common helpers and data structures for projects related to " |
113
|
|
|
"«IL-2 Sturmovik: Forgotten Battles» flight simulator" |
114
|
|
|
), |
115
|
|
|
long_description=README, |
116
|
|
|
long_description_content_type="text/x-rst", |
117
|
|
|
keywords=[ |
118
|
|
|
"il2", "il-2", "fb", "forgotten battles", "commons", "commons", |
119
|
|
|
"structure", "structures", |
120
|
|
|
], |
121
|
|
|
license="MIT", |
122
|
|
|
url=f"https://github.com/IL2HorusTeam/il2fb-commons/tree/v{VERSION}", |
123
|
|
|
|
124
|
|
|
author="Oleksandr Oblovatnyi", |
125
|
|
|
author_email="[email protected]", |
126
|
|
|
|
127
|
|
|
packages=[ |
128
|
|
|
"il2fb.commons", |
129
|
|
|
], |
130
|
|
|
namespace_packages=[ |
131
|
|
|
"il2fb", |
132
|
|
|
], |
133
|
|
|
|
134
|
|
|
python_requires=">=3.8", |
135
|
|
|
dependency_links=list(set(itertools.chain( |
136
|
|
|
INSTALL_DEPENDENCIES, |
137
|
|
|
# SETUP_DEPENDENCIES, |
138
|
|
|
TEST_DEPENDENCIES, |
139
|
|
|
))), |
140
|
|
|
install_requires=INSTALL_REQUIREMENTS, |
141
|
|
|
# setup_requires=SETUP_REQUIREMENTS, |
142
|
|
|
tests_require=TEST_REQUIREMENTS, |
143
|
|
|
test_suite="tests", |
144
|
|
|
|
145
|
|
|
classifiers=[ |
146
|
|
|
"Development Status :: 5 - Production/Stable", |
147
|
|
|
"Intended Audience :: Developers", |
148
|
|
|
"License :: OSI Approved :: MIT License", |
149
|
|
|
"Natural Language :: English", |
150
|
|
|
"Operating System :: MacOS :: MacOS X", |
151
|
|
|
"Operating System :: Microsoft :: Windows", |
152
|
|
|
"Operating System :: POSIX", |
153
|
|
|
"Programming Language :: Python :: 3", |
154
|
|
|
"Topic :: Software Development :: Libraries", |
155
|
|
|
], |
156
|
|
|
|
157
|
|
|
options={ |
158
|
|
|
'egg_info': { |
159
|
|
|
'tag_build': BUILD_TAG, |
160
|
|
|
'tag_date': False, |
161
|
|
|
}, |
162
|
|
|
}, |
163
|
|
|
|
164
|
|
|
include_package_data=True, |
165
|
|
|
zip_safe=False, |
166
|
|
|
) |
167
|
|
|
|