-
Notifications
You must be signed in to change notification settings - Fork 4
/
setup.py
executable file
·72 lines (48 loc) · 1.84 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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import re
import sys
from setuptools import find_packages, setup
def get_metadata(metadata_file):
with open(metadata_file) as stream:
text = stream.read()
ex = r"__(\w*?)__\s*?=\s*?[\"\']([^\"\']*)"
items = re.findall(ex, text)
metadata = {key: value for key, value in items}
metadata["keywords"] = metadata.get("keywords", "").split(", ")
ex = r'"{3}[^\w]*(?P<name>[^\s]*)[^\w]+(?P<description>.*)'
match_ = re.search(ex, text)
assert match_ is not None
metadata.update(match_.groupdict())
return metadata
ex = r"# ([^\s:]+).*\n([^#]+)"
requirements_prog = re.compile(ex)
def get_requirements(requirements):
with open(requirements) as stream:
matches = requirements_prog.findall(stream.read())
requires = {key: value.strip().splitlines() for key, value in matches}
return requires
def main():
if sys.version_info < (3, 6):
raise RuntimeError("Peony requires Python 3.6+")
dirname = os.path.dirname(__file__)
# get metadata and keywords from peony/__init__.py
kwargs = get_metadata(os.path.join(dirname, "peony", "__init__.py"))
# get requirements from requirements.txt
kwargs.update(get_requirements(os.path.join(dirname, "requirements.txt")))
# get extras requirements from extras_require.txt
extras = os.path.join(dirname, "extras_require.txt")
extras_require = get_requirements(extras)
# get long description from README.md
with open("README.rst") as stream:
long_description = stream.read()
setup(
long_description=long_description,
packages=find_packages(include=["peony*"]),
extras_require=extras_require,
python_requires=">=3.6",
**kwargs
)
if __name__ == "__main__":
main()