-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
executable file
·84 lines (68 loc) · 2.52 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
# -*- coding: utf-8 -*-
"""
setup.py implementation, interesting because it parsed the first __init__.py and
extracts the `__author__` and `__version__`
"""
from ast import parse
from distutils.sysconfig import get_python_lib
from functools import partial
from os import listdir, path
from setuptools import find_packages, setup
package_name = "ml_params"
def to_funcs(*paths):
"""
Produce function tuples that produce the local and install dir, respectively.
:param paths: one or more str, referring to relative folder names
:type paths: ```*paths```
:return: 2 functions
:rtype: ```Tuple[Callable[Optional[List[str]], str], Callable[Optional[List[str]], str]]```
"""
return (
partial(path.join, path.dirname(__file__), package_name, *paths),
partial(path.join, get_python_lib(prefix=""), package_name, *paths),
)
def main():
""" Main function for setup.py; this actually does the installation """
with open(
path.join(path.abspath(path.dirname(__file__)), package_name, "__init__.py")
) as f:
__author__, __version__ = map(
lambda buf: next(map(lambda e: e.value.s, parse(buf).body)),
filter(
lambda line: line.startswith("__version__")
or line.startswith("__author__"),
f,
),
)
_data_join, _data_install_dir = to_funcs("_data")
setup(
name=package_name,
author=__author__,
version=__version__,
install_requires=["pyyaml"],
test_suite=package_name + ".tests",
packages=find_packages(),
package_dir={package_name: package_name},
classifiers=[
"Development Status :: 3 - Alpha",
"Environment :: Console",
"Intended Audience :: Developers",
"License :: OSI Approved",
"License :: OSI Approved :: Apache Software License",
"License :: OSI Approved :: MIT License",
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: Implementation",
"Topic :: Software Development",
],
data_files=[
(_data_install_dir(), list(map(_data_join, listdir(_data_join()))))
],
)
def setup_py_main():
""" Calls main if `__name__ == '__main__'` """
if __name__ == "__main__":
main()
setup_py_main()