forked from docopt/docopt.c
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
111 lines (93 loc) · 3.87 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
# -*- coding: utf-8 -*-
"""
setup.py implementation, interesting because it parsed the first __init__.py and
extracts the `__author__` and `__version__`
"""
from ast import Assign, Constant, Str, parse
from distutils.sysconfig import get_python_lib
from functools import partial
from operator import attrgetter
from os import path
from os.path import extsep
from platform import python_version_tuple
from pkg_resources import resource_filename
from setuptools import setup
if python_version_tuple()[0] == '2':
from itertools import imap as map, ifilter as filter
package_name = "docopt_c"
with open(
path.join(path.dirname(__file__), "README{extsep}md".format(extsep=extsep)),
"rt",
encoding="utf-8",
) as fh:
long_description = fh.read()
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```
:returns: 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"""
assert path.isfile(resource_filename(package_name, "docopt_c.py"))
with open(
resource_filename(package_name, "docopt_c{extsep}py".format(extsep=extsep))) as f:
parsed_init = parse(f.read())
__author__, __version__, __description__ = map(
lambda node: node.value if isinstance(node, Constant) else node.s,
filter(
lambda node: isinstance(node, (Constant, Str)),
map(
attrgetter("value"),
filter(lambda node: isinstance(node, Assign)
and any(filter(lambda target: target.id in frozenset(("__author__",
"__version__",
"__description__")),
node.targets)),
parsed_init.body),
),
),
)
setup(
name=package_name,
author=__author__,
author_email="[email protected]",
version=__version__,
description=__description__,
long_description=long_description,
long_description_content_type="text/markdown",
py_modules=["docopt_c"],
scripts=["docopt.py", "docopt_c.py"],
classifiers=[
"Development Status :: 3 - Alpha",
"Environment :: Console",
"Intended Audience :: Developers",
"License :: OSI Approved",
"License :: OSI Approved :: MIT License",
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: Implementation",
"Topic :: Scientific/Engineering :: Interface Engine/Protocol Translator",
"Topic :: Software Development",
"Topic :: Software Development :: Build Tools",
"Topic :: Software Development :: Code Generators",
"Topic :: Software Development :: Compilers",
"Topic :: Software Development :: Pre-processors"
],
url="https://github.com/docopt/docopt.c"
)
def setup_py_main():
"""Calls main if `__name__ == '__main__'`"""
if __name__ == "__main__":
main()
setup_py_main()