-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
81 lines (64 loc) · 1.82 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
#!/usr/bin/env python
import os
import toml
from setuptools import setup, find_packages
REQUIREMENTS_FILE = 'requirements.txt'
README_FILE = 'README.md'
PYPROJECT_FILE = 'pyproject.toml'
SETUP_KWARGS = [
'name',
'version',
'description',
'author',
'authors',
'author_email',
'license',
'url',
'project_urls',
'download_url',
'keywords',
'classifiers',
'packages',
'include',
'extras_require',
'include_package_data',
'python_requires',
]
INCLUDE = ['pyproject.toml', 'init.py']
EXCLUDE_PACKAGE = ['tests*']
def get_requirements():
"""Build the requirements list for this project"""
requirements_list = []
if not os.path.isfile(REQUIREMENTS_FILE):
# Check if requirements file did not exist.
return requirements_list
with open(REQUIREMENTS_FILE) as reqs:
for install in reqs:
requirements_list.append(install.strip())
return requirements_list
def get_setup_kwargs(default=None):
"""Get setup kwargs"""
with open(README_FILE, 'r', encoding='utf-8') as fd:
kwargs = dict(
long_description=fd.read(),
install_requires=get_requirements(),
include=INCLUDE,
packages=find_packages(exclude=EXCLUDE_PACKAGE),
)
if isinstance(default, dict):
kwargs.update(default)
pyproject = toml.load(PYPROJECT_FILE)
for k, v in dict(pyproject['tool']['poetry']).items():
if k in SETUP_KWARGS:
if k not in kwargs:
kwargs[k] = v
continue
if isinstance(kwargs[k], list):
kwargs[k].extend(v)
elif isinstance(kwargs[k], dict):
kwargs[k].update(v)
return kwargs
def main():
setup(**get_setup_kwargs())
if __name__ == '__main__':
main()