[Checkins] SVN: zope.exceptions/branches/regebro-python3/ Runs under Python 3.1 now (but not 3.0).
Lennart Regebro
regebro at gmail.com
Sun Sep 13 07:51:33 EDT 2009
Log message for revision 103901:
Runs under Python 3.1 now (but not 3.0).
Seems to only need standard fixers, so we can clean this up a lot once Distribute works
under Python 3 properly. Also there is an ugly workaround for zope.testing not being done yet
that can be removed once zope.testing supports Python 3.
Changed:
A zope.exceptions/branches/regebro-python3/build_py3.py
U zope.exceptions/branches/regebro-python3/setup.py
U zope.exceptions/branches/regebro-python3/src/zope/exceptions/tests/__init__.py
U zope.exceptions/branches/regebro-python3/src/zope/exceptions/tests/test_exceptionformatter.py
-=-
Added: zope.exceptions/branches/regebro-python3/build_py3.py
===================================================================
--- zope.exceptions/branches/regebro-python3/build_py3.py (rev 0)
+++ zope.exceptions/branches/regebro-python3/build_py3.py 2009-09-13 11:51:32 UTC (rev 103901)
@@ -0,0 +1,136 @@
+import os
+import sys
+
+if sys.version_info < (3,):
+ raise ImportError
+
+from distutils.errors import (CCompilerError, DistutilsExecError,
+ DistutilsPlatformError)
+from setuptools.command.build_ext import build_ext
+from pkg_resources import (normalize_path, working_set,
+ add_activation_listener, require)
+
+from distutils import log
+from lib2to3.refactor import RefactoringTool, get_fixers_from_package
+# These should be a part of the Python 3 setuptools port
+def run_2to3(files, fixer_names=None, options=None, explicit=None, doctests_only=False):
+ """Invoke 2to3 on a list of Python files.
+ The files should all come from the build area, as the
+ modification is done in-place. To reduce the build time,
+ only files modified since the last invocation of this
+ function should be passed in the files argument."""
+
+ if not files:
+ return
+
+ # Make this class local, to delay import of 2to3
+ class DistutilsRefactoringTool(RefactoringTool):
+ def log_error(self, msg, *args, **kw):
+ log.error(msg, *args)
+
+ def log_message(self, msg, *args):
+ log.info(msg, *args)
+
+ def log_debug(self, msg, *args):
+ log.debug(msg, *args)
+
+ if fixer_names is None:
+ fixer_names = get_fixers_from_package('lib2to3.fixes')
+ r = DistutilsRefactoringTool(fixer_names, options=options, explicit=explicit)
+ r.refactor(files, write=True, doctests_only=doctests_only)
+
+class Mixin2to3:
+ '''Mixin class for commands that run 2to3.
+ To configure 2to3, setup scripts may either change
+ the class variables, or inherit from individual commands
+ to override how 2to3 is invoked.'''
+
+ # provide list of fixers to run;
+ # defaults to all from lib2to3.fixers
+ fixer_names = None
+
+ # options dictionary
+ options = None
+
+ # list of fixers to invoke even though they are marked as explicit
+ explicit = None
+
+ def run_2to3(self, files, doctests_only=False):
+ return run_2to3(files, self.fixer_names, self.options,
+ self.explicit, doctests_only=doctests_only)
+
+from setuptools.command.test import test
+class test_2to3(test):
+ def with_project_on_sys_path(self, func):
+ # Ensure metadata is up-to-date
+ self.reinitialize_command('build_py', inplace=0)
+ self.run_command('build_py')
+ bpy_cmd = self.get_finalized_command("build_py")
+ build_path = normalize_path(bpy_cmd.build_lib)
+
+ self.reinitialize_command('egg_info', egg_base=build_path)
+ self.run_command('egg_info')
+
+ self.reinitialize_command('build_ext', inplace=0)
+ self.run_command('build_ext')
+
+ ei_cmd = self.get_finalized_command("egg_info")
+
+ old_path = sys.path[:]
+ old_modules = sys.modules.copy()
+
+ try:
+ sys.path.insert(0, build_path)
+ working_set.__init__()
+ add_activation_listener(lambda dist: dist.activate())
+ require('%s==%s' % (ei_cmd.egg_name, ei_cmd.egg_version))
+ func()
+ finally:
+ sys.path[:] = old_path
+ sys.modules.clear()
+ sys.modules.update(old_modules)
+ working_set.__init__()
+
+from setuptools.command.build_py import build_py
+
+class build_py_2to3(Mixin2to3, build_py):
+ def run(self):
+ self.updated_files = []
+ self.possible_doctests = []
+
+ # Base class code
+ if self.py_modules:
+ self.build_modules()
+ if self.packages:
+ self.build_packages()
+ self.build_package_data()
+
+ # 2to3
+ self.fixer_names = get_fixers_from_package('lib2to3.fixes') + \
+ get_fixers_from_package('zope.fixers')
+ self.run_2to3(self.updated_files)
+ self.run_2to3(self.updated_files, doctests_only=True)
+ self.run_2to3(self.possible_doctests, doctests_only=True)
+
+ # 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
+
+ def build_package_data(self):
+ """Copy data files into build directory"""
+ lastdir = None
+ for package, src_dir, build_dir, filenames in self.data_files:
+ for filename in filenames:
+ target = os.path.join(build_dir, filename)
+ self.mkpath(os.path.dirname(target))
+ res = self.copy_file(os.path.join(src_dir, filename), target,
+ preserve_mode=False)
+ if res[1]:
+ # file was copied
+ self.possible_doctests.append(res[0])
Modified: zope.exceptions/branches/regebro-python3/setup.py
===================================================================
--- zope.exceptions/branches/regebro-python3/setup.py 2009-09-13 11:01:26 UTC (rev 103900)
+++ zope.exceptions/branches/regebro-python3/setup.py 2009-09-13 11:51:32 UTC (rev 103901)
@@ -26,6 +26,14 @@
def read(*rnames):
return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
+try: # Python 3 versions. Will get into Distribute in the future.
+ from build_py3 import build_py_2to3 as build_py
+ from build_py3 import test_2to3 as test
+
+except (ImportError, SyntaxError):
+ from setuptools.command.build_py import build_py
+ from setuptools.command.test import test
+
setup(name='zope.exceptions',
version = '3.6.0dev',
author='Zope Corporation and Contributors',
@@ -60,4 +68,8 @@
],
include_package_data = True,
zip_safe = False,
+ test_suite = 'zope.exceptions.tests',
+ cmdclass = {'build_py': build_py,
+ 'test': test,
+ },
)
Modified: zope.exceptions/branches/regebro-python3/src/zope/exceptions/tests/__init__.py
===================================================================
--- zope.exceptions/branches/regebro-python3/src/zope/exceptions/tests/__init__.py 2009-09-13 11:01:26 UTC (rev 103900)
+++ zope.exceptions/branches/regebro-python3/src/zope/exceptions/tests/__init__.py 2009-09-13 11:51:32 UTC (rev 103901)
@@ -1,2 +0,0 @@
-#
-# This file is necessary to make this directory a package.
Modified: zope.exceptions/branches/regebro-python3/src/zope/exceptions/tests/test_exceptionformatter.py
===================================================================
--- zope.exceptions/branches/regebro-python3/src/zope/exceptions/tests/test_exceptionformatter.py 2009-09-13 11:01:26 UTC (rev 103900)
+++ zope.exceptions/branches/regebro-python3/src/zope/exceptions/tests/test_exceptionformatter.py 2009-09-13 11:51:32 UTC (rev 103901)
@@ -19,8 +19,15 @@
from unittest import TestCase, main, makeSuite
from zope.exceptions.exceptionformatter import format_exception
-from zope.testing.cleanup import CleanUp # Base class w registry cleanup
+# zope.testing is not ported yet, temporary workaround:
+try:
+ from zope.testing.cleanup import CleanUp # Base class w registry cleanup
+ class CleanUpTestCase(CleanUp, TestCase):
+ pass
+except ImportError:
+ CleanUpTestCase = TestCase
+
def tb(as_html=0):
t, v, b = sys.exc_info()
try:
@@ -46,7 +53,7 @@
-class Test(CleanUp, TestCase):
+class Test(CleanUpTestCase):
def testBasicNamesText(self, as_html=0):
try:
More information about the checkins
mailing list