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