[Python-checkins] distutils2 (merge default -> default): Merge further changes by Montreal sprinters
eric.araujo
python-checkins at python.org
Wed May 16 07:07:27 CEST 2012
http://hg.python.org/distutils2/rev/8d9fbdbd65b0
changeset: 1340:8d9fbdbd65b0
parent: 1336:91ac9c36f09e
parent: 1339:4087d11330a1
user: Éric Araujo <merwok at netwok.org>
date: Wed May 16 01:06:53 2012 -0400
summary:
Merge further changes by Montreal sprinters
files:
distutils2/command/build_scripts.py | 2 +
distutils2/command/cmd.py | 16 +++++-
distutils2/run.py | 3 +-
distutils2/tests/test_command_build_scripts.py | 30 ++++++++++
4 files changed, 49 insertions(+), 2 deletions(-)
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
@@ -56,6 +56,8 @@
ie. starts with "\#!" and contains "python"), then adjust the first
line to refer to the current Python interpreter as we copy.
"""
+ # XXX use self.execute(shutil.rmtree, ...)
+ 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
--- 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/run.py b/distutils2/run.py
--- a/distutils2/run.py
+++ b/distutils2/run.py
@@ -436,6 +436,7 @@
# Pull the current command from the head of the command line
command = args[0]
if not command_re.match(command):
+ self.show_help() # TODO list only commands, not actions
sys.exit('error: invalid command name %r' % command)
self.commands.append(command)
@@ -445,7 +446,7 @@
try:
cmd_class = get_command_class(command)
except PackagingModuleError, msg:
- self.show_help()
+ self.show_help() # TODO list only commands, not actions
sys.exit('error: command %r not recognized' % command)
# XXX We want to push this in distutils2.command
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
@@ -129,6 +129,36 @@
firstline = fp.readline().strip()
self.assertEqual(firstline, '#!pythonx')
+ def test_build_old_scripts_deleted(self):
+ source = self.mkdtemp()
+ target = self.mkdtemp()
+
+ expected = ['script1.py', 'script2.py']
+ self.write_script(source, "script1.py",
+ ("#! /usr/bin/env python2.3\n"
+ "pass\n"))
+ self.write_script(source, "script2.py",
+ ("#!/usr/bin/python\n"
+ "pass\n"))
+
+ cmd = self.get_build_scripts_cmd(
+ target, [os.path.join(source, fn) for fn in expected])
+ cmd.finalize_options()
+ cmd.run()
+
+ built = sorted(os.listdir(target))
+ self.assertEqual(built, expected)
+
+ # if we run build_scripts with a different list of scripts, the old
+ # ones used to be left over in the build directory and installed anyway
+ cmd = self.get_build_scripts_cmd(
+ target, [os.path.join(source, 'script1.py')])
+ cmd.finalize_options()
+ cmd.run()
+
+ built = os.listdir(target)
+ self.assertEqual(built, ['script1.py'])
+
def test_suite():
return unittest.makeSuite(BuildScriptsTestCase)
--
Repository URL: http://hg.python.org/distutils2
More information about the Python-checkins
mailing list