Passed
Branch master (0fb205)
by Oleksandr
03:17
created

setup.maybe_get_current_commit_hash()   A

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 2
rs 10
c 0
b 0
f 0
cc 1
nop 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 Tuple
12
13
14
__here__ = Path(__file__).absolute().parent
15
16
17
version_file_path = __here__ / "il2fb" / "commons" / "version.py"
18
exec(compile(version_file_path.read_text(), version_file_path, "exec"))
19
20
21
def maybe_get_shell_output(command: str) -> str:
22
  try:
23
    args = shlex.split(command)
24
    with open(os.devnull, "w") as devnull:
25
      return check_output(args, stderr=devnull).strip().decode()
26
  except Exception:
27
    pass
28
29
30
def maybe_get_current_branch_name() -> Optional[str]:
31
  return maybe_get_shell_output("git rev-parse --abbrev-ref HEAD")
32
33
34
def maybe_get_current_commit_hash() -> Optional[str]:
35
  return maybe_get_shell_output("git rev-parse --short HEAD")
36
37
38
def parse_requirements(file_path: Path) -> Tuple[List[str], List[str]]:
39
  requirements, dependencies = list(), list()
40
41
  with file_path.open("rt") as f:
42
    for line in f:
43
      line = line.strip()
44
45
      if not line or line.startswith("#"):
46
        continue
47
48
      if "://" in line:
49
        dependencies.append(line)
50
51
        line = line.split("#egg=", 1)[1]
52
        requirements.append(line)
53
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
61
      else:
62
        requirements.append(line)
63
64
  return requirements, dependencies
65
66
67
README = (__here__ / "README.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
# SETUP_REQUIREMENTS, SETUP_DEPENDENCIES = parse_requirements(
85
#   file_path=(REQUIREMENTS_DIR_PATH / "setup.txt"),
86
# )
87
TEST_REQUIREMENTS, TEST_DEPENDENCIES = parse_requirements(
88
  file_path=(REQUIREMENTS_DIR_PATH / "test.txt"),
89
)
90
91
setup(
92
  name="il2fb-commons",
93
  version=VERSION,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable VERSION does not seem to be defined.
Loading history...
94
  description=(
95
    "Common helpers and data structures for projects related to "
96
    "«IL-2 Sturmovik: Forgotten Battles» flight simulator"
97
  ),
98
  long_description=README,
99
  long_description_content_type="text/x-rst",
100
  keywords=[
101
    "il2", "il-2", "fb", "forgotten battles", "commons", "commons",
102
    "structure", "structures",
103
  ],
104
  license="MIT",
105
  url=f"https://github.com/IL2HorusTeam/il2fb-commons/tree/v{VERSION}",
106
107
  author="Oleksandr Oblovatnyi",
108
  author_email="[email protected]",
109
110
  packages=[
111
    "il2fb.commons",
112
  ],
113
  namespace_packages=[
114
    "il2fb",
115
  ],
116
117
  python_requires=">=3.8",
118
  dependency_links=list(set(itertools.chain(
119
    INSTALL_DEPENDENCIES,
120
    # SETUP_DEPENDENCIES,
121
    TEST_DEPENDENCIES,
122
  ))),
123
  install_requires=INSTALL_REQUIREMENTS,
124
  # setup_requires=SETUP_REQUIREMENTS,
125
  tests_require=TEST_REQUIREMENTS,
126
  test_suite="tests",
127
128
  classifiers=[
129
    "Development Status :: 5 - Production/Stable",
130
    "Intended Audience :: Developers",
131
    "License :: OSI Approved :: MIT License",
132
    "Natural Language :: English",
133
    "Operating System :: MacOS :: MacOS X",
134
    "Operating System :: Microsoft :: Windows",
135
    "Operating System :: POSIX",
136
    "Programming Language :: Python :: 3",
137
    "Topic :: Software Development :: Libraries",
138
  ],
139
140
  options={
141
    'egg_info': {
142
      'tag_build': BUILD_TAG,
143
      'tag_date':  False,
144
    },
145
  },
146
147
  include_package_data=True,
148
  zip_safe=False,
149
)
150