-
Notifications
You must be signed in to change notification settings - Fork 4
/
setup.py
executable file
·165 lines (143 loc) · 5.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/usr/bin/env python
import io
import os
import re
import sys
import warnings
from setuptools import setup, find_packages
from setuptools.command.install import install
classifiers = [
"Intended Audience :: End Users/Desktop",
"Operating System :: POSIX",
"Natural Language :: English",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
"Programming Language :: Python",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
]
def getPackageInfo():
info_dict = {}
info_keys = ["version", "name", "author", "author_email", "url", "license",
"description", "release_name", "github_url"]
# FIXME: This remap is the exception, not the rule.
key_remap = {"name": "pypi_name"}
# __about__
info_fpath = os.path.join(os.path.abspath(os.path.dirname(__file__)),
".",
"mishmash",
"__about__.py")
with io.open(info_fpath, encoding='utf-8') as infof:
for line in infof:
for what in info_keys:
rex = re.compile(r"__{what}__\s*=\s*['\"](.*?)['\"]"
.format(what=what if what not in key_remap
else key_remap[what]))
m = rex.match(line.strip())
if not m:
continue
info_dict[what] = m.groups()[0]
vparts = info_dict["version"].split("-", maxsplit=1)
info_dict["release"] = vparts[1] if len(vparts) > 1 else "final"
# Requirements
requirements, extras = requirements_yaml()
info_dict["install_requires"] = requirements["main"] \
if "main" in requirements else []
info_dict["tests_require"] = requirements["test"] \
if "test" in requirements else []
info_dict["extras_require"] = extras
# Info
readme = ""
if os.path.exists("README.rst"):
with io.open("README.rst", encoding='utf-8') as readme_file:
readme = readme_file.read()
hist = "`changelog <https://github.com/nicfit/MishMash/blob/master/HISTORY.rst>`_"
info_dict["long_description"] =\
readme + "\n\n" +\
"See the {} file for release history and changes.".format(hist)
return info_dict, requirements
def requirements_yaml():
prefix = "extra_"
reqs = {}
reqfile = os.path.join("requirements", "requirements.yml")
if os.path.exists(reqfile):
with io.open(reqfile, encoding='utf-8') as fp:
curr = None
for line in [l for l in [l.strip() for l in fp.readlines()]
if l and not l.startswith("#")]:
if curr is None or line[0] != "-":
curr = line.split(":")[0]
reqs[curr] = []
else:
assert line[0] == "-"
r = line[1:].strip()
if r:
reqs[curr].append(r.strip())
return (reqs, {x[len(prefix):]: vals
for x, vals in reqs.items() if x.startswith(prefix)})
class PipInstallCommand(install, object):
def run(self):
reqs = " ".join(["'%s'" % r for r in PKG_INFO["install_requires"]])
os.system("pip install " + reqs)
# XXX: py27 compatible
return super(PipInstallCommand, self).run()
PKG_INFO, REQUIREMENTS = getPackageInfo()
if PKG_INFO["release"].startswith("a"):
#classifiers.append("Development Status :: 1 - Planning")
#classifiers.append("Development Status :: 2 - Pre-Alpha")
classifiers.append("Development Status :: 3 - Alpha")
elif PKG_INFO["release"].startswith("b"):
classifiers.append("Development Status :: 4 - Beta")
else:
classifiers.append("Development Status :: 5 - Production/Stable")
#classifiers.append("Development Status :: 6 - Mature")
#classifiers.append("Development Status :: 7 - Inactive")
gz = "{name}-{version}.tar.gz".format(**PKG_INFO)
PKG_INFO["download_url"] = (
"{github_url}/releases/downloads/v{version}/{gz}"
.format(gz=gz, **PKG_INFO)
)
def package_files(directory, prefix=".."):
paths = []
for (path, _, filenames) in os.walk(directory):
if "__pycache__" in path:
continue
for filename in filenames:
if filename.endswith(".pyc"):
continue
paths.append(os.path.join(prefix, path, filename))
return paths
if sys.argv[1:] and sys.argv[1] == "--release-name":
print(PKG_INFO["release_name"])
sys.exit(0)
else:
# The extra command line options we added cause warnings, quell that.
with warnings.catch_warnings():
warnings.filterwarnings("ignore", message="Unknown distribution option")
warnings.filterwarnings("ignore", message="Normalizing")
setup(classifiers=classifiers,
package_dir={"": "."},
packages=find_packages(".",
exclude=["tests", "tests.*"]),
zip_safe=False,
platforms=["Any"],
keywords=["music", "database"],
test_suite="./tests",
include_package_data=True,
package_data={
"mishmash": ["alembic.ini"] +
package_files("mishmash/alembic"),
"mishmash.web": package_files("mishmash/web/static",
"../..") +
package_files("mishmash/web/templates",
"../.."),
},
entry_points={
"console_scripts": [
"mishmash = mishmash.__main__:app.run",
]
},
cmdclass={
"install": PipInstallCommand,
},
**PKG_INFO
)