[Python-checkins] distutils2 (merge default -> default): merge commit

eric.araujo python-checkins at python.org
Wed May 16 07:07:27 CEST 2012


http://hg.python.org/distutils2/rev/4087d11330a1
changeset:   1339:4087d11330a1
parent:      1338:fcfa635db609
parent:      1337:463d3014ee4a
user:        Patrice Gauthier <patgauth at gmail.com>
date:        Mon May 14 16:01:47 2012 -0400
summary:
  merge commit

files:
  CHANGES.txt                                    |   5 +
  CONTRIBUTORS.txt                               |   1 +
  distutils2/command/build_scripts.py            |  12 +-
  distutils2/command/cmd.py                      |  16 ++-
  distutils2/tests/test_command_build_scripts.py |  62 +++++++++-
  5 files changed, 81 insertions(+), 15 deletions(-)


diff --git a/CHANGES.txt b/CHANGES.txt
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -8,6 +8,11 @@
 (and last name initial when needed) are given for each item; see
 CONTRIBUTORS.txt for full names.  Bug numbers refer to http://bugs.python.org/.
 
+1.0a5 - 2012-xx-xx
+------------------
+
+- #10374 Now creating scripts everytime when build_scripts is called,
+  as a side effect, --force option has been removed [PierrePaul]
 
 1.0a4 - 2012-03-13
 ------------------
diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt
--- a/CONTRIBUTORS.txt
+++ b/CONTRIBUTORS.txt
@@ -42,6 +42,7 @@
 - Jeremy Kloth
 - Amos Latteier
 - Mathieu Leduc-Hamel
+- Pierre Paul Lefebvre
 - Tshepang Lekhonkhobe
 - Alain Leufroy
 - Martin von Löwis
diff --git a/distutils2/command/build_scripts.py b/distutils2/command/build_scripts.py
--- a/distutils2/command/build_scripts.py
+++ b/distutils2/command/build_scripts.py
@@ -20,17 +20,12 @@
 
     user_options = [
         ('build-dir=', 'd', "directory to build (copy) to"),
-        ('force', 'f', "forcibly build everything (ignore file timestamps"),
         ('executable=', 'e', "specify final destination interpreter path"),
         ]
 
-    boolean_options = ['force']
-
-
     def initialize_options(self):
         self.build_dir = None
         self.scripts = None
-        self.force = None
         self.executable = None
         self.outfiles = None
         self.use_2to3 = False
@@ -41,7 +36,7 @@
         self.set_undefined_options('build',
                                    ('build_scripts', 'build_dir'),
                                    'use_2to3', 'use_2to3_fixers',
-                                   'convert_2to3_doctests', 'force',
+                                   'convert_2to3_doctests',
                                    'executable')
         self.scripts = self.distribution.scripts
 
@@ -61,6 +56,7 @@
         ie. starts with "\#!" and contains "python"), then adjust the first
         line to refer to the current Python interpreter as we copy.
         """
+        self.rmpath(self.build_dir)
         self.mkpath(self.build_dir)
         outfiles = []
         for script in self.scripts:
@@ -69,10 +65,6 @@
             outfile = os.path.join(self.build_dir, os.path.basename(script))
             outfiles.append(outfile)
 
-            if not self.force and not newer(script, outfile):
-                logger.debug("not copying %s (up-to-date)", script)
-                continue
-
             # Always open the file, but ignore failures in dry-run mode --
             # that way, we'll get accurate feedback if we can read the
             # script.
diff --git a/distutils2/command/cmd.py b/distutils2/command/cmd.py
--- a/distutils2/command/cmd.py
+++ b/distutils2/command/cmd.py
@@ -5,7 +5,7 @@
 from distutils2 import util
 from distutils2 import logger
 from distutils2.errors import PackagingOptionError
-from distutils2._backport.shutil import copyfile, move, make_archive
+from distutils2._backport.shutil import copyfile, move, make_archive, rmtree
 
 
 class Command(object):
@@ -365,6 +365,20 @@
             return
         os.makedirs(name, mode)
 
+    def rmpath(self, name, dry_run=None):
+        if dry_run is None:
+            dry_run = self.dry_run
+        name = os.path.normpath(name)
+        if not os.path.isdir(name) or name == '':
+            return
+        if dry_run:
+            head = ''
+            for part in name.split(os.sep):
+                logger.info("removing directory %s%s", head, part)
+                head += part + os.sep
+            return
+        rmtree(name)
+
     def copy_file(self, infile, outfile,
                   preserve_mode=True, preserve_times=True, link=None, level=1):
         """Copy a file respecting dry-run and force flags.
