Completed
Push — master ( f4c0a2...4a0808 )
by Oleksandr
03:35
created

setup.split_requirements()   A

Complexity

Conditions 3

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 9
nop 1
dl 0
loc 12
rs 9.95
c 0
b 0
f 0
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__ / "il2fb" / "regiments" / "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
CHANGELOG = (__here__ / "CHANGELOG.rst").read_text()
68
69
STABLE_BRANCH_NAME  = "master"
70
CURRENT_COMMIT_HASH = maybe_get_current_commit_hash()
71
CURRENT_BRANCH_NAME = maybe_get_current_branch_name()
72
IS_CURRENT_BRANCH_STABLE = (CURRENT_BRANCH_NAME == STABLE_BRANCH_NAME)
73
BUILD_TAG = (
74
  f".{CURRENT_BRANCH_NAME}.{CURRENT_COMMIT_HASH}"
75
  if not IS_CURRENT_BRANCH_STABLE and CURRENT_COMMIT_HASH
76
  else ""
77
)
78
79
REQUIREMENTS_DIR_PATH = __here__ / "requirements"
80
81
INSTALL_REQUIREMENTS, INSTALL_DEPENDENCIES = parse_requirements(
82
  file_path=(REQUIREMENTS_DIR_PATH / "dist.txt"),
83
)
84
TEST_REQUIREMENTS, TEST_DEPENDENCIES = parse_requirements(
85
  file_path=(REQUIREMENTS_DIR_PATH / "test.txt"),
86
)
87
88
89
setup(
90
  name="il2fb-regiments",
91
  version=VERSION,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable VERSION does not seem to be defined.
Loading history...
92
  description=(
93
    "Access data about regiments from «IL-2 Sturmovik: Forgotten Battles» "
94
    "flight simulator"
95
  ),
96
  long_description=README + "\n\n" + CHANGELOG,
97
  long_description_content_type="text/x-rst",
98
  keywords=[
99
    "il2", "il-2", "fb", "forgotten battles", "regiments",
100
  ],
101
  license="MIT",
102
  url=f"https://github.com/IL2HorusTeam/il2fb-regiments/tree/v{VERSION}",
103
104
  author="Oleksandr Oblovatnyi",
105
  author_email="[email protected]",
106
107
  packages=[
108
    "il2fb.regiments",
109
  ],
110
  namespace_packages=[
111
    "il2fb",
112
  ],
113
  include_package_data=True,
114
115
  python_requires=">=3.7",
116
  dependency_links=list(set(itertools.chain(
117
    INSTALL_DEPENDENCIES,
118
    TEST_DEPENDENCIES,
119
  ))),
120
  install_requires=INSTALL_REQUIREMENTS,
121
  tests_require=TEST_REQUIREMENTS,
122
  test_suite="tests",
123
124
  classifiers=[
125
    "Development Status :: 5 - Production/Stable",
126
    "Intended Audience :: Developers",
127
    "License :: OSI Approved :: MIT License",
128
    "Natural Language :: English",
129
    "Operating System :: MacOS :: MacOS X",
130
    "Operating System :: Microsoft :: Windows",
131
    "Operating System :: POSIX",
132
    "Programming Language :: Python :: 3.7",
133
    "Programming Language :: Python :: 3.8",
134
    "Topic :: Software Development :: Libraries",
135
  ],
136
137
  options={
138
    'egg_info': {
139
      'tag_build': BUILD_TAG,
140
      'tag_date':  False,
141
    },
142
  },
143
144
  zip_safe=False,
145
)
146