setup   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 135
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 89
dl 0
loc 135
rs 10
c 0
b 0
f 0
wmc 12

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__ / "candv" / "version.py"
20
exec(compile(version_file_path.read_text(), 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()
69
70
STABLE_BRANCH_NAME  = "master"
71
CURRENT_COMMIT_HASH = maybe_get_current_commit_hash()
72
CURRENT_BRANCH_NAME = maybe_get_current_branch_name()
73
IS_CURRENT_BRANCH_STABLE = (CURRENT_BRANCH_NAME == STABLE_BRANCH_NAME)
74
BUILD_TAG = (
75
  f".{CURRENT_BRANCH_NAME}.{CURRENT_COMMIT_HASH}"
76
  if not IS_CURRENT_BRANCH_STABLE and CURRENT_COMMIT_HASH
77
  else ""
78
)
79
80
REQUIREMENTS_DIR_PATH = __here__ / "requirements"
81
82
INSTALL_REQUIREMENTS = parse_requirements(REQUIREMENTS_DIR_PATH / "dist.txt")
83
SETUP_REQUIREMENTS   = parse_requirements(REQUIREMENTS_DIR_PATH / "setup.txt")
84
TEST_REQUIREMENTS    = parse_requirements(REQUIREMENTS_DIR_PATH / "test.txt")
85
86
setup(
87
  name="candv",
88
  version=VERSION,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable VERSION does not seem to be defined.
Loading history...
89
  description=(
90
    "Constants and Values: create enum-like complext constants with the "
91
    "ability to attach arbitrary attributes to them, e.g. values, "
92
    "human-readable names, help texts and so on"
93
  ),
94
  long_description=README,
95
  long_description_content_type="text/x-rst",
96
  keywords=[
97
    "constants", "values", "structures", "choices", "enum",
98
  ],
99
  license="MIT",
100
  url=f"https://github.com/oblalex/candv/tree/v{VERSION}",
101
102
  author="Oleksandr Oblovatnyi",
103
  author_email="[email protected]",
104
105
  packages=[
106
    "candv",
107
  ],
108
109
  python_requires=">=3.7",
110
  install_requires=INSTALL_REQUIREMENTS,
111
  setup_requires=SETUP_REQUIREMENTS,
112
  tests_require=TEST_REQUIREMENTS,
113
  test_suite="tests",
114
115
  classifiers=[
116
    "Development Status :: 5 - Production/Stable",
117
    "Intended Audience :: Developers",
118
    "License :: OSI Approved :: MIT License",
119
    "Natural Language :: English",
120
    "Operating System :: MacOS :: MacOS X",
121
    "Operating System :: Microsoft :: Windows",
122
    "Operating System :: POSIX",
123
    "Programming Language :: Python :: 3",
124
    "Topic :: Software Development :: Libraries",
125
  ],
126
127
  options={
128
    'egg_info': {
129
      'tag_build': BUILD_TAG,
130
      'tag_date':  False,
131
    },
132
  },
133
134
  zip_safe=True,
135
)
136