diff --git a/distutils2/tests/test_command_build_scripts.py b/distutils2/tests/test_command_build_scripts.py
--- a/distutils2/tests/test_command_build_scripts.py
+++ b/distutils2/tests/test_command_build_scripts.py
@@ -20,7 +20,7 @@
 
         cmd.finalize_options()
 
-        self.assertTrue(cmd.force)
+        self.assertFalse(cmd.force)
         self.assertEqual(cmd.build_dir, "/foo/bar")
 
     def test_build(self):
@@ -38,13 +38,13 @@
         for name in expected:
             self.assertIn(name, built)
 
-    def get_build_scripts_cmd(self, target, scripts):
+    def get_build_scripts_cmd(self, target, scripts, executable=sys.executable):
         dist = Distribution()
         dist.scripts = scripts
         dist.command_obj["build"] = support.DummyCommand(
             build_scripts=target,
-            force=True,
-            executable=sys.executable,
+            force=False,
+            executable=executable,
             use_2to3=False,
             use_2to3_fixers=None,
             convert_2to3_doctests=None
@@ -105,6 +105,60 @@
         for name in expected:
             self.assertIn(name, built)
 
+    def test_build_dir_recreated(self):
+        source = self.mkdtemp()
+        target = self.mkdtemp()
+        self.write_script(source, 'taunt', '#! /usr/bin/python')
+
+        built = os.path.join(target, 'taunt')
+
+        cmd = self.get_build_scripts_cmd(target, [os.path.join(source, 'taunt')], 'pythona')
+        cmd.finalize_options()
+        cmd.run()
+
+        self.assertEqual(open(built).readline(), '#!pythona\n')
+
+        cmd = self.get_build_scripts_cmd(target, [os.path.join(source, 'taunt')], 'pythonx')
+        cmd.finalize_options()
+        cmd.run()
+
+        self.assertEqual(open(built).readline(), '#!pythonx\n')
+
+    def test_build_old_scripts_deleted(self):
+        source = self.mkdtemp()
+
+        expected = []
+        expected.append("script1.py")
+        self.write_script(source, "script1.py",
+                          ("#! /usr/bin/env python2.3\n"
+                           "# bogus script w/ Python sh-bang\n"
+                           "pass\n"))
+        expected.append("script2.py")
+        self.write_script(source, "script2.py",
+                          ("#!/usr/bin/python\n"
+                           "# bogus script w/ Python sh-bang\n"
+                           "pass\n"))
+
+        target = self.mkdtemp()
+        cmd = self.get_build_scripts_cmd(target,
+                                         [os.path.join(source, fn)
+                                          for fn in expected])
+        cmd.finalize_options()
+        cmd.run()
+
+        built = os.listdir(target)
+        for name in expected:
+            self.assertIn(name, built)
+
+        cmd = self.get_build_scripts_cmd(target, 
+                                        [os.path.join(source, 'script1.py')])
+        cmd.finalize_options()
+        cmd.run()
+
+        built = os.listdir(target)
+        self.assertIn('script1.py', built)
+        self.assertNotIn('script2.py', built)
+        
 def test_suite():
     return unittest.makeSuite(BuildScriptsTestCase)
 

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


More information about the Python-checkins mailing list