From 80b0aa42676621a920907bdf7bb1f3f5cc47ac12 Mon Sep 17 00:00:00 2001 From: Pierre Paul Date: Sat, 12 May 2012 18:14:31 -0400 Subject: Now creating scripts everytime when build_scripts is called, as a side effect, --force option has been removed --- CHANGES.txt | 5 +++++ CONTRIBUTORS.txt | 1 + distutils2/command/build_scripts.py | 11 +---------- distutils2/tests/test_command_build_scripts.py | 27 ++++++++++++++++++++++---- 4 files changed, 30 insertions(+), 14 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..a274e3a 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 @@ -69,10 +64,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/tests/test_command_build_scripts.py b/distutils2/tests/test_command_build_scripts.py index ab41bee..9747153 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,25 @@ 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_suite(): return unittest.makeSuite(BuildScriptsTestCase) -- cgit v1.2.1 From 21ef245b09084349f7bdfe4ed103bac55a9ae4e4 Mon Sep 17 00:00:00 2001 From: Pierre Paul Date: Mon, 14 May 2012 08:36:06 -0400 Subject: Now deleting build-scripts directory before creating it. No more leftovers. --- distutils2/command/build_scripts.py | 1 + distutils2/command/cmd.py | 16 +++++++++++- distutils2/tests/test_command_build_scripts.py | 35 ++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/distutils2/command/build_scripts.py b/distutils2/command/build_scripts.py index a274e3a..9275378 100644 --- a/distutils2/command/build_scripts.py +++ b/distutils2/command/build_scripts.py @@ -56,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: 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 9747153..1438186 100644 --- a/distutils2/tests/test_command_build_scripts.py +++ b/distutils2/tests/test_command_build_scripts.py @@ -123,6 +123,41 @@ class BuildScriptsTestCase(support.TempdirManager, 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) -- cgit v1.2.1