equal
deleted
inserted
replaced
81 DistutilsError, |
81 DistutilsError, |
82 DistutilsExecError, |
82 DistutilsExecError, |
83 ) |
83 ) |
84 from distutils.sysconfig import get_python_inc, get_config_var |
84 from distutils.sysconfig import get_python_inc, get_config_var |
85 from distutils.version import StrictVersion |
85 from distutils.version import StrictVersion |
86 |
|
87 convert2to3 = '--c2to3' in sys.argv |
|
88 if convert2to3: |
|
89 try: |
|
90 from distutils.command.build_py import build_py_2to3 as build_py |
|
91 from lib2to3.refactor import get_fixers_from_package as getfixers |
|
92 except ImportError: |
|
93 if sys.version_info[0] < 3: |
|
94 raise SystemExit("--c2to3 is only compatible with python3.") |
|
95 raise |
|
96 sys.path.append('contrib') |
|
97 elif sys.version_info[0] >= 3: |
|
98 raise SystemExit("setup.py with python3 needs --c2to3 (experimental)") |
|
99 |
86 |
100 scripts = ['hg'] |
87 scripts = ['hg'] |
101 if os.name == 'nt': |
88 if os.name == 'nt': |
102 # We remove hg.bat if we are able to build hg.exe. |
89 # We remove hg.bat if we are able to build hg.exe. |
103 scripts.append('contrib/win32/hg.bat') |
90 scripts.append('contrib/win32/hg.bat') |
233 version = 'unknown' |
220 version = 'unknown' |
234 |
221 |
235 class hgbuild(build): |
222 class hgbuild(build): |
236 # Insert hgbuildmo first so that files in mercurial/locale/ are found |
223 # Insert hgbuildmo first so that files in mercurial/locale/ are found |
237 # when build_py is run next. |
224 # when build_py is run next. |
238 sub_commands = [('build_mo', None), |
225 sub_commands = [('build_mo', None)] + build.sub_commands |
239 |
|
240 # We also need build_ext before build_py. Otherwise, when 2to3 is |
|
241 # called (in build_py), it will not find osutil & friends, |
|
242 # thinking that those modules are global and, consequently, making |
|
243 # a mess, now that all module imports are global. |
|
244 |
|
245 ('build_ext', build.has_ext_modules), |
|
246 ] + build.sub_commands |
|
247 |
226 |
248 class hgbuildmo(build): |
227 class hgbuildmo(build): |
249 |
228 |
250 description = "build translations (.mo files)" |
229 description = "build translations (.mo files)" |
251 |
230 |
280 pure = ispypy |
259 pure = ispypy |
281 |
260 |
282 global_options = Distribution.global_options + \ |
261 global_options = Distribution.global_options + \ |
283 [('pure', None, "use pure (slow) Python " |
262 [('pure', None, "use pure (slow) Python " |
284 "code instead of C extensions"), |
263 "code instead of C extensions"), |
285 ('c2to3', None, "(experimental!) convert " |
|
286 "code with 2to3"), |
|
287 ] |
264 ] |
288 |
265 |
289 def has_ext_modules(self): |
266 def has_ext_modules(self): |
290 # self.ext_modules is emptied in hgbuildpy.finalize_options which is |
267 # self.ext_modules is emptied in hgbuildpy.finalize_options which is |
291 # too late for some cases |
268 # too late for some cases |
326 self.scripts.remove('contrib/win32/hg.bat') |
303 self.scripts.remove('contrib/win32/hg.bat') |
327 |
304 |
328 return build_scripts.run(self) |
305 return build_scripts.run(self) |
329 |
306 |
330 class hgbuildpy(build_py): |
307 class hgbuildpy(build_py): |
331 if convert2to3: |
|
332 fixer_names = sorted(set(getfixers("lib2to3.fixes") + |
|
333 getfixers("hgfixes"))) |
|
334 |
|
335 def finalize_options(self): |
308 def finalize_options(self): |
336 build_py.finalize_options(self) |
309 build_py.finalize_options(self) |
337 |
310 |
338 if self.distribution.pure: |
311 if self.distribution.pure: |
339 self.distribution.ext_modules = [] |
312 self.distribution.ext_modules = [] |