Commits

Tarek Ziadé committed 6642784

cleanup util + better names

Comments (0)

Files changed (2)

distutils2/mkcfg.py

         program.query_user()
         program.update_config_file()
     program.write_setup_script()
-    # istutils2.util.generate_distutils_setup_py()
+    # distutils2.util.cfg_to_args()
 
 
 if __name__ == '__main__':

distutils2/util.py

 import re
 import string
 import sys
-import shutil
-import tarfile
-import zipfile
 from subprocess import call as sub_call
 from copy import copy
 from fnmatch import fnmatchcase
             if missing == 'error':      # blow up when we stat() the file
                 pass
             elif missing == 'ignore':   # missing source dropped from
-                continue                #  target's dependency list
+                continue                # target's dependency list
             elif missing == 'newer':    # missing source means target is
-                return True             #  out-of-date
+                return True             # out-of-date
 
         if os.stat(source).st_mtime > target_mtime:
             return True
         msg = "command '%s' failed with exit status %d"
         raise DistutilsExecError(msg % (cmd, exit_status))
 
+
 def find_executable(executable, path=None):
     """Tries to find 'executable' in the directories listed in 'path'.
 
 
     if fixer_names:
         for fixername in fixer_names:
-            fixers.extend([fixer for fixer in get_fixers_from_package(fixername)])
+            fixers.extend([fixer for fixer in
+                           get_fixers_from_package(fixername)])
     r = RefactoringTool(fixers, options=options)
     r.refactor(files, write=True, doctests_only=doctests_only)
 
                    yield file
 
 
-def generate_distutils_kwargs_from_setup_cfg(file='setup.cfg'):
+def cfg_to_args(path='setup.cfg'):
     """ Distutils2 to distutils1 compatibility util.
 
         This method uses an existing setup.cfg to generate a dictionnary of
     """
     # We need to declare the following constants here so that it's easier to
     # generate the setup.py afterwards, using inspect.getsource.
-    D1_D2_SETUP_ARGS = {
-        # D1 name             : (D2_section, D2_name)
-        "name"                : ("metadata",),
-        "version"             : ("metadata",),
-        "author"              : ("metadata",),
-        "author_email"        : ("metadata",),
-        "maintainer"          : ("metadata",),
-        "maintainer_email"    : ("metadata",),
-        "url"                 : ("metadata", "home_page"),
-        "description"         : ("metadata", "summary"),
-        "long_description"    : ("metadata", "description"),
-        "download-url"        : ("metadata",),
-        "classifiers"         : ("metadata", "classifier"),
-        "platforms"           : ("metadata", "platform"), # Needs testing
-        "license"             : ("metadata",),
-        "requires"            : ("metadata", "requires_dist"),
-        "provides"            : ("metadata", "provides_dist"), # Needs testing
-        "obsoletes"           : ("metadata", "obsoletes_dist"), # Needs testing
-    
-        "packages"            : ("files",),
-        "scripts"             : ("files",),
-        "py_modules"          : ("files", "modules"), # Needs testing
-    }
+
+    # XXX ** == needs testing
+    D1_D2_SETUP_ARGS = {"name": ("metadata",),
+                        "version": ("metadata",),
+                        "author": ("metadata",),
+                        "author_email": ("metadata",),
+                        "maintainer": ("metadata",),
+                        "maintainer_email": ("metadata",),
+                        "url": ("metadata", "home_page"),
+                        "description": ("metadata", "summary"),
+                        "long_description": ("metadata", "description"),
+                        "download-url": ("metadata",),
+                        "classifiers": ("metadata", "classifier"),
+                        "platforms": ("metadata", "platform"),  # **
+                        "license": ("metadata",),
+                        "requires": ("metadata", "requires_dist"),
+                        "provides": ("metadata", "provides_dist"),  # **
+                        "obsoletes": ("metadata", "obsoletes_dist"),  # **
+                        "packages": ("files",),
+                        "scripts": ("files",),
+                        "py_modules": ("files", "modules"),  # **
+                        }
 
     MULTI_FIELDS = ("classifiers",
                     "requires",
     if not os.path.exists(file):
         raise DistutilsFileError("file '%s' does not exist" %
                                  os.path.abspath(file))
-    config.read(file)
+    config.read(path)
 
     kwargs = {}
     for arg in D1_D2_SETUP_ARGS:
     return kwargs
 
 
-def generate_distutils_setup_py():
-    """ Generate a distutils compatible setup.py using an existing setup.cfg.
+_SETUP_TMPL = """\
+# This script was automatically generated by Distutils2
+import os
+from distutils.core import setup
+from ConfigParser import RawConfigParser
+
+%(func)s
+
+setup(**cfg_to_args())
+"""
+
+
+def generate_setup_py():
+    """Generates a distutils compatible setup.py using an existing setup.cfg.
 
         :raises DistutilsFileError:
             When a setup.py already exists.
 
     handle = open("setup.py", "w")
     try:
-        handle.write(
-            "# Distutils script using distutils2 setup.cfg to call the\n"
-            "# distutils.core.setup() with the right args.\n\n"
-            "import os\n"
-            "from distutils.core import setup\n"
-            "from ConfigParser import RawConfigParser\n\n"
-            "" + getsource(generate_distutils_kwargs_from_setup_cfg) + "\n\n"
-            "kwargs = generate_distutils_kwargs_from_setup_cfg()\n"
-            "setup(**kwargs)\n"
-        )
+        handle.write(_SETUP_TMPL % {'func': getsource(cfg_to_args)})
     finally:
         handle.close()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.