[Python-checkins] distutils2: added a setuptools use case in the converter

tarek.ziade python-checkins at python.org
Fri May 14 22:36:12 CEST 2010


tarek.ziade pushed 53dfb044602c to distutils2:

http://hg.python.org/distutils2/rev/53dfb044602c
changeset:   146:53dfb044602c
user:        Tarek Ziade <tarek at ziade.org>
date:        Fri May 14 16:46:00 2010 +0200
summary:     added a setuptools use case in the converter
files:       src/distutils2/converter/fixers/fix_imports.py, src/distutils2/converter/fixers/fix_setup_options.py

diff --git a/src/distutils2/converter/fixers/fix_imports.py b/src/distutils2/converter/fixers/fix_imports.py
--- a/src/distutils2/converter/fixers/fix_imports.py
+++ b/src/distutils2/converter/fixers/fix_imports.py
@@ -27,3 +27,17 @@
             imp.changed()
             return node
 
+        if imp.value == 'setuptools':
+            # catching "from setuptools import setup"
+            pattern = []
+            next = imp.get_next_sibling()
+            while next is not None:
+                pattern.append(next.value)
+                next = next.get_next_sibling()
+            if pattern == ['import', 'setup']:
+                imp.value = 'distutils2.core'
+                imp.changed()
+
+            return node
+
+
diff --git a/src/distutils2/converter/fixers/fix_setup_options.py b/src/distutils2/converter/fixers/fix_setup_options.py
--- a/src/distutils2/converter/fixers/fix_setup_options.py
+++ b/src/distutils2/converter/fixers/fix_setup_options.py
@@ -18,7 +18,14 @@
 # all old-style options to distutils2 style
 _OLD_NAMES = {'url': 'home_page',
               'long_description': 'description',
-              'description': 'summary'}
+              'description': 'summary',
+              'install_requires': 'requires_dist'}
+
+# XXX see what we want to do for these..
+_INCOMPATIBLE_OPTIONS = ['entry_points',
+                         'include_package_data',
+                         'zip_safe',
+                         'namespace_packages']
 
 class FixSetupOptions(fixer_base.BaseFix):
 
@@ -28,22 +35,38 @@
             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 _fix_name(self, argument, remove_list):
+        name = argument.children[0]
+        sibling = name.get_next_sibling()
+        if sibling is None or sibling.type != token.EQUAL:
+            return False
+
+        if name.value in _OLD_NAMES:
+            name.value = _OLD_NAMES[name.value]
+        elif name.value in _INCOMPATIBLE_OPTIONS:
+            # removing the args, and the comma
+            # behind
+            next_token = name.parent.get_next_sibling()
+            if next_token.type == 12:
+                remove_list.append(next_token)
+            remove_list.append(name.parent)
+        return True
 
     def transform(self, node, results):
-        trailer = node.children[1]
-        self._fix_name(trailer)
+        arglist = node.children[1].children[1]
+        remove_list = []
+        changed = False
+
+        for subnode in arglist.children:
+            if subnode.type != _ARG:
+                continue
+            if self._fix_name(subnode, remove_list) and not changed:
+                changed = True
+
+        for subnode in remove_list:
+            subnode.remove()
+
+        if changed:
+            node.changed()
         return node
 

--
Repository URL: http://hg.python.org/distutils2


More information about the Python-checkins mailing list