@@ -65,12 +65,66 @@ def run(self):
65
65
build_py .run (self )
66
66
67
67
68
+ cmdclass = {'build_py' : CustomPythonBuild }
69
+
68
70
package_data = ['py.typed' ]
69
71
70
72
package_data += find_package_data (os .path .join ('mypy' , 'typeshed' ), ['*.py' , '*.pyi' ])
71
73
72
74
package_data += find_package_data (os .path .join ('mypy' , 'xml' ), ['*.xsd' , '*.xslt' , '*.css' ])
73
75
76
+ USE_MYPYC = False
77
+ # To compile with mypyc, a mypyc checkout must be present on the PYTHONPATH
78
+ if len (sys .argv ) > 1 and sys .argv [1 ] == '--use-mypyc' :
79
+ sys .argv .pop (1 )
80
+ USE_MYPYC = True
81
+ if os .getenv ('MYPY_USE_MYPYC' , None ) == '1' :
82
+ USE_MYPYC = True
83
+
84
+ if USE_MYPYC :
85
+ MYPYC_BLACKLIST = (
86
+ 'mypyc_hacks.py' ,
87
+ 'interpreted_plugin.py' ,
88
+
89
+ '__main__.py' ,
90
+ 'bogus_type.py' ,
91
+ 'dmypy.py' ,
92
+ 'gclogger.py' ,
93
+ 'main.py' ,
94
+ 'memprofile.py' ,
95
+ 'version.py' ,
96
+ )
97
+
98
+ everything = find_package_data ('mypy' , ['*.py' ])
99
+ # Start with all the .py files
100
+ all_real_pys = [x for x in everything if not x .startswith ('typeshed/' )]
101
+ # Strip out anything in our blacklist
102
+ mypyc_targets = [x for x in all_real_pys if x not in MYPYC_BLACKLIST ]
103
+ # Strip out any test code
104
+ mypyc_targets = [x for x in mypyc_targets if not x .startswith ('test/' )]
105
+ # ... and add back in the one test module we need
106
+ mypyc_targets .append ('test/visitors.py' )
107
+
108
+ # Fix the paths to be full
109
+ mypyc_targets = [os .path .join ('mypy' , x ) for x in mypyc_targets ]
110
+
111
+ # This bit is super unfortunate: we want to use the mypy packaged
112
+ # with mypyc. It will arrange for the path to be setup so it can
113
+ # find it, but we've already imported parts, so we remove the
114
+ # modules that we've imported already, which will let the right
115
+ # versions be imported by mypyc.
116
+ del sys .modules ['mypy' ]
117
+ del sys .modules ['mypy.version' ]
118
+ del sys .modules ['mypy.git' ]
119
+
120
+ from mypyc .build import mypycify , MypycifyBuildExt
121
+ opt_level = os .getenv ('MYPYC_OPT_LEVEL' , '3' )
122
+ ext_modules = mypycify (mypyc_targets , ['--config-file=mypy_bootstrap.ini' ], opt_level )
123
+ cmdclass ['build_ext' ] = MypycifyBuildExt
124
+ description += " (mypyc-compiled version)"
125
+ else :
126
+ ext_modules = []
127
+
74
128
75
129
classifiers = [
76
130
'Development Status :: 3 - Alpha' ,
@@ -84,7 +138,7 @@ def run(self):
84
138
'Topic :: Software Development' ,
85
139
]
86
140
87
- setup (name = 'mypy' ,
141
+ setup (name = 'mypy' if not USE_MYPYC else 'mypy-mypyc' ,
88
142
version = version ,
89
143
description = description ,
90
144
long_description = long_description ,
@@ -93,14 +147,15 @@ def run(self):
93
147
url = 'http://www.mypy-lang.org/' ,
94
148
license = 'MIT License' ,
95
149
py_modules = [],
150
+ ext_modules = ext_modules ,
96
151
packages = ['mypy' , 'mypy.test' , 'mypy.server' , 'mypy.plugins' ],
97
152
package_data = {'mypy' : package_data },
98
153
entry_points = {'console_scripts' : ['mypy=mypy.__main__:console_entry' ,
99
154
'stubgen=mypy.stubgen:main' ,
100
155
'dmypy=mypy.dmypy:main' ,
101
156
]},
102
157
classifiers = classifiers ,
103
- cmdclass = { 'build_py' : CustomPythonBuild } ,
158
+ cmdclass = cmdclass ,
104
159
install_requires = ['typed-ast >= 1.1.0, < 1.2.0' ,
105
160
'mypy_extensions >= 0.4.0, < 0.5.0' ,
106
161
],
0 commit comments