[Python-checkins] distutils2: Make set_undefined_options more friendly

tarek.ziade python-checkins at python.org
Sun Aug 8 11:50:46 CEST 2010


tarek.ziade pushed 60931bb3e1d3 to distutils2:

http://hg.python.org/distutils2/rev/60931bb3e1d3
changeset:   439:60931bb3e1d3
user:        ?ric Araujo <merwok at netwok.org>
date:        Wed Aug 04 18:12:31 2010 +0200
summary:     Make set_undefined_options more friendly
files:       src/distutils2/command/bdist_dumb.py, src/distutils2/command/bdist_msi.py, src/distutils2/command/bdist_wininst.py, src/distutils2/command/build_clib.py, src/distutils2/command/build_ext.py, src/distutils2/command/build_py.py, src/distutils2/command/build_scripts.py, src/distutils2/command/clean.py, src/distutils2/command/cmd.py, src/distutils2/command/install.py, src/distutils2/command/install_data.py, src/distutils2/command/install_headers.py, src/distutils2/command/install_lib.py, src/distutils2/command/install_scripts.py

diff --git a/src/distutils2/command/bdist_dumb.py b/src/distutils2/command/bdist_dumb.py
--- a/src/distutils2/command/bdist_dumb.py
+++ b/src/distutils2/command/bdist_dumb.py
@@ -77,9 +77,7 @@
                       ("don't know how to create dumb built distributions " +
                        "on platform %s") % os.name
 
-        self.set_undefined_options('bdist',
-                                   ('dist_dir', 'dist_dir'),
-                                   ('plat_name', 'plat_name'))
+        self.set_undefined_options('bdist', 'dist_dir', 'plat_name')
 
     def run(self):
         if not self.skip_build:
diff --git a/src/distutils2/command/bdist_msi.py b/src/distutils2/command/bdist_msi.py
--- a/src/distutils2/command/bdist_msi.py
+++ b/src/distutils2/command/bdist_msi.py
@@ -153,10 +153,7 @@
         else:
             self.versions = list(self.all_versions)
 
-        self.set_undefined_options('bdist',
-                                   ('dist_dir', 'dist_dir'),
-                                   ('plat_name', 'plat_name'),
-                                   )
+        self.set_undefined_options('bdist', 'dist_dir', 'plat_name')
 
         if self.pre_install_script:
             raise DistutilsOptionError, "the pre-install-script feature is not yet implemented"
diff --git a/src/distutils2/command/bdist_wininst.py b/src/distutils2/command/bdist_wininst.py
--- a/src/distutils2/command/bdist_wininst.py
+++ b/src/distutils2/command/bdist_wininst.py
@@ -100,10 +100,7 @@
                       " option must be specified" % (short_version,)
             self.target_version = short_version
 
-        self.set_undefined_options('bdist',
-                                   ('dist_dir', 'dist_dir'),
-                                   ('plat_name', 'plat_name'),
-                                  )
+        self.set_undefined_options('bdist', 'dist_dir', 'plat_name')
 
         if self.install_script:
             for script in self.distribution.scripts:
diff --git a/src/distutils2/command/build_clib.py b/src/distutils2/command/build_clib.py
--- a/src/distutils2/command/build_clib.py
+++ b/src/distutils2/command/build_clib.py
@@ -76,9 +76,7 @@
         self.set_undefined_options('build',
                                    ('build_temp', 'build_clib'),
                                    ('build_temp', 'build_temp'),
-                                   ('compiler', 'compiler'),
-                                   ('debug', 'debug'),
-                                   ('force', 'force'))
+                                   'compiler', 'debug', 'force')
 
         self.libraries = self.distribution.libraries
         if self.libraries:
