summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrice Gauthier <patgauth@gmail.com>2012-05-14 16:01:47 -0400
committerPatrice Gauthier <patgauth@gmail.com>2012-05-14 16:01:47 -0400
commit7c7f383ef9e6a6e0189d7515f4b2ec37ffa445a9 (patch)
treef9561bf0236d4b9903a07254bfa494d4625fcab1
parent132a6f08cf60ac518fd6e7ba91b8efd6a082af4d (diff)
parent21ef245b09084349f7bdfe4ed103bac55a9ae4e4 (diff)
downloaddisutils2-7c7f383ef9e6a6e0189d7515f4b2ec37ffa445a9.tar.gz
merge commit
-rw-r--r--CHANGES.txt5
-rw-r--r--CONTRIBUTORS.txt1
-rw-r--r--distutils2/command/build_scripts.py12
-rw-r--r--distutils2/command/cmd.py16
-rw-r--r--distutils2/tests/test_command_build_scripts.py62
5 files changed, 81 insertions, 15 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 698667f..e77005a 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -8,6 +8,11 @@ their clones, and all changes that have a bug report. Contributors' first names
(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
index e33eb16..f72c456 100644
--- a/CONTRIBUTORS.txt
+++ b/CONTRIBUTORS.txt
@@ -42,6 +42,7 @@ Thanks to:
- 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
index 901a679..9275378 100644
--- a/distutils2/command/build_scripts.py
+++ b/distutils2/command/build_scripts.py
@@ -20,17 +20,12 @@ class build_scripts(Command, Mixin2to3):
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 @@ class build_scripts(Command, Mixin2to3):
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 @@ class build_scripts(Command, Mixin2to3):
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 @@ class build_scripts(Command, Mixin2to3):
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
index 1cdae14..3dc6e0f 100644
--- a/distutils2/command/cmd.py
+++ b/distutils2/command/cmd.py
@@ -5,7 +5,7 @@ import re
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 @@ class Command(object):
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
index ab41bee..1438186 100644
--- a/distutils2/tests/test_command_build_scripts.py
+++ b/distutils2/tests/test_command_build_scripts.py
@@ -20,7 +20,7 @@ class BuildScriptsTestCase(support.TempdirManager,
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 @@ class BuildScriptsTestCase(support.TempdirManager,
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 @@ class BuildScriptsTestCase(support.TempdirManager,
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)