diff options
author | Pierre Paul <info@pierre-paul.com> | 2012-05-14 08:36:06 -0400 |
---|---|---|
committer | Pierre Paul <info@pierre-paul.com> | 2012-05-14 08:36:06 -0400 |
commit | 21ef245b09084349f7bdfe4ed103bac55a9ae4e4 (patch) | |
tree | 6a29c60701cae79a5693162d661e9846573b554b | |
parent | ab781d67700f6a0506f255ae9c9a121937a8698b (diff) | |
download | disutils2-21ef245b09084349f7bdfe4ed103bac55a9ae4e4.tar.gz |
Now deleting build-scripts directory before creating it. No more leftovers.
-rw-r--r-- | distutils2/command/build_scripts.py | 1 | ||||
-rw-r--r-- | distutils2/command/cmd.py | 16 | ||||
-rw-r--r-- | distutils2/tests/test_command_build_scripts.py | 35 |
3 files changed, 51 insertions, 1 deletions
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) |