Passed
Push — master ( 8fb3c8...bc47d1 )
by Oleksandr
49s
created

setup   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 140
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 12
eloc 93
dl 0
loc 140
rs 10
c 0
b 0
f 0

4 Functions

Rating   Name   Duplication   Size   Complexity  
A maybe_get_shell_output() 0 7 3
A maybe_get_current_commit_hash() 0 2 1
B parse_requirements() 0 26 7
A maybe_get_current_branch_name() 0 2 1
1
import os
2
import shlex
3
import sys
4
5
if sys.version_info >= (3, 9):
6
  List  = list
7
else:
8
  from typing import List
9
10
from pathlib import Path
11
from setuptools import setup
12
from subprocess import check_output
13
from typing import Optional
14
15
16
__here__ = Path(__file__).absolute().parent
17
18
19
version_file_path = __here__ / "il2fb" / "regiments" / "version.py"
20
exec(compile(version_file_path.read_text(encoding="utf-8"), version_file_path, "exec"))
21
22
23
def maybe_get_shell_output(command: str) -> str:
24
  try:
25
    args = shlex.split(command)
26
    with open(os.devnull, "w") as devnull:
27
      return check_output(args, stderr=devnull).strip().decode()
28
  except Exception:
29
    pass
30
31
32
def maybe_get_current_branch_name() -> Optional[str]:
33
  return maybe_get_shell_output("git rev-parse --abbrev-ref HEAD")
34
35
36
def maybe_get_current_commit_hash() -> Optional[str]:
37
  return maybe_get_shell_output("git rev-parse --short HEAD")
38
39
40
def parse_requirements(file_path: Path) -> List[str]:
41
  requirements = list()
42
43
  if not file_path.exists():
44
    return requirements
45
46
  with file_path.open("rt") as f:
47
    for line in f:
48
      line = line.strip()
49
50
      # check if comment or empty
51
      if not line or line.startswith("#"):
52
        continue
53
54
      # check if is inclusion of other requirements file
55
      elif line.startswith("-r"):
56
        name = Path(line.split(" ", 1)[1])
57
        path = file_path.parent / name
58
        subrequirements = parse_requirements(path)
59
        requirements.extend(subrequirements)
60
61
      # assume standard requirement
62
      else:
63
        requirements.append(line)
64
65
  return requirements
66
67
68
README    = (__here__ / "README.rst"   ).read_text(encoding="utf-8")
69
CHANGELOG = (__here__ / "CHANGELOG.rst").read_text(encoding="utf-8")
70
71
STABLE_BRANCH_NAME  = "master"
72
CURRENT_COMMIT_HASH = maybe_get_current_commit_hash()
73
CURRENT_BRANCH_NAME = maybe_get_current_branch_name()
74
IS_CURRENT_BRANCH_STABLE = (CURRENT_BRANCH_NAME == STABLE_BRANCH_NAME)
75
BUILD_TAG = (
76
  f".{CURRENT_BRANCH_NAME}.{CURRENT_COMMIT_HASH}"
77
  if not IS_CURRENT_BRANCH_STABLE and CURRENT_COMMIT_HASH
78
  else ""
79
)
80
81
REQUIREMENTS_DIR_PATH = __here__ / "requirements"
82
83
INSTALL_REQUIREMENTS = parse_requirements(REQUIREMENTS_DIR_PATH / "dist.txt")
84
SETUP_REQUIREMENTS   = parse_requirements(REQUIREMENTS_DIR_PATH / "setup.txt")
85
TEST_REQUIREMENTS    = parse_requirements(REQUIREMENTS_DIR_PATH / "test.txt")
86
87
88
setup(
89
  name="il2fb-regiments",
90
  version=VERSION,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable VERSION does not seem to be defined.
Loading history...
91
  description=(
92
    "Access data about regiments from «IL-2 Sturmovik: Forgotten Battles» "
93
    "flight simulator"
94
  ),
95
  long_description=README + "\n\n" + CHANGELOG,
96
  long_description_content_type="text/x-rst",
97
  keywords=[
98
    "il2", "il-2", "fb", "forgotten battles", "regiments",
99
  ],
100
  license="MIT",
101
  url=f"https://github.com/IL2HorusTeam/il2fb-regiments/tree/v{VERSION}",
102
103
  author="Oleksandr Oblovatnyi",
104
  author_email="[email protected]",
105
106
  namespace_packages=[
107
    "il2fb",
108
  ],
109
  packages=[
110
    "il2fb.regiments",
111
  ],
112
  include_package_data=True,
113
114
  python_requires=">=3.8",
115
  install_requires=INSTALL_REQUIREMENTS,
116
  setup_requires=SETUP_REQUIREMENTS,
117
  tests_require=TEST_REQUIREMENTS,
118
  test_suite="tests",
119
120
  classifiers=[
121
    "Development Status :: 5 - Production/Stable",
122
    "Intended Audience :: Developers",
123
    "License :: OSI Approved :: MIT License",
124
    "Natural Language :: English",
125
    "Operating System :: MacOS :: MacOS X",
126
    "Operating System :: Microsoft :: Windows",
127
    "Operating System :: POSIX",
128
    "Programming Language :: Python :: 3",
129
    "Topic :: Software Development :: Libraries",
130
  ],
131
132
  options={
133
    'egg_info': {
134
      'tag_build': BUILD_TAG,
135
      'tag_date':  False,
136
    },
137
  },
138
139
  zip_safe=False,
140
)
141