-
Notifications
You must be signed in to change notification settings - Fork 5
/
setup.py
260 lines (229 loc) · 11 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import logging
import os
import sys
try:
from packaging.version import Version as LooseVersion
except ImportError:
from distutils.version import LooseVersion # pylint: disable=deprecated-module
try:
from setuptools import setup
except ImportError:
from distutils.core import setup # pylint: disable=deprecated-module
try:
# typing only available builtin starting with Python3
# cannot employ it during setup, but will be installed afterwards with backport
from typing import TYPE_CHECKING # noqa
if TYPE_CHECKING:
# pylint: disable=W0611,unused-import
from typing import Iterable, Set, Tuple, Union # noqa: F401
except ImportError:
pass
MAGPIE_ROOT = os.path.abspath(os.path.dirname(__file__))
MAGPIE_MODULE_DIR = os.path.join(MAGPIE_ROOT, "magpie")
sys.path.insert(0, MAGPIE_MODULE_DIR)
# do not use "from magpie" to avoid import error on not yet installed packages
import __meta__ # isort:skip # noqa: E402
LOGGER = logging.getLogger("magpie.setup")
if logging.StreamHandler not in LOGGER.handlers:
LOGGER.addHandler(logging.StreamHandler(sys.stdout)) # type: ignore # noqa
LOGGER.setLevel(logging.INFO)
LOGGER.info("starting setup")
with open("README.rst", mode="r", encoding="utf-8") as readme_file:
README = readme_file.read()
with open("CHANGES.rst", mode="r", encoding="utf-8") as changes_file:
CHANGES = changes_file.read().replace(".. :changelog:", "")
def _split_requirement(requirement, version=False, python=False, merge=False):
# type: (str, bool, bool, bool) -> Union[str, Tuple[str, str]]
"""
Splits a requirement package definition into it's name and version specification.
Returns the appropriate part(s) according to :paramref:`version`. If ``True``, returns the operator and version
string. The returned version in this case would be either the package's or the environment python's version string
according to the value of :paramref:`python`. Otherwise, only returns the 'other part' of the requirement, which
will be the plain package name without version or the complete ``package+version`` without ``python_version`` part.
Package requirement format::
package [<|<=|==|>|>=|!= x.y.z][; python_version <|<=|==|>|>=|!= "x.y.z"]
Returned values with provided arguments::
default: "<package>"
python=True n/a
version=True: ([pkg-op], [pkg-ver])
version=True,python=True: ([py-op], [py-ver])
version=True,merge=True: "<package> [pkg-op] [pkg-ver]"
version=True,python=True,merge=True: "[python_version] [py-op] [py-ver]"
:param requirement: full package string requirement.
:param version:
Retrieves the version operator and version number instead of only the package's name (without specifications).
:param python:
Retrieves the python operator and python version instead of the package's version.
Must be combined with :paramref:`version`, otherwise doesn't do anything.
:param merge:
Nothing done if ``False`` (other arguments behave normally).
If only :paramref:`version` is ``True``, merges the package name back with the version operator and number into
a single string (if any version part), but without the python version part (if any).
If both :paramref:`version` and :paramref:`python` are ``True`` combines back the part after ``;`` to form
the python version specifier.
:return: Extracted requirement part(s). Emtpy strings if parts cannot be found.
"""
idx_pyv = -1 if python else 0
if python and "python_version" not in requirement:
return ("", "") if version and not merge else ""
requirement = requirement.split("python_version")[idx_pyv].replace(";", "").replace("\"", "")
requirement = requirement.split(" #")[0] # ignore comments, space important because 'pkg#egg=' is valid
op_str = ""
pkg_name = requirement
for operator in [">=", ">", "<=", "<", "!=", "==", "="]:
if operator in requirement:
op_str = operator
pkg_name, requirement = requirement.split(operator, 1)
break
if not version:
return pkg_name.strip()
if op_str == "":
pkg_name = requirement
requirement = ""
parts = (op_str, requirement.strip())
if merge and python:
return "python_version {} \"{}\"".format(parts[0], parts[1])
if merge and version:
return "{}{}{}".format(pkg_name, parts[0], parts[1])
return parts
def _parse_requirements(file_path, requirements, links):
# type: (str, Set[str], Set[str]) -> None
"""
Parses a requirements file to extra packages and links.
If a python version specific is present, requirements are added only if they match the current environment.
:param file_path: file path to the requirements file.
:param requirements: pre-initialized set in which to store extracted package requirements.
:param links: pre-initialized set in which to store extracted link reference requirements.
:returns: None
"""
with open(file_path, mode="r", encoding="utf-8") as requirements_file:
for line in requirements_file:
# ignore empty line, comment line or reference to other requirements file (-r flag)
if not line or line.startswith("#") or line.startswith("-"):
continue
if "python_version" in line:
operator, py_ver = _split_requirement(line, version=True, python=True)
sys_ver = ".".join([str(part) for part in sys.version_info[:3]])
op_map = {
"==": LooseVersion(sys_ver) == LooseVersion(py_ver),
">=": LooseVersion(sys_ver) >= LooseVersion(py_ver),
"<=": LooseVersion(sys_ver) <= LooseVersion(py_ver),
"!=": LooseVersion(sys_ver) != LooseVersion(py_ver),
">": LooseVersion(sys_ver) > LooseVersion(py_ver),
"<": LooseVersion(sys_ver) < LooseVersion(py_ver),
}
# skip requirement if not fulfilling python version
if not op_map[operator]:
continue
# remove only python part if any present
line = _split_requirement(line, version=True, merge=True)
if "git+https" in line:
pkg = line.split("#")[-1]
links.add(line.strip())
requirements.add(pkg.replace("egg=", "").rstrip())
elif line.startswith("http"):
links.add(line.strip())
else:
requirements.add(line.strip())
def _extra_requirements(base_requirements, other_requirements):
# type: (Iterable[str], Iterable[str]) -> Set[str]
"""
Extracts only the extra requirements not already defined within the base requirements.
:param base_requirements: base package requirements.
:param other_requirements: other set of requirements referring to additional dependencies.
"""
raw_requirements = set()
for req in base_requirements:
raw_req = _split_requirement(req, version=True, merge=True)
raw_requirements.add(raw_req)
filtered_requirements = set()
for req in other_requirements:
raw_req = _split_requirement(req, version=True, merge=True)
if raw_req and raw_req not in raw_requirements:
filtered_requirements.add(req)
return filtered_requirements
LOGGER.info("reading requirements")
# See https://github.com/pypa/pip/issues/3610
# use set to have unique packages by name
LINKS = set()
REQUIREMENTS = set()
DOCS_REQUIREMENTS = set()
TEST_REQUIREMENTS = set()
_parse_requirements("requirements.txt", REQUIREMENTS, LINKS)
_parse_requirements("requirements-doc.txt", DOCS_REQUIREMENTS, LINKS)
_parse_requirements("requirements-dev.txt", TEST_REQUIREMENTS, LINKS)
LINKS = list(LINKS)
REQUIREMENTS = list(REQUIREMENTS)
DOCS_REQUIREMENTS = list(_extra_requirements(REQUIREMENTS, DOCS_REQUIREMENTS))
TEST_REQUIREMENTS = list(_extra_requirements(REQUIREMENTS, TEST_REQUIREMENTS))
LOGGER.info("base requirements: %s", REQUIREMENTS)
LOGGER.info("docs requirements: %s", DOCS_REQUIREMENTS)
LOGGER.info("test requirements: %s", TEST_REQUIREMENTS)
LOGGER.info("link requirements: %s", LINKS)
setup(
# -- meta information --------------------------------------------------
name=__meta__.__package__,
version=__meta__.__version__,
description=__meta__.__description__,
long_description=README + "\n\n" + CHANGES,
author=__meta__.__author__,
maintainer=__meta__.__maintainer__,
maintainer_email=__meta__.__email__,
contact=__meta__.__maintainer__,
contact_email=__meta__.__email__,
url=__meta__.__url__,
platforms=__meta__.__platforms__,
license=__meta__.__license__,
keywords=__meta__.__title__ + ", Authentication, AuthN, Birdhouse",
classifiers=[
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"License :: OSI Approved :: Apache Software License",
"Natural Language :: English",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
],
python_requires=">=3.8, <4",
# -- Package structure -------------------------------------------------
packages=[__meta__.__package__],
package_dir={__meta__.__package__: __meta__.__package__},
include_package_data=True,
install_requires=REQUIREMENTS,
dependency_links=LINKS,
extras_require={
"docs": DOCS_REQUIREMENTS,
"dev": TEST_REQUIREMENTS,
"test": TEST_REQUIREMENTS,
},
zip_safe=False,
# -- self - tests --------------------------------------------------------
# test_suite="nose.collector",
# test_suite="tests.test_runner",
# test_loader="tests.test_runner:run_suite",
test_suite="tests",
tests_require=TEST_REQUIREMENTS,
# -- script entry points -----------------------------------------------
entry_points={
"paste.app_factory": [
"main = magpie.app:main"
],
"console_scripts": [
"magpie_cli = magpie.cli:magpie_helper_cli", # redirect to others below
"magpie_helper = magpie.cli:magpie_helper_cli", # alias to helper
"magpie_batch_update_permissions = magpie.cli.batch_update_permissions:main",
"magpie_batch_update_users = magpie.cli.batch_update_users:main",
"magpie_register_defaults = magpie.cli.register_defaults:main",
"magpie_register_providers = magpie.cli.register_providers:main",
"magpie_run_db_migration = magpie.cli.run_db_migration:main",
"magpie_send_email = magpie.cli.send_email:main",
"magpie_sync_resources = magpie.cli.sync_resources:main",
],
}
)
LOGGER.info("setup complete")