-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
65 lines (48 loc) · 1.69 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
# flake8: noqa
from pathlib import Path
from dicountries import metadata
from setuptools import find_packages, setup
BUNDLES = {}
def strip_comments(l):
return l.split('#', 1)[0].strip()
def _pip_requirement(req, *root):
if req.startswith('-r ') or req.startswith('-c '):
_, path = req.split()
return reqs(*root, *path.split('/'))
return [req]
def _reqs(*f):
path = (Path.cwd() / 'requirements').joinpath(*f)
if not path.is_file():
return []
with path.open() as fh:
reqs = [strip_comments(l) for l in fh.readlines()]
return [_pip_requirement(r, *f[:-1]) for r in reqs if r]
def reqs(*f):
return [req for subreq in _reqs(*f) for req in subreq]
def extras(*p):
return reqs('extras', *p)
def extras_require():
deps = {x: extras(f'{x}.txt') for x in BUNDLES}
pre_deps = {x: extras(f'pre-{x}.txt') for x in BUNDLES}
keys = set(deps.keys()).union(set(pre_deps.keys()))
result = {}
for key in keys:
result[key] = list(set(deps.get(key, [])).union(set(pre_deps.get(key, []))))
return result
if __name__ == '__main__':
setup(
name=metadata.name,
version=metadata.version,
url=metadata.url,
license=metadata.license,
author=metadata.author,
author_email=metadata.author_email,
description=metadata.description,
packages=find_packages(exclude=['tests', 'examples', 'docs']),
python_requires='>=3.6.0',
install_requires=reqs('default.txt') + reqs('pre-default.txt'),
extras_require=extras_require(),
long_description=open('README.rst').read(),
package_data={'dicountries': ['data/*']},
zip_safe=False,
)