diff --git a/src/distutils2/command/build_ext.py b/src/distutils2/command/build_ext.py
--- a/src/distutils2/command/build_ext.py
+++ b/src/distutils2/command/build_ext.py
@@ -177,13 +177,8 @@
 
     def finalize_options(self):
         self.set_undefined_options('build',
-                                   ('build_lib', 'build_lib'),
-                                   ('build_temp', 'build_temp'),
-                                   ('compiler', 'compiler'),
-                                   ('debug', 'debug'),
-                                   ('force', 'force'),
-                                   ('plat_name', 'plat_name'),
-                                   )
+                                   'build_lib', 'build_temp', 'compiler',
+                                   'debug', 'force', 'plat_name')
 
         if self.package is None:
             self.package = self.distribution.ext_package
diff --git a/src/distutils2/command/build_py.py b/src/distutils2/command/build_py.py
--- a/src/distutils2/command/build_py.py
+++ b/src/distutils2/command/build_py.py
@@ -95,9 +95,7 @@
         self._doctests_2to3 = []
 
     def finalize_options(self):
-        self.set_undefined_options('build',
-                                   ('build_lib', 'build_lib'),
-                                   ('force', 'force'))
+        self.set_undefined_options('build', 'build_lib', 'force')
 
         # Get the distribution options that are aliases for build_py
         # options -- list of packages and list of modules.
diff --git a/src/distutils2/command/build_scripts.py b/src/distutils2/command/build_scripts.py
--- a/src/distutils2/command/build_scripts.py
+++ b/src/distutils2/command/build_scripts.py
@@ -40,8 +40,7 @@
     def finalize_options (self):
         self.set_undefined_options('build',
                                    ('build_scripts', 'build_dir'),
-                                   ('force', 'force'),
-                                   ('executable', 'executable'))
+                                   'force', 'executable')
         self.scripts = self.distribution.scripts
 
     def get_source_files(self):
diff --git a/src/distutils2/command/clean.py b/src/distutils2/command/clean.py
--- a/src/distutils2/command/clean.py
+++ b/src/distutils2/command/clean.py
@@ -40,13 +40,9 @@
         self.all = None
 
     def finalize_options(self):
-        self.set_undefined_options('build',
-                                   ('build_base', 'build_base'),
-                                   ('build_lib', 'build_lib'),
-                                   ('build_scripts', 'build_scripts'),
-                                   ('build_temp', 'build_temp'))
-        self.set_undefined_options('bdist',
-                                   ('bdist_base', 'bdist_base'))
+        self.set_undefined_options('build', 'build_base', 'build_lib',
+                                   'build_scripts', 'build_temp')
+        self.set_undefined_options('bdist', 'bdist_base')
 
     def run(self):
         # remove the build/temp.<plat> directory (unless it's already
diff --git a/src/distutils2/command/cmd.py b/src/distutils2/command/cmd.py
--- a/src/distutils2/command/cmd.py
+++ b/src/distutils2/command/cmd.py
@@ -297,26 +297,30 @@
         else:
             return self.__class__.__name__
 
