summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author?ric Araujo <merwok@netwok.org>2012-05-16 01:06:53 -0400
committer?ric Araujo <merwok@netwok.org>2012-05-16 01:06:53 -0400
commit5ffba496119972cddc5e14f6836c8fec44507c5d (patch)
tree4044019eb86635c9ada8b14996b18f03cd529577
parent477f787a64f10e743ba7ed66008d853156b3fed5 (diff)
parent7c7f383ef9e6a6e0189d7515f4b2ec37ffa445a9 (diff)
downloaddisutils2-5ffba496119972cddc5e14f6836c8fec44507c5d.tar.gz
Merge further changes by Montreal sprinters
-rw-r--r--distutils2/command/build_scripts.py2
-rw-r--r--distutils2/command/cmd.py16
-rw-r--r--distutils2/run.py3
-rw-r--r--distutils2/tests/test_command_build_scripts.py30
4 files changed, 49 insertions, 2 deletions
diff --git a/distutils2/command/build_scripts.py b/distutils2/command/build_scripts.py
index 08d32df..38bfa01 100644
--- a/distutils2/command/build_scripts.py
+++ b/distutils2/command/build_scripts.py
@@ -56,6 +56,8 @@ 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.
"""
+ # 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
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/run.py b/distutils2/run.py
index f571baa..71fbe03 100644
--- a/distutils2/run.py
+++ b/distutils2/run.py
@@ -436,6 +436,7 @@ class Dispatcher(object):
# 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 @@ class Dispatcher(object):
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
index 90d2b28..5d7930b 100644
--- a/distutils2/tests/test_command_build_scripts.py
+++ b/distutils2/tests/test_command_build_scripts.py
@@ -129,6 +129,36 @@ class BuildScriptsTestCase(support.TempdirManager,
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)