[pywin32-checkins] pywin32 setup3.py,1.1,1.2 setup.py,1.94,1.95
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
|
From: Mark H. <mha...@us...> - 2009-01-27 14:16:41
|
Update of /cvsroot/pywin32/pywin32 In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv31607 Modified Files: setup.py Added Files: setup3.py Log Message: merge final py3k build support Index: setup.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/setup.py,v retrieving revision 1.94 retrieving revision 1.95 diff -C2 -d -r1.94 -r1.95 *** setup.py 25 Jan 2009 23:49:17 -0000 1.94 --- setup.py 27 Jan 2009 13:09:09 -0000 1.95 *************** *** 97,100 **** --- 97,103 ---- from distutils.command.build import build from distutils.command.install_data import install_data + from distutils.command.build_py import build_py + from distutils.command.build_scripts import build_scripts + try: from distutils.command.bdist_msi import bdist_msi *************** *** 527,530 **** --- 530,608 ---- ################################################################ + # Extensions to the distutils commands. + + # Start with 2to3 related stuff for py3k. + do_2to3 = is_py3k + if do_2to3: + def refactor_filenames(filenames): + from lib2to3.refactor import RefactoringTool + # we only need some fixers. + fixers = """basestring exec except dict import imports next nonzero + print raw_input long standarderror types unicode urllib + xrange""".split() + fqfixers = ['lib2to3.fixes.fix_' + f for f in fixers] + + options = dict(doctests_only=False, fix=[], list_fixes=[], + print_function=False, verbose=False, + write=True) + r = RefactoringTool(fqfixers, options) + for updated_file in filenames: + if os.path.splitext(updated_file)[1] not in ['.py', '.pys']: + continue + log.info("Refactoring %s" % updated_file) + try: + r.refactor_file(updated_file, write=True, doctests_only=False) + if os.path.exists(updated_file + ".bak"): + os.unlink(updated_file + ".bak") + except Exception: + log.warn("WARNING: Failed to 2to3 %s: %s" % (updated_file, sys.exc_info()[1])) + else: + # py2k - nothing to do. + def refactor_filenames(filenames): + pass + + # 'build_py' command + if do_2to3: + # Force 2to3 to be run for py3k versions. + class my_build_py(build_py): + def run(self): + self.updated_files = [] + + # Base class code + if self.py_modules: + self.build_modules() + if self.packages: + self.build_packages() + self.build_package_data() + + # 2to3 + refactor_filenames(self.updated_files) + + # Remaining base class code + self.byte_compile(self.get_outputs(include_bytecode=0)) + + def build_module(self, module, module_file, package): + res = build_py.build_module(self, module, module_file, package) + if res[1]: + # file was copied + self.updated_files.append(res[0]) + return res + else: + my_build_py = build_py # default version. + + # 'build_scripts' command + if do_2to3: + class my_build_scripts(build_scripts): + def copy_file(self, src, dest): + dest, copied = build_scripts.copy_file(self, src, dest) + # 2to3 + if not self.dry_run and copied: + refactor_filenames([dest]) + return dest, copied + + else: + my_build_scripts = build_scripts + + # 'build' command class my_build(build): def run(self): *************** *** 1340,1343 **** --- 1418,1428 ---- install_data.finalize_options(self) + def copy_file(self, src, dest): + dest, copied = install_data.copy_file(self, src, dest) + # 2to3 + if not self.dry_run and copied: + refactor_filenames([dest]) + return dest, copied + ################################################################ *************** *** 1930,1933 **** --- 2015,2023 ---- other_extensions + if is_py3k: + py3k_skip_modules = \ + """adsi mapi isapi PyISAPI_loader""".split() + ext_modules = [e for e in ext_modules if e.name not in py3k_skip_modules] + # Build a map of DLL base addresses. According to Python's PC\dllbase_nt.txt, # we start at 0x1e200000 and go up in 0x00020000 increments. A couple of *************** *** 1948,1951 **** --- 2038,2043 ---- 'build_ext': my_build_ext, 'install_data': my_install_data, + 'build_py' : my_build_py, + 'build_scripts' : my_build_scripts, } --- NEW FILE: setup3.py --- # This is a Python 3.x script to build pywin32. It converts then executes # the regular setup.py script. import os from lib2to3.refactor import RefactoringTool, get_fixers_from_package fixers = ['lib2to3.fixes.fix_print', 'lib2to3.fixes.fix_except'] options = dict(doctests_only=False, fix=[], list_fixes=[], print_function=False, verbose=False, write=True) r = RefactoringTool(fixers, options) script = os.path.join(os.path.dirname(__file__), "setup.py") data = open(script).read() print("Converting...") got = r.refactor_string(data, "setup.py") print("Executing...") exec(str(got)) |