Skip to content
Permalink
Newer
Older
100644 216 lines (185 sloc) 7.83 KB
Jun 27, 2013
1
#!/usr/bin/env python
2
3
import glob
4
import os
5
import os.path
6
import sys
Jun 27, 2013
7
8
if sys.version_info < (3, 6, 0):
9
sys.stderr.write("ERROR: You need Python 3.6 or later to use mypy.\n")
10
exit(1)
11
12
# we'll import stuff from the source tree, let's ensure is on the sys path
13
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
14
15
# This requires setuptools when building; setuptools is not needed
16
# when installing from a wheel file (though it is still needed for
17
# alternative forms of installing, as suggested by README.md).
18
from setuptools import setup, find_packages
19
from setuptools.command.build_py import build_py
20
from mypy.version import __version__ as version
Apr 6, 2015
22
description = 'Optional static typing for Python'
Jun 27, 2013
23
long_description = '''
Apr 6, 2015
24
Mypy -- Optional Static Typing for Python
25
=========================================
Jun 27, 2013
26
27
Add type annotations to your Python programs, and use mypy to type
28
check them. Mypy is essentially a Python linter on steroids, and it
Apr 6, 2015
29
can catch many programming errors by analyzing your program, without
30
actually having to run it. Mypy has a powerful type system with
31
features such as type inference, gradual typing, generics and union
32
types.
Jun 27, 2013
33
'''.lstrip()
34
36
def find_package_data(base, globs, root='mypy'):
37
"""Find all interesting data files, for setup(package_data=)
39
Arguments:
40
root: The directory to search in.
41
globs: A list of glob patterns to accept files.
42
"""
44
rv_dirs = [root for root, dirs, files in os.walk(base)]
45
rv = []
46
for rv_dir in rv_dirs:
47
files = []
48
for pat in globs:
49
files += glob.glob(os.path.join(rv_dir, pat))
50
if not files:
51
continue
52
rv.extend([os.path.relpath(f, root) for f in files])
55
56
class CustomPythonBuild(build_py):
57
def pin_version(self):
58
path = os.path.join(self.build_lib, 'mypy')
59
self.mkpath(path)
60
with open(os.path.join(path, 'version.py'), 'w') as stream:
61
stream.write(f'__version__ = "{version}"\n')
62
63
def run(self):
64
self.execute(self.pin_version, ())
65
build_py.run(self)
66
67
68
cmdclass = {'build_py': CustomPythonBuild}
69
70
package_data = ['py.typed']
71
72
package_data += find_package_data(os.path.join('mypy', 'typeshed'), ['*.py', '*.pyi'])
73
package_data += [os.path.join('mypy', 'typeshed', 'stdlib', 'VERSIONS')]
75
package_data += find_package_data(os.path.join('mypy', 'xml'), ['*.xsd', '*.xslt', '*.css'])
77
USE_MYPYC = False
78
# To compile with mypyc, a mypyc checkout must be present on the PYTHONPATH
79
if len(sys.argv) > 1 and sys.argv[1] == '--use-mypyc':
80
sys.argv.pop(1)
81
USE_MYPYC = True
82
if os.getenv('MYPY_USE_MYPYC', None) == '1':
83
USE_MYPYC = True
84
85
if USE_MYPYC:
86
MYPYC_BLACKLIST = tuple(os.path.join('mypy', x) for x in (
87
# Need to be runnable as scripts
89
'pyinfo.py',
90
os.path.join('dmypy', '__main__.py'),
91
92
# Uses __getattr__/__setattr__
93
'split_namespace.py',
95
# Lies to mypy about code reachability
97
98
# We don't populate __file__ properly at the top level or something?
99
# Also I think there would be problems with how we generate version.py.
102
# Skip these to reduce the size of the build
103
'stubtest.py',
104
'stubgenc.py',
105
'stubdoc.py',
106
'stubutil.py',
107
)) + (
108
# Don't want to grab this accidentally
109
os.path.join('mypyc', 'lib-rt', 'setup.py'),
110
# Uses __file__ at top level https://github.com/mypyc/mypyc/issues/700
111
os.path.join('mypyc', '__main__.py'),
114
everything = (
115
[os.path.join('mypy', x) for x in find_package_data('mypy', ['*.py'])] +
116
[os.path.join('mypyc', x) for x in find_package_data('mypyc', ['*.py'], root='mypyc')])
117
# Start with all the .py files
118
all_real_pys = [x for x in everything
119
if not x.startswith(os.path.join('mypy', 'typeshed') + os.sep)]
120
# Strip out anything in our blacklist
121
mypyc_targets = [x for x in all_real_pys if x not in MYPYC_BLACKLIST]
122
# Strip out any test code
123
mypyc_targets = [x for x in mypyc_targets
124
if not x.startswith((os.path.join('mypy', 'test') + os.sep,
125
os.path.join('mypyc', 'test') + os.sep,
126
os.path.join('mypyc', 'doc') + os.sep,
127
os.path.join('mypyc', 'test-data') + os.sep,
128
))]
129
# ... and add back in the one test module we need
130
mypyc_targets.append(os.path.join('mypy', 'test', 'visitors.py'))
132
# The targets come out of file system apis in an unspecified
133
# order. Sort them so that the mypyc output is deterministic.
134
mypyc_targets.sort()
136
use_other_mypyc = os.getenv('ALTERNATE_MYPYC_PATH', None)
137
if use_other_mypyc:
138
# This bit is super unfortunate: we want to use a different
139
# mypy/mypyc version, but we've already imported parts, so we
140
# remove the modules that we've imported already, which will
141
# let the right versions be imported by mypyc.
142
del sys.modules['mypy']
143
del sys.modules['mypy.version']
144
del sys.modules['mypy.git']
145
sys.path.insert(0, use_other_mypyc)
147
from mypyc.build import mypycify
148
opt_level = os.getenv('MYPYC_OPT_LEVEL', '3')
149
debug_level = os.getenv('MYPYC_DEBUG_LEVEL', '1')
150
force_multifile = os.getenv('MYPYC_MULTI_FILE', '') == '1'
151
ext_modules = mypycify(
152
mypyc_targets + ['--config-file=mypy_bootstrap.ini'],
153
opt_level=opt_level,
155
# Use multi-file compilation mode on windows because without it
156
# our Appveyor builds run out of memory sometimes.
157
multi_file=sys.platform == 'win32' or force_multifile,
159
else:
160
ext_modules = []
161
Jun 27, 2013
163
classifiers = [
164
'Development Status :: 4 - Beta',
Jun 27, 2013
165
'Environment :: Console',
166
'Intended Audience :: Developers',
167
'License :: OSI Approved :: MIT License',
168
'Programming Language :: Python :: 3',
169
'Programming Language :: Python :: 3.6',
170
'Programming Language :: Python :: 3.7',
171
'Programming Language :: Python :: 3.8',
172
'Programming Language :: Python :: 3.9',
173
'Programming Language :: Python :: 3.10',
Jun 27, 2013
174
'Topic :: Software Development',
175
]
176
Jun 27, 2013
178
version=version,
179
description=description,
180
long_description=long_description,
181
author='Jukka Lehtosalo',
182
author_email='jukka.lehtosalo@iki.fi',
183
url='http://www.mypy-lang.org/',
184
license='MIT License',
186
ext_modules=ext_modules,
187
packages=find_packages(),
188
package_data={'mypy': package_data},
189
entry_points={'console_scripts': ['mypy=mypy.__main__:console_entry',
190
'stubgen=mypy.stubgen:main',
191
'stubtest=mypy.stubtest:main',
192
'dmypy=mypy.dmypy.client:console_entry',
193
'mypyc=mypyc.__main__:main',
Jun 27, 2013
195
classifiers=classifiers,
197
# When changing this, also update mypy-requirements.txt.
198
install_requires=["typed_ast >= 1.4.0, < 2; python_version<'3.8'",
199
'typing_extensions>=3.10',
200
'mypy_extensions >= 0.4.3',
201
"tomli>=1.1.0; python_version<'3.11'",
204
extras_require={
205
'dmypy': 'psutil >= 4.0',
206
'python2': 'typed_ast >= 1.4.0, < 2',
207
'reports': 'lxml'
208
},
209
python_requires=">=3.6",
210
include_package_data=True,
211
project_urls={
212
'News': 'http://mypy-lang.org/news.html',
213
'Documentation': 'https://mypy.readthedocs.io/en/stable/introduction.html',
214
'Repository': 'https://github.com/python/mypy',
215
},
Jun 27, 2013
216
)