[Python-checkins] distutils2 (merge default -> default): Branch merge, reverting some of Alexis’ changes.
eric.araujo
python-checkins at python.org
Tue Sep 13 13:43:49 CEST 2011
http://hg.python.org/distutils2/rev/eee8d2a46e62
changeset: 1144:eee8d2a46e62
parent: 1140:e0098d4649a6
parent: 1143:a8ef48dacaff
user: Éric Araujo <merwok at netwok.org>
date: Tue Sep 13 13:28:48 2011 +0200
summary:
Branch merge, reverting some of Alexis’ changes.
The print statement fixes that were in my branch override the print(u'')
calls added by Alexis; the import at function scope were removed for the
usual reasons; d2._backport.hashlib is used if hashlib is not available
instead of md5.
files:
distutils2/_backport/tests/test_sysconfig.py | 13 +-
distutils2/command/install_data.py | 2 +-
distutils2/command/register.py | 16 +-
distutils2/compiler/bcppcompiler.py | 6 +-
distutils2/create.py | 38 ++++----
distutils2/depgraph.py | 20 ++--
distutils2/dist.py | 24 ++--
distutils2/run.py | 43 ++++-----
distutils2/tests/__init__.py | 8 +
distutils2/tests/support.py | 11 +-
distutils2/tests/test_command_build_ext.py | 4 +-
distutils2/tests/test_command_install_dist.py | 10 +-
distutils2/tests/test_command_register.py | 12 +-
distutils2/util.py | 30 +++---
14 files changed, 125 insertions(+), 112 deletions(-)
diff --git a/distutils2/_backport/tests/test_sysconfig.py b/distutils2/_backport/tests/test_sysconfig.py
--- a/distutils2/_backport/tests/test_sysconfig.py
+++ b/distutils2/_backport/tests/test_sysconfig.py
@@ -15,7 +15,7 @@
get_scheme_names, _main, _SCHEMES)
from distutils2.tests import unittest, TESTFN, unlink
-from distutils2.tests.support import EnvironGuard
+from distutils2.tests.support import EnvironRestorer
from test.test_support import TESTFN, unlink
try:
@@ -24,7 +24,10 @@
skip_unless_symlink = unittest.skip(
'requires test.test_support.skip_unless_symlink')
-class TestSysConfig(EnvironGuard, unittest.TestCase):
+
+class TestSysConfig(EnvironRestorer, unittest.TestCase):
+
+ restore_environ = ['MACOSX_DEPLOYMENT_TARGET', 'PATH']
def setUp(self):
super(TestSysConfig, self).setUp()
@@ -245,13 +248,13 @@
# On Windows, the EXE needs to know where pythonXY.dll is at so we have
# to add the directory to the path.
if sys.platform == 'win32':
- os.environ['Path'] = ';'.join((
- os.path.dirname(sys.executable), os.environ['Path']))
+ os.environ['PATH'] = ';'.join((
+ os.path.dirname(sys.executable), os.environ['PATH']))
# Issue 7880
def get(python):
cmd = [python, '-c',
- 'import sysconfig; print(sysconfig.get_platform())']
+ 'import sysconfig; print sysconfig.get_platform()']
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, env=os.environ)
return p.communicate()
real = os.path.realpath(sys.executable)
diff --git a/distutils2/command/install_data.py b/distutils2/command/install_data.py
--- a/distutils2/command/install_data.py
+++ b/distutils2/command/install_data.py
@@ -4,10 +4,10 @@
import os, sys
from shutil import Error
-from distutils2._backport.sysconfig import get_paths, format_value
from distutils2 import logger
from distutils2.util import convert_path
from distutils2.command.cmd import Command
+from distutils2._backport.sysconfig import get_paths, format_value
class install_data(Command):
diff --git a/distutils2/command/register.py b/distutils2/command/register.py
--- a/distutils2/command/register.py
+++ b/distutils2/command/register.py
@@ -144,16 +144,16 @@
4. quit
Your selection [default 1]: ''')
- choice = input()
+ choice = raw_input()
if not choice:
choice = '1'
elif choice not in choices:
- print('Please choose one of the four options!')
+ print 'Please choose one of the four options!'
if choice == '1':
# get the username and password
while not username:
- username = input('Username: ')
+ username = raw_input('Username: ')
while not password:
password = getpass.getpass('Password: ')
@@ -179,7 +179,7 @@
get_pypirc_path())
choice = 'X'
while choice.lower() not in 'yn':
- choice = input('Save your login (y/N)?')
+ choice = raw_input('Save your login (y/N)?')
if not choice:
choice = 'n'
if choice.lower() == 'y':
@@ -190,7 +190,7 @@
data['name'] = data['password'] = data['email'] = ''
data['confirm'] = None
while not data['name']:
- data['name'] = input('Username: ')
+ data['name'] = raw_input('Username: ')
while data['password'] != data['confirm']:
while not data['password']:
data['password'] = getpass.getpass('Password: ')
@@ -199,9 +199,9 @@
if data['password'] != data['confirm']:
data['password'] = ''
data['confirm'] = None
- print("Password and confirm don't match!")
+ print "Password and confirm don't match!"
while not data['email']:
- data['email'] = input(' EMail: ')
+ data['email'] = raw_input(' EMail: ')
code, result = self.post_to_server(data)
if code != 200:
logger.info('server response (%s): %s', code, result)
@@ -212,7 +212,7 @@
data = {':action': 'password_reset'}
data['email'] = ''
while not data['email']:
- data['email'] = input('Your email address: ')
+ data['email'] = raw_input('Your email address: ')
code, result = self.post_to_server(data)
logger.info('server response (%s): %s', code, result)
diff --git a/distutils2/compiler/bcppcompiler.py b/distutils2/compiler/bcppcompiler.py
--- a/distutils2/compiler/bcppcompiler.py
+++ b/distutils2/compiler/bcppcompiler.py
@@ -351,7 +351,5 @@
self.mkpath(os.path.dirname(output_file))
try:
self.spawn(pp_args)
- except PackagingExecError:
- msg = sys.exc_info()[1]
- print(msg)
- raise CompileError(msg)
+ except PackagingExecError, exc:
+ raise CompileError(exc)
diff --git a/distutils2/create.py b/distutils2/create.py
--- a/distutils2/create.py
+++ b/distutils2/create.py
@@ -130,7 +130,7 @@
if answer and answer[0].lower() in 'yn':
return answer[0].lower()
- print('\nERROR: You must select "Y" or "N".\n')
+ print '\nERROR: You must select "Y" or "N".\n'
def ask(question, default=None, helptext=None, required=True,
@@ -154,19 +154,19 @@
line = sys.stdin.readline().strip()
if line == '?':
- print('=' * 70)
- print(helptext)
- print('=' * 70)
+ print '=' * 70
+ print helptext
+ print '=' * 70
continue
if default and not line:
return default
if not line and required:
- print('*' * 70)
- print('This value cannot be empty.')
- print('===========================')
+ print '*' * 70
+ print 'This value cannot be empty.'
+ print '==========================='
if helptext:
- print(helptext)
- print('*' * 70)
+ print helptext
+ print '*' * 70
continue
return line
@@ -273,9 +273,9 @@
def _write_cfg(self):
if os.path.exists(_FILENAME):
if os.path.exists('%s.old' % _FILENAME):
- print("ERROR: %(name)s.old backup exists, please check that "
- "current %(name)s is correct and remove %(name)s.old" %
- {'name': _FILENAME})
+ print ('ERROR: %(name)s.old backup exists, please check that '
+ 'current %(name)s is correct and remove %(name)s.old' %
+ {'name': _FILENAME})
return
shutil.move(_FILENAME, '%s.old' % _FILENAME)
@@ -324,7 +324,7 @@
fp.close()
os.chmod(_FILENAME, 00644)
- print('Wrote "%s".' % _FILENAME)
+ print 'Wrote %r.' % _FILENAME
def convert_py_to_cfg(self):
"""Generate a setup.cfg from an existing setup.py.
@@ -631,8 +631,8 @@
break
if len(found_list) == 0:
- print('ERROR: Could not find a matching license for "%s"' %
- license)
+ print ('ERROR: Could not find a matching license for "%s"' %
+ license)
continue
question = 'Matching licenses:\n\n'
@@ -653,8 +653,8 @@
try:
index = found_list[int(choice) - 1]
except ValueError:
- print("ERROR: Invalid selection, type a number from the list "
- "above.")
+ print ('ERROR: Invalid selection, type a number from the list '
+ 'above.')
classifiers.add(_CLASSIFIERS_LIST[index])
@@ -677,8 +677,8 @@
classifiers.add(key)
return
except (IndexError, ValueError):
- print("ERROR: Invalid selection, type a single digit "
- "number.")
+ print ('ERROR: Invalid selection, type a single digit '
+ 'number.')
def main():
diff --git a/distutils2/depgraph.py b/distutils2/depgraph.py
--- a/distutils2/depgraph.py
+++ b/distutils2/depgraph.py
@@ -238,19 +238,19 @@
e = sys.exc_info()[1]
tempout.seek(0)
tempout = tempout.read()
- print(u'Could not generate the graph')
- print(tempout)
- print(e)
+ print 'Could not generate the graph'
+ print tempout
+ print e
sys.exit(1)
for dist, reqs in graph.missing.items():
if len(reqs) > 0:
- print(u"Warning: Missing dependencies for %r:" % dist.name,
- ", ".join(reqs))
+ print 'Warning: Missing dependencies for %r:' % dist.name, \
+ ', '.join(reqs)
# XXX replace with argparse
if len(sys.argv) == 1:
- print(u'Dependency graph:')
- print(u' ', repr(graph).replace(u'\n', u'\n '))
+ print 'Dependency graph:'
+ print ' ', repr(graph).replace('\n', '\n ')
sys.exit(0)
elif len(sys.argv) > 1 and sys.argv[1] in ('-d', '--dot'):
if len(sys.argv) > 2:
@@ -263,11 +263,11 @@
f.close()
tempout.seek(0)
tempout = tempout.read()
- print(tempout)
- print('Dot file written at %r' % filename)
+ print tempout
+ print 'Dot file written at %r' % filename
sys.exit(0)
else:
- print('Supported option: -d [filename]')
+ print 'Supported option: -d [filename]'
sys.exit(1)
diff --git a/distutils2/dist.py b/distutils2/dist.py
--- a/distutils2/dist.py
+++ b/distutils2/dist.py
@@ -511,14 +511,14 @@
options = self.global_options
parser.set_option_table(options)
parser.print_help(self.common_usage + "\nGlobal options:")
- print(u'')
+ print
if display_options:
parser.set_option_table(self.display_options)
parser.print_help(
"Information display options (just display " +
"information, ignore any commands)")
- print(u'')
+ print
for command in self.commands:
if isinstance(command, type) and issubclass(command, Command):
@@ -531,9 +531,9 @@
else:
parser.set_option_table(cls.user_options)
parser.print_help("Options for %r command:" % cls.__name__)
- print(u'')
+ print
- print(gen_usage(self.script_name))
+ print gen_usage(self.script_name)
def handle_display_options(self, option_order):
"""If there were any non-global "display-only" options
@@ -546,8 +546,8 @@
# we ignore "foo bar").
if self.help_commands:
self.print_commands()
- print(u'')
- print(gen_usage(self.script_name))
+ print
+ print gen_usage(self.script_name)
return 1
# If user supplied any of the "display metadata" options, then
@@ -563,12 +563,12 @@
opt = opt.replace('-', '_')
value = self.metadata[opt]
if opt in ('keywords', 'platform'):
- print(','.join(value))
+ print ','.join(value)
elif opt in ('classifier', 'provides', 'requires',
'obsoletes'):
- print('\n'.join(value))
+ print '\n'.join(value)
else:
- print(value)
+ print value
any_display_options = True
return any_display_options
@@ -577,14 +577,14 @@
"""Print a subset of the list of all commands -- used by
'print_commands()'.
"""
- print(header + ":")
+ print header + ":"
for cmd in commands:
cls = self.cmdclass.get(cmd) or get_command_class(cmd)
description = getattr(cls, 'description',
'(no description available)')
- print(" %-*s %s" % (max_length, cmd, description))
+ print " %-*s %s" % (max_length, cmd, description)
def _get_command_groups(self):
"""Helper function to retrieve all the command class names divided
@@ -614,7 +614,7 @@
"Standard commands",
max_length)
if extra_commands:
- print(u'')
+ print
self.print_command_list(extra_commands,
"Extra commands",
max_length)
diff --git a/distutils2/run.py b/distutils2/run.py
--- a/distutils2/run.py
+++ b/distutils2/run.py
@@ -10,7 +10,9 @@
from distutils2.dist import Distribution
from distutils2.util import _is_archive_file, generate_setup_py
from distutils2.command import get_command_class, STANDARD_COMMANDS
+from distutils2.install import install, install_local_project, remove
from distutils2.database import get_distribution, get_distributions
+from distutils2.depgraph import generate_graph
from distutils2.fancy_getopt import FancyGetopt
from distutils2.errors import (PackagingArgError, PackagingError,
PackagingModuleError, PackagingClassError,
@@ -197,7 +199,7 @@
def wrapper(*args, **kwargs):
f_args = args[1]
if '--help' in f_args or '-h' in f_args:
- print(self.help_msg)
+ print self.help_msg
return
return f(*args, **kwargs)
return wrapper
@@ -217,7 +219,6 @@
@action_help(graph_usage)
def _graph(dispatcher, args, **kw):
- from distutils2.depgraph import generate_graph
name = args[1]
dist = get_distribution(name, use_egg_info=True)
if dist is None:
@@ -226,12 +227,11 @@
else:
dists = get_distributions(use_egg_info=True)
graph = generate_graph(dists)
- print(graph.repr_node(dist))
+ print graph.repr_node(dist)
@action_help(install_usage)
def _install(dispatcher, args, **kw):
- from distutils2.install import install, install_local_project
# first check if we are in a source directory
if len(args) < 2:
# are we inside a project dir?
@@ -279,18 +279,17 @@
for key in keys:
if key in metadata:
- print(metadata._convert_name(key) + ':')
+ print metadata._convert_name(key) + ':'
value = metadata[key]
if isinstance(value, list):
for v in value:
- print(' ', v)
+ print ' ', v
else:
- print(' ', value.replace('\n', '\n '))
+ print ' ', value.replace('\n', '\n ')
@action_help(remove_usage)
def _remove(distpatcher, args, **kw):
- from distutils2.install import remove
opts = _parse_args(args[1:], 'y', [])
if 'y' in opts:
auto_confirm = True
@@ -316,14 +315,14 @@
commands = STANDARD_COMMANDS # + extra commands
if args == ['--list-commands']:
- print('List of available commands:')
+ print 'List of available commands:'
cmds = sorted(commands)
for cmd in cmds:
cls = dispatcher.cmdclass.get(cmd) or get_command_class(cmd)
desc = getattr(cls, 'description',
'(no description available)')
- print(' %s: %s' % (cmd, desc))
+ print ' %s: %s' % (cmd, desc)
return
while args:
@@ -361,7 +360,7 @@
number = 0
for dist in results:
- print('%r %s (from %r)' % (dist.name, dist.version, dist.path))
+ print '%r %s (from %r)' % (dist.name, dist.version, dist.path)
number += 1
if number == 0:
@@ -574,18 +573,18 @@
# late import because of mutual dependence between these modules
from distutils2.command.cmd import Command
- print('Usage: pysetup [options] action [action_options]')
- print(u'')
+ print 'Usage: pysetup [options] action [action_options]'
+ print
if global_options_:
self.print_usage(self.parser)
- print(u'')
+ print
if display_options_:
parser.set_option_table(display_options)
parser.print_help(
"Information display options (just display " +
"information, ignore any commands)")
- print(u'')
+ print
for command in commands:
if isinstance(command, type) and issubclass(command, Command):
@@ -599,15 +598,15 @@
parser.set_option_table(cls.user_options)
parser.print_help("Options for %r command:" % cls.__name__)
- print(u'')
+ print
def _show_command_help(self, command):
if isinstance(command, basestring):
command = get_command_class(command)
desc = getattr(command, 'description', '(no description available)')
- print('Description:', desc)
- print(u'')
+ print 'Description:', desc
+ print
if (hasattr(command, 'help_options') and
isinstance(command.help_options, list)):
@@ -617,7 +616,7 @@
self.parser.set_option_table(command.user_options)
self.parser.print_help("Options:")
- print(u'')
+ print
def _get_command_groups(self):
"""Helper function to retrieve all the command class names divided
@@ -644,7 +643,7 @@
self.print_command_list(std_commands, "Standard commands", max_length)
if extra_commands:
- print(u'')
+ print
self.print_command_list(extra_commands, "Extra commands",
max_length)
@@ -652,14 +651,14 @@
"""Print a subset of the list of all commands -- used by
'print_commands()'.
"""
- print(header + ":")
+ print header + ":"
for cmd in commands:
cls = self.cmdclass.get(cmd) or get_command_class(cmd)
description = getattr(cls, 'description',
'(no description available)')
- print(" %-*s %s" % (max_length, cmd, description))
+ print " %-*s %s" % (max_length, cmd, description)
def __call__(self):
if self.action is None:
diff --git a/distutils2/tests/__init__.py b/distutils2/tests/__init__.py
--- a/distutils2/tests/__init__.py
+++ b/distutils2/tests/__init__.py
@@ -16,6 +16,7 @@
import os
import sys
import unittest2 as unittest
+from distutils2.tests.support import TESTFN
# XXX move helpers to support, add tests for them, remove things that
# duplicate test.support (or keep them for the backport; needs thinking)
@@ -130,3 +131,10 @@
del sys.modules[name]
except KeyError:
pass
+
+
+def unlink(filename):
+ try:
+ os.unlink(filename)
+ except OSError:
+ pass
diff --git a/distutils2/tests/support.py b/distutils2/tests/support.py
--- a/distutils2/tests/support.py
+++ b/distutils2/tests/support.py
@@ -326,9 +326,9 @@
except UnicodeEncodeError:
pass
else:
- print('WARNING: The filename %r CAN be encoded by the filesystem encoding (%s). '
- 'Unicode filename tests may not be effective'
- % (TESTFN_UNENCODABLE, TESTFN_ENCODING))
+ print ('WARNING: The filename %r CAN be encoded by the filesystem encoding (%s). '
+ 'Unicode filename tests may not be effective'
+ % (TESTFN_UNENCODABLE, TESTFN_ENCODING))
TESTFN_UNENCODABLE = None
# Mac OS X denies unencodable filenames (invalid utf-8)
elif sys.platform != 'darwin':
@@ -503,3 +503,8 @@
except KeyError:
pass
+try:
+ from test.test_support import skip_unless_symlink
+except ImportError:
+ skip_unless_symlink = unittest.skip(
+ 'requires test.test_support.skip_unless_symlink')
diff --git a/distutils2/tests/test_command_build_ext.py b/distutils2/tests/test_command_build_ext.py
--- a/distutils2/tests/test_command_build_ext.py
+++ b/distutils2/tests/test_command_build_ext.py
@@ -465,8 +465,8 @@
src = _get_source_filename()
if not os.path.exists(src):
if verbose:
- print('test_command_build_ext: Cannot find source code (test'
- ' must run in python build dir)')
+ print ('test_command_build_ext: Cannot find source code (test'
+ ' must run in python build dir)')
return unittest.TestSuite()
else:
return unittest.makeSuite(BuildExtTestCase)
diff --git a/distutils2/tests/test_command_install_dist.py b/distutils2/tests/test_command_install_dist.py
--- a/distutils2/tests/test_command_install_dist.py
+++ b/distutils2/tests/test_command_install_dist.py
@@ -3,17 +3,17 @@
import os
import sys
-from sysconfig import (get_scheme_names, get_config_vars,
- _SCHEMES, get_config_var, get_path)
-
-_CONFIG_VARS = get_config_vars()
-
from distutils2.command.install_dist import install_dist
from distutils2.dist import Distribution
from distutils2.errors import PackagingOptionError
from distutils2.tests import unittest, support
+from distutils2._backport.sysconfig import (
+ get_scheme_names, get_config_vars, _SCHEMES, get_config_var, get_path)
+
+_CONFIG_VARS = get_config_vars()
+
class InstallTestCase(support.TempdirManager,
support.LoggingCatcher,
diff --git a/distutils2/tests/test_command_register.py b/distutils2/tests/test_command_register.py
--- a/distutils2/tests/test_command_register.py
+++ b/distutils2/tests/test_command_register.py
@@ -120,7 +120,7 @@
# Password : 'password'
# Save your login (y/N)? : 'y'
inputs = Inputs('1', 'tarek', 'y')
- register_module.input = inputs
+ register_module.raw_input = inputs
cmd.ensure_finalized()
cmd.run()
@@ -168,7 +168,7 @@
# this test runs choice 2
cmd = self._get_cmd()
inputs = Inputs('2', 'tarek', 'tarek at ziade.org')
- register_module.input = inputs
+ register_module.raw_input = inputs
# let's run the command
# FIXME does this send a real request? use a mock server
cmd.ensure_finalized()
@@ -185,7 +185,7 @@
# this test runs choice 3
cmd = self._get_cmd()
inputs = Inputs('3', 'tarek at ziade.org')
- register_module.input = inputs
+ register_module.raw_input = inputs
cmd.ensure_finalized()
cmd.run()
@@ -208,7 +208,7 @@
cmd.ensure_finalized()
cmd.strict = True
inputs = Inputs('1', 'tarek', 'y')
- register_module.input = inputs
+ register_module.raw_input = inputs
self.assertRaises(PackagingSetupError, cmd.run)
# metadata is OK but long_description is broken
@@ -229,7 +229,7 @@
cmd.ensure_finalized()
cmd.strict = True
inputs = Inputs('1', 'tarek', 'y')
- register_module.input = inputs
+ register_module.raw_input = inputs
cmd.ensure_finalized()
cmd.run()
@@ -237,7 +237,7 @@
cmd = self._get_cmd()
cmd.ensure_finalized()
inputs = Inputs('1', 'tarek', 'y')
- register_module.input = inputs
+ register_module.raw_input = inputs
cmd.ensure_finalized()
cmd.run()
diff --git a/distutils2/util.py b/distutils2/util.py
--- a/distutils2/util.py
+++ b/distutils2/util.py
@@ -1,33 +1,33 @@
"""Miscellaneous utility functions."""
-import codecs
import os
import re
import csv
import sys
import errno
+import codecs
import shutil
import string
-try:
- from hashlib import md5
-except ImportError: #<2.5
- from md5 import md5
import tarfile
import zipfile
import posixpath
import subprocess
-try:
- from glob import iglob as std_iglob
-except ImportError:#<2.5
- from glob import glob as std_iglob
from fnmatch import fnmatchcase
from inspect import getsource
from ConfigParser import RawConfigParser
+try:
+ from glob import iglob as std_iglob
+except ImportError:
+ from glob import glob as std_iglob
+try:
+ import hashlib
+except ImportError:
+ from distutils2._backport import hashlib
from distutils2 import logger
from distutils2.errors import (PackagingPlatformError, PackagingFileError,
- PackagingByteCompileError, PackagingExecError,
- InstallationException, PackagingInternalError)
+ PackagingByteCompileError, PackagingExecError,
+ InstallationException, PackagingInternalError)
from distutils2._backport import sysconfig
_PLATFORM = None
@@ -1156,11 +1156,11 @@
def ask(message, options):
"""Prompt the user with *message*; *options* contains allowed responses."""
while True:
- response = input(message)
+ response = raw_input(message)
response = response.strip().lower()
if response not in options:
- print('invalid response:', repr(response))
- print('choose one of', ', '.join(repr(o) for o in options))
+ print 'invalid response:', repr(response)
+ print 'choose one of', ', '.join(repr(o) for o in options)
else:
return response
@@ -1212,7 +1212,7 @@
# do not put size and md5 hash, as in PEP-376
writer.writerow((fpath, '', ''))
else:
- hash = md5()
+ hash = hashlib.md5()
fp = open(fpath, 'rb')
hash.update(fp.read())
fp.close()
--
Repository URL: http://hg.python.org/distutils2
More information about the Python-checkins
mailing list