-
Notifications
You must be signed in to change notification settings - Fork 28
/
setup.py
162 lines (128 loc) · 4.55 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
# pylint: disable=E0602
import sys
import os.path as osp
import glob
import io
import shutil
from setuptools import setup, find_packages
from setuptools.command.develop import develop
from setuptools.command.install import install
# import pip
# try:
# from pip._internal.req import parse_requirements # pip 10
# except ImportError:
# from pip.req import parse_requirements # pip 9
# globals
PACKAGE = "pipupgrade"
SRCDIR = "src"
# A very awful patch for parse_requirements from pip
def parse_requirements(filename, session = None):
class FakeRequirement:
def __init__(self, name):
self.req = name
def sanitize_line(line):
if "git+" in line:
if "#egg=" in line:
_, name = line.split("#egg=")
name = name.strip()
line = "%s @ %s" % (name, line)
line = line.strip()
return line
def check_line(line):
return line and not line.startswith("#")
return [
FakeRequirement(sanitize_line(line)) for line in open(filename) if check_line(line)
]
def isdef(var):
return var in globals()
def read(path, encoding = None):
content = None
with io.open(path, encoding = encoding) as f:
content = f.read()
return content
def get_package_info():
attr = osp.abspath(osp.join(SRCDIR, PACKAGE, "__attr__.py"))
info = dict(__file__ = attr) # HACK
with open(attr) as f:
content = f.read()
exec(content, info)
return info
def get_dependencies(type_ = None):
path = osp.realpath("requirements.txt")
requirements = [str(ir.req) for ir in parse_requirements(path, session = "hack")]
if type_ == "development":
path = osp.realpath("requirements-dev.txt")
requirements = [
str(ir.req) for ir in parse_requirements(path, session = "hack")
if str(ir.req) not in requirements
]
return requirements
PKGINFO = get_package_info()
def remove_cache():
userdir = osp.expanduser("~")
pkgname = PKGINFO["__name__"]
paths = [
osp.join(userdir, ".%s" % pkgname), # backward-compatibility
osp.join(userdir, ".config", pkgname)
]
for path in paths:
if osp.exists(path):
shutil.rmtree(path)
class DevelopCommand(develop):
def run(self):
develop.run(self)
remove_cache()
class InstallCommand(install):
def run(self):
install.run(self)
remove_cache()
setup(
name = PKGINFO["__name__"],
version = PKGINFO["__version__"],
url = PKGINFO["__url__"],
author = PKGINFO["__author__"],
author_email = PKGINFO["__email__"],
description = PKGINFO["__description__"],
long_description = read("README.md", encoding = "utf8"),
long_description_content_type = "text/markdown",
license = PKGINFO["__license__"],
keywords = " ".join(PKGINFO["__keywords__"]),
packages = find_packages(where = SRCDIR),
package_dir = { "": SRCDIR },
zip_safe = False,
entry_points = {
"console_scripts": [
"%s = %s.__main__:main" % (
PKGINFO["__command__"] if hasattr(PKGINFO, "__command__") else PKGINFO["__name__"],
PACKAGE
)
]
},
install_requires = get_dependencies(type_ = "production"),
extras_require = dict(
dev = get_dependencies(type_ = "development")
),
include_package_data = True,
classifiers = [
"Development Status :: 5 - Production/Stable",
"Environment :: Console",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy"
],
cmdclass = {
"install": InstallCommand,
"develop": DevelopCommand
}
)