[Python-checkins] distutils2: Pull fixes from jkloth
tarek.ziade
python-checkins at python.org
Thu Jul 15 01:38:06 CEST 2010
tarek.ziade pushed 70b98f177413 to distutils2:
http://hg.python.org/distutils2/rev/70b98f177413
changeset: 367:70b98f177413
tag: tip
parent: 360:2a9ad83361f7
parent: 366:5b9c3c536275
user: ?ric Araujo <merwok at netwok.org>
date: Wed Jul 14 15:59:45 2010 +0200
summary: Pull fixes from jkloth
files:
diff --git a/src/distutils2/command/build_ext.py b/src/distutils2/command/build_ext.py
--- a/src/distutils2/command/build_ext.py
+++ b/src/distutils2/command/build_ext.py
@@ -188,7 +188,24 @@
if self.package is None:
self.package = self.distribution.ext_package
+ # Ensure that the list of extensions is valid, i.e. it is a list of
+ # Extension objects.
self.extensions = self.distribution.ext_modules
+ if self.extensions:
+ if not isinstance(self.extensions, (list, tuple)):
+ type_name = (self.extensions is None and 'None'
+ or type(self.extensions).__name__)
+ raise DistutilsSetupError(
+ "'ext_modules' must be a sequence of Extension instances,"
+ " not %s" % (type_name,))
+ for i, ext in enumerate(self.extensions):
+ if isinstance(ext, Extension):
+ continue # OK! (assume type-checking done
+ # by Extension constructor)
+ type_name = (ext is None and 'None' or type(ext).__name__)
+ raise DistutilsSetupError(
+ "'ext_modules' item %d must be an Extension instance,"
+ " not %s" % (i, type_name))
# Make sure Python's include directories (for Python.h, pyconfig.h,
# etc.) are in the include search path.
@@ -396,86 +413,7 @@
# Now actually compile and link everything.
self.build_extensions()
- def check_extensions_list(self, extensions):
- """Ensure that the list of extensions (presumably provided as a
- command option 'extensions') is valid, i.e. it is a list of
- Extension objects. We also support the old-style list of 2-tuples,
- where the tuples are (ext_name, build_info), which are converted to
- Extension instances here.
-
- Raise DistutilsSetupError if the structure is invalid anywhere;
- just returns otherwise.
- """
- if not isinstance(extensions, list):
- raise DistutilsSetupError, \
- "'ext_modules' option must be a list of Extension instances"
-
- for i, ext in enumerate(extensions):
- if isinstance(ext, Extension):
- continue # OK! (assume type-checking done
- # by Extension constructor)
-
- if not isinstance(ext, tuple) or len(ext) != 2:
- raise DistutilsSetupError, \
- ("each element of 'ext_modules' option must be an "
- "Extension instance or 2-tuple")
-
- ext_name, build_info = ext
-
- log.warn(("old-style (ext_name, build_info) tuple found in "
- "ext_modules for extension '%s'"
- "-- please convert to Extension instance" % ext_name))
-
- if not (isinstance(ext_name, str) and
- extension_name_re.match(ext_name)):
- raise DistutilsSetupError, \
- ("first element of each tuple in 'ext_modules' "
- "must be the extension name (a string)")
-
- if not isinstance(build_info, dict):
- raise DistutilsSetupError, \
- ("second element of each tuple in 'ext_modules' "
- "must be a dictionary (build info)")
-
- # OK, the (ext_name, build_info) dict is type-safe: convert it
- # to an Extension instance.
- ext = Extension(ext_name, build_info['sources'])
-
- # Easy stuff: one-to-one mapping from dict elements to
- # instance attributes.
- for key in ('include_dirs', 'library_dirs', 'libraries',
- 'extra_objects', 'extra_compile_args',
- 'extra_link_args'):
- val = build_info.get(key)
- if val is not None:
- setattr(ext, key, val)
-
- # Medium-easy stuff: same syntax/semantics, different names.
- ext.runtime_library_dirs = build_info.get('rpath')
- if 'def_file' in build_info:
- log.warn("'def_file' element of build info dict "
- "no longer supported")
-
- # Non-trivial stuff: 'macros' split into 'define_macros'
- # and 'undef_macros'.
- macros = build_info.get('macros')
- if macros:
- ext.define_macros = []
- ext.undef_macros = []
- for macro in macros:
- if not (isinstance(macro, tuple) and len(macro) in (1, 2)):
- raise DistutilsSetupError, \
- ("'macros' element of build info dict "
- "must be 1- or 2-tuple")
- if len(macro) == 1:
- ext.undef_macros.append(macro[0])
- elif len(macro) == 2:
- ext.define_macros.append(macro)
-
- extensions[i] = ext
-
def get_source_files(self):
- self.check_extensions_list(self.extensions)
filenames = []
# Wouldn't it be neat if we knew the names of header files too...
@@ -485,11 +423,6 @@
return filenames
def get_outputs(self):
- # Sanity check the 'extensions' list -- can't assume this is being
- # done in the same run as a 'build_extensions()' call (in fact, we
- # can probably assume that it *isn't*!).
- self.check_extensions_list(self.extensions)
-
# And build the list of output (built) filenames. Note that this
# ignores the 'inplace' flag, and assumes everything goes in the
# "build" tree.
@@ -499,9 +432,6 @@
return outputs
def build_extensions(self):
- # First, sanity-check the 'extensions' list
- self.check_extensions_list(self.extensions)
-
for ext in self.extensions:
try:
self.build_extension(ext)
diff --git a/src/distutils2/command/build_py.py b/src/distutils2/command/build_py.py
--- a/src/distutils2/command/build_py.py
+++ b/src/distutils2/command/build_py.py
@@ -151,8 +151,13 @@
self.byte_compile(self.get_outputs(include_bytecode=0))
+ # -- Top-level worker functions ------------------------------------
+
def get_data_files(self):
- """Generate list of '(package,src_dir,build_dir,filenames)' tuples"""
+ """Generate list of '(package,src_dir,build_dir,filenames)' tuples.
+
+ Helper function for `finalize_options()`.
+ """
data = []
if not self.packages:
return data
@@ -176,7 +181,10 @@
return data
def find_data_files(self, package, src_dir):
- """Return filenames for package's data files in 'src_dir'"""
+ """Return filenames for package's data files in 'src_dir'.
+
+ Helper function for `get_data_files()`.
+ """
globs = (self.package_data.get('', [])
+ self.package_data.get(package, []))
files = []
@@ -188,7 +196,10 @@
return files
def build_package_data(self):
- """Copy data files into build directory"""
+ """Copy data files into build directory.
+
+ Helper function for `run()`.
+ """
for package, src_dir, build_dir, filenames in self.data_files:
for filename in filenames:
target = os.path.join(build_dir, filename)
@@ -198,6 +209,8 @@
if copied and srcfile in self.distribution.convert_2to3.doctests:
self._doctests_2to3.append(outf)
+ # XXX - this should be moved to the Distribution class as it is not
+ # only needed for build_py. It also has no dependencies on this class.
def get_package_dir(self, package):
"""Return the directory, relative to the top of the source
distribution, where package 'package' should be found
@@ -239,6 +252,8 @@
return ''
def check_package(self, package, package_dir):
+ """Helper function for `find_package_modules()` and `find_modules()'.
+ """
# Empty dir name means current directory, which we can probably
# assume exists. Also, os.path.exists and isdir don't know about
# my "empty string means current dir" convention, so we have to
diff --git a/src/distutils2/command/cmd.py b/src/distutils2/command/cmd.py
--- a/src/distutils2/command/cmd.py
+++ b/src/distutils2/command/cmd.py
@@ -373,8 +373,10 @@
if os.path.isdir(name) or name == '':
return
if dry_run:
+ head = ''
for part in name.split(os.sep):
- self.log(part)
+ log.info("created directory %s%s", head, part)
+ head += part + os.sep
return
os.makedirs(name, mode)
diff --git a/src/distutils2/command/register.py b/src/distutils2/command/register.py
--- a/src/distutils2/command/register.py
+++ b/src/distutils2/command/register.py
@@ -28,8 +28,6 @@
boolean_options = PyPIRCCommand.boolean_options + [
'verify', 'list-classifiers', 'strict']
- sub_commands = [('check', lambda self: True)]
-
def initialize_options(self):
PyPIRCCommand.initialize_options(self)
self.list_classifiers = 0
@@ -46,9 +44,8 @@
self.finalize_options()
self._set_config()
- # Run sub commands
- for cmd_name in self.get_sub_commands():
- self.run_command(cmd_name)
+ # Check the package metadata
+ self.run_command('check')
if self.dry_run:
self.verify_metadata()
diff --git a/src/distutils2/command/sdist.py b/src/distutils2/command/sdist.py
--- a/src/distutils2/command/sdist.py
+++ b/src/distutils2/command/sdist.py
@@ -45,12 +45,6 @@
description = "create a source distribution (tarball, zip file, etc.)"
- def checking_metadata(self):
- """Callable used for the check sub-command.
-
- Placed here so user_options can view it"""
- return self.metadata_check
-
user_options = [
('template=', 't',
"name of manifest template file [default: MANIFEST.in]"),
@@ -100,8 +94,6 @@
default_format = {'posix': 'gztar',
'nt': 'zip' }
- sub_commands = [('check', checking_metadata)]
-
def initialize_options(self):
# 'template' and 'manifest' are, respectively, the names of
# the manifest template and manifest file.
@@ -162,9 +154,9 @@
# manifest
self.filelist.clear()
- # Run sub commands
- for cmd_name in self.get_sub_commands():
- self.run_command(cmd_name)
+ # Check the package metadata
+ if self.metadata_check:
+ self.run_command('check')
# Do whatever it takes to get the list of files to process
# (process the manifest template, read an existing manifest,
diff --git a/src/distutils2/compiler/ccompiler.py b/src/distutils2/compiler/ccompiler.py
--- a/src/distutils2/compiler/ccompiler.py
+++ b/src/distutils2/compiler/ccompiler.py
@@ -940,8 +940,10 @@
if os.path.isdir(name) or name == '':
return
if self.dry_run:
+ head = ''
for part in name.split(os.sep):
- self.log(part)
+ log.info("created directory %s%s", head, part)
+ head += part + os.sep
return
os.makedirs(name, mode)
diff --git a/src/distutils2/tests/test_build_ext.py b/src/distutils2/tests/test_build_ext.py
--- a/src/distutils2/tests/test_build_ext.py
+++ b/src/distutils2/tests/test_build_ext.py
@@ -237,53 +237,6 @@
cmd.finalize_options()
self.assertEqual(cmd.swig_opts, ['1', '2'])
- def test_check_extensions_list(self):
- dist = Distribution()
- cmd = build_ext(dist)
- cmd.finalize_options()
-
- #'extensions' option must be a list of Extension instances
- self.assertRaises(DistutilsSetupError, cmd.check_extensions_list, 'foo')
-
- # each element of 'ext_modules' option must be an
- # Extension instance or 2-tuple
- exts = [('bar', 'foo', 'bar'), 'foo']
- self.assertRaises(DistutilsSetupError, cmd.check_extensions_list, exts)
-
- # first element of each tuple in 'ext_modules'
- # must be the extension name (a string) and match
- # a python dotted-separated name
- exts = [('foo-bar', '')]
- self.assertRaises(DistutilsSetupError, cmd.check_extensions_list, exts)
-
- # second element of each tuple in 'ext_modules'
- # must be a ary (build info)
- exts = [('foo.bar', '')]
- self.assertRaises(DistutilsSetupError, cmd.check_extensions_list, exts)
-
- # ok this one should pass
- exts = [('foo.bar', {'sources': [''], 'libraries': 'foo',
- 'some': 'bar'})]
- cmd.check_extensions_list(exts)
- ext = exts[0]
- self.assertTrue(isinstance(ext, Extension))
-
- # check_extensions_list adds in ext the values passed
- # when they are in ('include_dirs', 'library_dirs', 'libraries'
- # 'extra_objects', 'extra_compile_args', 'extra_link_args')
- self.assertEqual(ext.libraries, 'foo')
- self.assertTrue(not hasattr(ext, 'some'))
-
- # 'macros' element of build info dict must be 1- or 2-tuple
- exts = [('foo.bar', {'sources': [''], 'libraries': 'foo',
- 'some': 'bar', 'macros': [('1', '2', '3'), 'foo']})]
- self.assertRaises(DistutilsSetupError, cmd.check_extensions_list, exts)
-
- exts[0][1]['macros'] = [('1', '2'), ('3',)]
- cmd.check_extensions_list(exts)
- self.assertEqual(exts[0].undef_macros, ['3'])
- self.assertEqual(exts[0].define_macros, [('1', '2')])
-
def test_get_source_files(self):
modules = [Extension('foo', ['xxx'], optional=False)]
dist = Distribution({'name': 'xx', 'ext_modules': modules})
--
Repository URL: http://hg.python.org/distutils2
More information about the Python-checkins
mailing list