[Python-checkins] python/nondist/sandbox/distutils_refactor/distutils ccompiler.py, 1.1, 1.2 cmd.py, 1.1, 1.2 dep_util.py, 1.1, 1.2 dist.py, 1.1, 1.2 util.py, 1.1, 1.2

anthonybaxter@users.sourceforge.net anthonybaxter at users.sourceforge.net
Fri Jun 10 08:48:16 CEST 2005


Update of /cvsroot/python/python/nondist/sandbox/distutils_refactor/distutils
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25579/distutils

Modified Files:
	ccompiler.py cmd.py dep_util.py dist.py util.py 
Log Message:
first bit of getting rid of fancy_getopt

Index: ccompiler.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/distutils_refactor/distutils/ccompiler.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- ccompiler.py	10 Jun 2005 06:43:22 -0000	1.1
+++ ccompiler.py	10 Jun 2005 06:48:14 -0000	1.2
@@ -1115,16 +1115,13 @@
     """Print list of available compilers (used by the "--help-compiler"
     options to "build", "build_ext", "build_clib").
     """
-    # XXX this "knows" that the compiler option it's describing is
-    # "--compiler", which just happens to be the case for the three
-    # commands that use it.
-    from distutils.fancy_getopt import FancyGetopt
+    from distutils.util import OptionPrettyPrinter
     compilers = []
     for compiler in compiler_class.keys():
         compilers.append(("compiler="+compiler, None,
                           compiler_class[compiler][2]))
     compilers.sort()
-    pretty_printer = FancyGetopt(compilers)
+    pretty_printer = OptionPrettyPrinter(compilers)
     pretty_printer.print_help("List of available compilers:")
 
 

Index: cmd.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/distutils_refactor/distutils/cmd.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- cmd.py	10 Jun 2005 06:43:22 -0000	1.1
+++ cmd.py	10 Jun 2005 06:48:14 -0000	1.2
@@ -160,13 +160,12 @@
 
 
     def dump_options (self, header=None, indent=""):
-        from distutils.fancy_getopt import longopt_xlate
         if header is None:
             header = "command options for '%s':" % self.get_command_name()
         print indent + header
         indent = indent + "  "
         for (option, _, _) in self.user_options:
-            option = string.translate(option, longopt_xlate)
+            option = option.replace('-', '_')
             if option[-1] == "=":
                 option = option[:-1]
             value = getattr(self, option)

Index: dep_util.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/distutils_refactor/distutils/dep_util.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- dep_util.py	10 Jun 2005 06:43:22 -0000	1.1
+++ dep_util.py	10 Jun 2005 06:48:14 -0000	1.2
@@ -12,15 +12,13 @@
 from distutils.errors import DistutilsFileError
 
 
-def newer (source, target, dry_run=0):
+def newer (source, target):
     """Return true if 'source' exists and is more recently modified than
     'target', or if 'source' exists and 'target' doesn't.  Return false if
     both exist and 'target' is the same age or younger than 'source'.
     Raise DistutilsFileError if 'source' does not exist.
     """
     if not os.path.exists(source):
-        if dry_run:
-            return 1
         raise DistutilsFileError, "file '%s' does not exist" % source
     if not os.path.exists(target):
         return 1

Index: dist.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/distutils_refactor/distutils/dist.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- dist.py	10 Jun 2005 06:43:22 -0000	1.1
+++ dist.py	10 Jun 2005 06:48:14 -0000	1.2
@@ -18,7 +18,7 @@
     warnings = None
 
 from distutils.errors import *
-from distutils.fancy_getopt import FancyGetopt, translate_longopt
+from distutils.fancy_getopt import FancyGetopt
 from distutils.util import check_environ, strtobool, rfc822_escape
 from distutils import log
 from distutils.debug import DEBUG
@@ -113,8 +113,7 @@
         ('obsoletes', None,
          "print the list of packages/modules made obsolete")
         ]
-    display_option_names = map(lambda x: translate_longopt(x[0]),
-                               display_options)
+    display_option_names = [x[0].replace('-','_') for x in display_options]
 
     # negative options are options that exclude other options
     negative_opt = {'quiet': 'verbose'}
@@ -444,6 +443,9 @@
         # until we know what the command is.
 
         self.commands = []
+        print "toplevel_options", toplevel_options
+        print "display_options", self.display_options
+        print "negative_opt", self.negative_opt
         parser = FancyGetopt(toplevel_options + self.display_options)
         parser.set_negative_aliases(self.negative_opt)
         parser.set_aliases({'licence': 'license'})
@@ -692,7 +694,7 @@
 
         for (opt, val) in option_order:
             if val and is_display_option.get(opt):
-                opt = translate_longopt(opt)
+                opt = opt.replace('-','_')
                 value = getattr(self.metadata, "get_"+opt)()
                 if opt in ['keywords', 'platforms']:
                     print string.join(value, ',')
@@ -897,7 +899,8 @@
         for (option, (source, value)) in option_dict.items():
             if DEBUG: print "    %s = %s (from %s)" % (option, value, source)
             try:
-                bool_opts = map(translate_longopt, command_obj.boolean_options)
+                bool_opts = [ x.replace('-','_') 
+                                for x in command_obj.boolean_options]
             except AttributeError:
                 bool_opts = []
             try:

Index: util.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/distutils_refactor/distutils/util.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- util.py	10 Jun 2005 06:43:22 -0000	1.1
+++ util.py	10 Jun 2005 06:48:14 -0000	1.2
@@ -444,7 +444,7 @@
 
             cfile_base = os.path.basename(cfile)
             if direct:
-                if force or newer(file, cfile, dry_run):
+                if force or newer(file, cfile):
                     log.info("byte-compiling %s to %s", file, cfile_base)
                     if not dry_run:
                         compile(file, cfile, dfile)
@@ -462,3 +462,18 @@
     lines = map(string.strip, lines)
     header = string.join(lines, '\n' + 8*' ')
     return header
+
+class OptionPrettyPrinter:
+    def __init__(self, options):
+        self.options = options
+
+    def print_help(self, header, file=None):
+        if file is None:
+            file = sys.stdout
+        file.write(header+'\n')
+        # i18n?
+        maxlen = max([len(x[0]) for x in self.options])
+        fmtstr = '  --%%-%ds %%s\n'%(maxlen+1)
+        for arg, ign, help in self.options:
+            file.write(fmtstr%(arg,help))
+



More information about the Python-checkins mailing list