-    def set_undefined_options(self, src_cmd, *option_pairs):
-        """Set the values of any "undefined" options from corresponding
-        option values in some other command object.  "Undefined" here means
-        "is None", which is the convention used to indicate that an option
-        has not been changed between 'initialize_options()' and
-        'finalize_options()'.  Usually called from 'finalize_options()' for
-        options that depend on some other command rather than another
-        option of the same command.  'src_cmd' is the other command from
-        which option values will be taken (a command object will be created
-        for it if necessary); the remaining arguments are
-        '(src_option,dst_option)' tuples which mean "take the value of
-        'src_option' in the 'src_cmd' command object, and copy it to
-        'dst_option' in the current command object".
+    def set_undefined_options(self, src_cmd, *options):
+        """Set values of undefined options from another command.
+
+        Undefined options are options set to None, which is the convention
+        used to indicate that an option has not been changed between
+        'initialize_options()' and 'finalize_options()'.  This method is
+        usually called from 'finalize_options()' for options that depend on
+        some other command rather than another option of the same command,
+        typically subcommands.
+
+        The 'src_cmd' argument is the other command from which option values
+        will be taken (a command object will be created for it if necessary);
+        the remaining positional arguments are strings that give the name of
+        the option to set. If the name is different on the source and target
+        command, you can pass a tuple with '(name_on_source, name_on_dest)' so
+        that 'self.name_on_dest' will be set from 'src_cmd.name_on_source'.
         """
-
-        # Option_pairs: list of (src_option, dst_option) tuples
-
         src_cmd_obj = self.distribution.get_command_obj(src_cmd)
         src_cmd_obj.ensure_finalized()
-        for (src_option, dst_option) in option_pairs:
+        for obj in options:
+            if isinstance(obj, tuple):
+                src_option, dst_option = obj
+            else:
+                src_option, dst_option = obj, obj
             if getattr(self, dst_option) is None:
                 setattr(self, dst_option,
                         getattr(src_cmd_obj, src_option))
diff --git a/src/distutils2/command/install.py b/src/distutils2/command/install.py
--- a/src/distutils2/command/install.py
+++ b/src/distutils2/command/install.py
@@ -317,9 +317,7 @@
         self.dump_dirs("after prepending root")
 
         # Find out the build directories, ie. where to install from.
-        self.set_undefined_options('build',
-                                   ('build_base', 'build_base'),
-                                   ('build_lib', 'build_lib'))
+        self.set_undefined_options('build', 'build_base', 'build_lib')
 
         # Punt on doc directories for now -- after all, we're punting on
         # documentation completely!
diff --git a/src/distutils2/command/install_data.py b/src/distutils2/command/install_data.py
--- a/src/distutils2/command/install_data.py
+++ b/src/distutils2/command/install_data.py
@@ -37,9 +37,7 @@
     def finalize_options(self):
         self.set_undefined_options('install',
                                    ('install_data', 'install_dir'),
-                                   ('root', 'root'),
-                                   ('force', 'force'),
-                                  )
+                                   'root', 'force')
 
     def run(self):
         self.mkpath(self.install_dir)
diff --git a/src/distutils2/command/install_headers.py b/src/distutils2/command/install_headers.py
--- a/src/distutils2/command/install_headers.py
+++ b/src/distutils2/command/install_headers.py
@@ -29,8 +29,7 @@
     def finalize_options(self):
         self.set_undefined_options('install',
                                    ('install_headers', 'install_dir'),
-                                   ('force', 'force'))
-
+                                   'force')
 
     def run(self):
         headers = self.distribution.headers
diff --git a/src/distutils2/command/install_lib.py b/src/distutils2/command/install_lib.py
--- a/src/distutils2/command/install_lib.py
+++ b/src/distutils2/command/install_lib.py
@@ -68,11 +68,7 @@
         self.set_undefined_options('install',
                                    ('build_lib', 'build_dir'),
                                    ('install_lib', 'install_dir'),
-                                   ('force', 'force'),
-                                   ('compile', 'compile'),
-                                   ('optimize', 'optimize'),
-                                   ('skip_build', 'skip_build'),
-                                  )
+                                   'force', 'compile', 'optimize', 'skip_build')
 
         if self.compile is None:
             self.compile = 1
diff --git a/src/distutils2/command/install_scripts.py b/src/distutils2/command/install_scripts.py
--- a/src/distutils2/command/install_scripts.py
+++ b/src/distutils2/command/install_scripts.py
@@ -36,9 +36,7 @@
         self.set_undefined_options('build', ('build_scripts', 'build_dir'))
         self.set_undefined_options('install',
                                    ('install_scripts', 'install_dir'),
-                                   ('force', 'force'),
-                                   ('skip_build', 'skip_build'),
-                                  )
+                                   'force', 'skip_build')
 
     def run (self):
         if not self.skip_build:

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


More information about the Python-checkins mailing list