Passed
Push — master ( 6f77b1...954ddf )
by Oleksandr
11:42
created
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__ / "verboselib" / "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
87
setup(
88
  name="verboselib",
89
  version=VERSION,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable VERSION does not seem to be defined.
Loading history...
90
  description="A little I18N framework for libraries and applications",
91
  long_description=README,
92
  long_description_content_type="text/x-rst",
93
  keywords=[
94
      "library", "l18n", "localization", "lazy", "string", "framework", "gettext",
95
  ],
96
  license="MIT",
97
  url=f"https://github.com/oblalex/verboselib/tree/v{VERSION}",
98
99
  author="Oleksandr Oblovatnyi",
100
  author_email="[email protected]",
101
102
  packages=[
103
    "verboselib",
104
    "verboselib.cli",
105
  ],
106
  entry_points={
107
    "console_scripts": [
108
      "verboselib = verboselib.cli.main:main",
109
    ],
110
  },
111
112
  python_requires=">=3.7",
113
  dependency_links=list(set(itertools.chain(
114
    TEST_DEPENDENCIES,
115
  ))),
116
  tests_require=TEST_REQUIREMENTS,
117
  test_suite="tests",
118
119
  classifiers=[
120
    "Development Status :: 5 - Production/Stable",
121
    "Intended Audience :: Developers",
122
    "License :: OSI Approved :: MIT License",
123
    "Natural Language :: English",
124
    "Operating System :: MacOS :: MacOS X",
125
    "Operating System :: Microsoft :: Windows",
126
    "Operating System :: POSIX",
127
    "Programming Language :: Python :: 3",
128
    "Topic :: Software Development :: Libraries",
129
  ],
130
131
  options={
132
    'egg_info': {
133
      'tag_build': BUILD_TAG,
134
      'tag_date':  False,
135
    },
136
  },
137
138
  zip_safe=True,
139
)
140