Passed
Push — master ( 82f1c1...e27252 )
by Oleksandr
46s
created

setup.py (1 issue)

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
15
from setuptools import setup
16
from subprocess import check_output
17
18
from typing import Optional
19
20
21
__here__ = Path(__file__).absolute().parent
22
23
24
version_file_path = __here__ / "verboselib" / "version.py"
25
exec(compile(version_file_path.read_text(), version_file_path, "exec"))
26
27
28
def maybe_get_shell_output(command: str) -> str:
29
  try:
30
    args = shlex.split(command)
31
    with open(os.devnull, "w") as devnull:
32
      return check_output(args, stderr=devnull).strip().decode()
33
  except Exception:
34
    pass
35
36
37
def maybe_get_current_branch_name() -> Optional[str]:
38
  return maybe_get_shell_output("git rev-parse --abbrev-ref HEAD")
39
40
41
def maybe_get_current_commit_hash() -> Optional[str]:
42
  return maybe_get_shell_output("git rev-parse --short HEAD")
43
44
45
def parse_requirements(file_path: Path) -> Tuple[List[str], List[str]]:
46
  requirements, dependencies = list(), list()
47
48
  with file_path.open("rt") as f:
49
    for line in f:
50
      line = line.strip()
51
52
      if not line or line.startswith("#"):
53
        continue
54
55
      if "://" in line:
56
        dependencies.append(line)
57
58
        line = line.split("#egg=", 1)[1]
59
        requirements.append(line)
60
61
      elif line.startswith("-r"):
62
        name = Path(line.split(" ", 1)[1])
63
        path = file_path.parent / name
64
        subrequirements, subdependencies = parse_requirements(path)
65
        requirements.extend(subrequirements)
66
        dependencies.extend(subdependencies)
67
68
      else:
69
        requirements.append(line)
70
71
  return requirements, dependencies
72
73
74
README = (__here__ / "README.rst").read_text()
75
76
STABLE_BRANCH_NAME  = "master"
77
CURRENT_COMMIT_HASH = maybe_get_current_commit_hash()
78
CURRENT_BRANCH_NAME = maybe_get_current_branch_name()
79
IS_CURRENT_BRANCH_STABLE = (CURRENT_BRANCH_NAME == STABLE_BRANCH_NAME)
80
BUILD_TAG = (
81
  f".{CURRENT_BRANCH_NAME}.{CURRENT_COMMIT_HASH}"
82
  if not IS_CURRENT_BRANCH_STABLE and CURRENT_COMMIT_HASH
83
  else ""
84
)
85
86
REQUIREMENTS_DIR_PATH = __here__ / "requirements"
87
88
INSTALL_REQUIREMENTS, INSTALL_DEPENDENCIES = parse_requirements(
89
  file_path=(REQUIREMENTS_DIR_PATH / "dist.txt"),
90
)
91
TEST_REQUIREMENTS, TEST_DEPENDENCIES = parse_requirements(
92
  file_path=(REQUIREMENTS_DIR_PATH / "test.txt"),
93
)
94
95
setup(
96
  name="verboselib",
97
  version=VERSION,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable VERSION does not seem to be defined.
Loading history...
98
  description="A little I18N framework for libraries and applications",
99
  long_description=README,
100
  long_description_content_type="text/x-rst",
101
  keywords=[
102
      "library", "l18n", "localization", "lazy", "string", "framework", "gettext",
103
  ],
104
  license="MIT",
105
  url=f"https://github.com/oblalex/verboselib/tree/v{VERSION}",
106
107
  author="Oleksandr Oblovatnyi",
108
  author_email="[email protected]",
109
110
  packages=[
111
    "verboselib",
112
    "verboselib.cli",
113
  ],
114
  entry_points={
115
    "console_scripts": [
116
      "verboselib = verboselib.cli.main:main",
117
    ],
118
  },
119
120
  python_requires=">=3.7",
121
  dependency_links=list(set(itertools.chain(
122
    INSTALL_DEPENDENCIES,
123
    TEST_DEPENDENCIES,
124
  ))),
125
  install_requires=INSTALL_REQUIREMENTS,
126
  tests_require=TEST_REQUIREMENTS,
127
  test_suite="tests",
128
129
  classifiers=[
130
    "Development Status :: 5 - Production/Stable",
131
    "Intended Audience :: Developers",
132
    "License :: OSI Approved :: MIT License",
133
    "Natural Language :: English",
134
    "Operating System :: MacOS :: MacOS X",
135
    "Operating System :: Microsoft :: Windows",
136
    "Operating System :: POSIX",
137
    "Programming Language :: Python :: 3",
138
    "Topic :: Software Development :: Libraries",
139
  ],
140
141
  options={
142
    'egg_info': {
143
      'tag_build': BUILD_TAG,
144
      'tag_date':  False,
145
    },
146
  },
147
148
  zip_safe=True,
149
)
150