Completed
Branch master (77de8c)
by Oleksandr
01:17
created

setup.py (1 issue)

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__ / "candv" / "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[str], List[str]]:
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 "://" in line:
50
        dependencies.append(line)
51
52
        line = line.split("#egg=", 1)[1]
53
        requirements.append(line)
54
55
      elif line.startswith("-r"):
56
        name = Path(line.split(" ", 1)[1])
57
        path = file_path.parent / name
58
        subrequirements, subdependencies = parse_requirements(path)
59
        requirements.extend(subrequirements)
60
        dependencies.extend(subdependencies)
61
62
      else:
63
        requirements.append(line)
64
65
  return requirements, dependencies
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
TEST_REQUIREMENTS, TEST_DEPENDENCIES = parse_requirements(
83
  file_path=(REQUIREMENTS_DIR_PATH / "test.txt"),
84
)
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
  dependency_links=list(set(itertools.chain(
111
    TEST_DEPENDENCIES,
112
  ))),
113
  tests_require=TEST_REQUIREMENTS,
114
  test_suite="tests",
115
116
  classifiers=[
117
    "Development Status :: 5 - Production/Stable",
118
    "Intended Audience :: Developers",
119
    "License :: OSI Approved :: MIT License",
120
    "Natural Language :: English",
121
    "Operating System :: MacOS :: MacOS X",
122
    "Operating System :: Microsoft :: Windows",
123
    "Operating System :: POSIX",
124
    "Programming Language :: Python :: 3",
125
    "Topic :: Software Development :: Libraries",
126
  ],
127
128
  options={
129
    'egg_info': {
130
      'tag_build': BUILD_TAG,
131
      'tag_date':  False,
132
    },
133
  },
134
135
  zip_safe=True,
136
)
137