[Python-checkins] distutils2: added a first version of the fixer that renames setup() options.
tarek.ziade
python-checkins at python.org
Fri May 14 22:36:12 CEST 2010
tarek.ziade pushed 16f2b107e867 to distutils2:
http://hg.python.org/distutils2/rev/16f2b107e867
changeset: 137:16f2b107e867
user: Tarek Ziade <tarek at ziade.org>
date: Wed May 12 15:38:43 2010 +0200
summary: added a first version of the fixer that renames setup() options.
files: src/distutils2/converter/fixers/fix_setup_options.py, src/distutils2/converter/refactor.py, src/distutils2/tests/conversions/02_after.py, src/distutils2/tests/conversions/02_before.py
diff --git a/src/distutils2/converter/fixers/fix_setup_options.py b/src/distutils2/converter/fixers/fix_setup_options.py
new file mode 100644
--- /dev/null
+++ b/src/distutils2/converter/fixers/fix_setup_options.py
@@ -0,0 +1,49 @@
+"""Fixer for setup() options.
+
+All distutils or setuptools options are translated
+into PEP 345-style options.
+"""
+
+# Local imports
+from lib2to3 import pytree
+from lib2to3.pgen2 import token
+from lib2to3 import fixer_base
+from lib2to3.fixer_util import Assign, Name, Newline, Number, Subscript, syms
+
+# XXX where is that defined ?
+_ARGLIST = 259
+_ARG = 260
+
+# name mapping : we want to convert
+# all old-style options to distutils2 style
+_OLD_NAMES = {'url': 'home_page',
+ 'long_description': 'description',
+ 'description': 'summary'}
+
+class FixSetupOptions(fixer_base.BaseFix):
+
+ # XXX need to find something better here :
+ # identify a setup call, whatever alias is used
+ PATTERN = """
+ power< name='setup' trailer< '(' [any] ')' > any* >
+ """
+
+ def _fix_name(self, node):
+ for child in node.children:
+ if child.type != token.NAME:
+ self._fix_name(child)
+ else:
+ # let's see if it's a left operator
+ sibling = child.get_next_sibling()
+ if sibling is None or sibling.type != token.EQUAL:
+ # nope
+ return
+ if child.value in _OLD_NAMES:
+ child.value = _OLD_NAMES[child.value]
+ child.changed()
+
+ def transform(self, node, results):
+ trailer = node.children[1]
+ self._fix_name(trailer)
+ return node
+
diff --git a/src/distutils2/converter/refactor.py b/src/distutils2/converter/refactor.py
--- a/src/distutils2/converter/refactor.py
+++ b/src/distutils2/converter/refactor.py
@@ -3,15 +3,26 @@
Provides DistutilsRefactoringTool, a class that register fixers used
to refactor distutils or setuptools packages into distutils2 ones.
"""
-from lib2to3.refactor import RefactoringTool
+try:
+ from lib2to3.refactor import RefactoringTool
+ _LIB2TO3 = True
+except ImportError:
+ # we need 2.6 at least to run this
+ _LIB2TO3 = False
-_DISTUTILS_FIXERS = ['distutils2.converter.fixers.fix_imports']
+_DISTUTILS_FIXERS = ['distutils2.converter.fixers.fix_imports',
+ 'distutils2.converter.fixers.fix_setup_options']
-class DistutilsRefactoringTool(RefactoringTool):
+if _LIB2TO3:
+ class DistutilsRefactoringTool(RefactoringTool):
- def __init__(self, fixer_names=_DISTUTILS_FIXERS, options=None,
- explicit=None):
+ def __init__(self, fixer_names=_DISTUTILS_FIXERS, options=None,
+ explicit=None):
- super(DistutilsRefactoringTool, self).__init__(fixer_names, options,
- explicit)
+ super(DistutilsRefactoringTool, self).__init__(fixer_names, options,
+ explicit)
+else:
+ class DistutilsRefactoringTool(object):
+ def __init__(self, *args, **kw):
+ raise NotImplementedError('Not available if run from Python < 2.6')
diff --git a/src/distutils2/tests/conversions/02_after.py b/src/distutils2/tests/conversions/02_after.py
new file mode 100644
--- /dev/null
+++ b/src/distutils2/tests/conversions/02_after.py
@@ -0,0 +1,46 @@
+# -*- encoding: utf8 -*-
+import sys
+import os
+from distutils2.core import setup, Extension
+from distutils2.errors import CCompilerError, DistutilsError, CompileError
+from distutils2.command.build_ext import build_ext as distutils_build_ext
+
+VERSION = "0.1"
+
+class build_ext(distutils_build_ext):
+
+ def build_extension(self, ext):
+ try:
+ return distutils_build_ext.build_extension(self, ext)
+ except (CCompilerError, DistutilsError, CompileError), e:
+ pass
+
+def _get_ext_modules():
+ levenshtein = Extension('_levenshtein',
+ sources=[os.path.join('texttools',
+ '_levenshtein.c')])
+ return [levenshtein]
+
+with open('README.txt') as f:
+ LONG_DESCRIPTION = f.read()
+
+setup(name="TextTools", version=VERSION, author="Tarek Ziade",
+ author_email="tarek at ziade.org",
+ home_page="http://bitbucket.org/tarek/texttools",
+ summary="Text manipulation utilities",
+ description=LONG_DESCRIPTION,
+ keywords="text,guess,levenshtein",
+ classifiers=[
+ 'Development Status :: 4 - Beta',
+ 'Intended Audience :: Developers',
+ 'License :: OSI Approved :: Python Software Foundation License'
+ ],
+ cmdclass={'build_ext': build_ext},
+ packages=['texttools'],
+ package_dir={'texttools': 'texttools'},
+ package_data={'texttools': [os.path.join('samples', '*.txt')]},
+ scripts=[os.path.join('scripts', 'levenshtein.py'),
+ os.path.join('scripts', 'guesslang.py')],
+ ext_modules=_get_ext_modules()
+ )
+
diff --git a/src/distutils2/tests/conversions/02_before.py b/src/distutils2/tests/conversions/02_before.py
new file mode 100644
--- /dev/null
+++ b/src/distutils2/tests/conversions/02_before.py
@@ -0,0 +1,46 @@
+# -*- encoding: utf8 -*-
+import sys
+import os
+from distutils.core import setup, Extension
+from distutils.errors import CCompilerError, DistutilsError, CompileError
+from distutils.command.build_ext import build_ext as distutils_build_ext
+
+VERSION = "0.1"
+
+class build_ext(distutils_build_ext):
+
+ def build_extension(self, ext):
+ try:
+ return distutils_build_ext.build_extension(self, ext)
+ except (CCompilerError, DistutilsError, CompileError), e:
+ pass
+
+def _get_ext_modules():
+ levenshtein = Extension('_levenshtein',
+ sources=[os.path.join('texttools',
+ '_levenshtein.c')])
+ return [levenshtein]
+
+with open('README.txt') as f:
+ LONG_DESCRIPTION = f.read()
+
+setup(name="TextTools", version=VERSION, author="Tarek Ziade",
+ author_email="tarek at ziade.org",
+ url="http://bitbucket.org/tarek/texttools",
+ description="Text manipulation utilities",
+ long_description=LONG_DESCRIPTION,
+ keywords="text,guess,levenshtein",
+ classifiers=[
+ 'Development Status :: 4 - Beta',
+ 'Intended Audience :: Developers',
+ 'License :: OSI Approved :: Python Software Foundation License'
+ ],
+ cmdclass={'build_ext': build_ext},
+ packages=['texttools'],
+ package_dir={'texttools': 'texttools'},
+ package_data={'texttools': [os.path.join('samples', '*.txt')]},
+ scripts=[os.path.join('scripts', 'levenshtein.py'),
+ os.path.join('scripts', 'guesslang.py')],
+ ext_modules=_get_ext_modules()
+ )
+
--
Repository URL: http://hg.python.org/distutils2
More information about the Python-checkins
mailing list