# HG changeset patch # User hodgestar # Date 1300438942 0 # Node ID 1a86e0af2ae134e3579067fc44f31e6fa5d00868 # Parent 7dae2a05554304249119e7fe7f686897da86d88d Merge r1137 from py3k: add 2to3 build infrastructure to setup.py (this pulls the tests into the source distribution so that tests can be run after building with 2to3) diff --git a/MANIFEST.in b/MANIFEST.in --- a/MANIFEST.in +++ b/MANIFEST.in @@ -2,3 +2,4 @@ recursive-exclude doc/logo.lineform * include doc/api/*.* include doc/*.html +recursive-include genshi/template/tests/templates *.html *.txt diff --git a/examples_to_py3k.sh b/examples_to_py3k.sh new file mode 100644 --- /dev/null +++ b/examples_to_py3k.sh @@ -0,0 +1,8 @@ +#!/bin/sh +# +# Script to run 2to3 on files not covered by setup.py +# +export PYTHONIOENCODING=utf8 + +# General 2to3 run +2to3 -w --no-diffs examples/ diff --git a/fixes/__init__.py b/fixes/__init__.py new file mode 100644 diff --git a/fixes/fix_unicode_in_strings.py b/fixes/fix_unicode_in_strings.py new file mode 100644 --- /dev/null +++ b/fixes/fix_unicode_in_strings.py @@ -0,0 +1,17 @@ +"""Fixer that changes expressions inside strings literals from u"..." to "...". + +""" + +import re +from lib2to3 import fixer_base + +_literal_re = re.compile(r"(.+?)\b[uU]([rR]?[\'\"])") + +class FixUnicodeInStrings(fixer_base.BaseFix): + + PATTERN = "STRING" + + def transform(self, node, results): + new = node.clone() + new.value = _literal_re.sub(r"\1\2", new.value) + return new diff --git a/setup.py b/setup.py --- a/setup.py +++ b/setup.py @@ -41,7 +41,8 @@ def run(self): try: build_ext.run(self) - except DistutilsPlatformError, e: + except DistutilsPlatformError: + _etype, e, _tb = sys.exc_info() self._unavailable(e) def build_extension(self, ext): @@ -49,7 +50,8 @@ build_ext.build_extension(self, ext) global _speedup_available _speedup_available = True - except CCompilerError, e: + except CCompilerError: + _etype, e, _tb = sys.exc_info() self._unavailable(e) def _unavailable(self, exc): @@ -86,6 +88,25 @@ cmdclass['bdist_egg'] = my_bdist_egg +# Use 2to3 if we're running under Python 3 (with Distribute) +extra = {} +if sys.version_info >= (3,): + extra['use_2to3'] = True + extra['convert_2to3_doctests'] = [] + extra['use_2to3_fixers'] = ['fixes'] + # include tests for python3 setup.py test + packages = [ + 'genshi', 'genshi.filters', 'genshi.template', + 'genshi.tests', 'genshi.filters.tests', + 'genshi.template.tests', + 'genshi.template.tests.templates', + ] + # Install genshi template tests + extra['include_package_data'] = True +else: + packages = ['genshi', 'genshi.filters', 'genshi.template'] + + setup( name = 'Genshi', version = '0.7', @@ -108,13 +129,14 @@ 'License :: OSI Approved :: BSD License', 'Operating System :: OS Independent', 'Programming Language :: Python', + 'Programming Language :: Python :: 3', 'Topic :: Internet :: WWW/HTTP :: Dynamic Content', 'Topic :: Software Development :: Libraries :: Python Modules', 'Topic :: Text Processing :: Markup :: HTML', 'Topic :: Text Processing :: Markup :: XML' ], keywords = ['python.templating.engines'], - packages = ['genshi', 'genshi.filters', 'genshi.template'], + packages = packages, test_suite = 'genshi.tests.suite', extras_require = { @@ -132,5 +154,7 @@ """, features = {'speedups': speedups}, - cmdclass = cmdclass + cmdclass = cmdclass, + + **extra )