[Python-checkins] distutils2: Merge from Jeremy
tarek.ziade
python-checkins at python.org
Sun Aug 8 11:50:48 CEST 2010
tarek.ziade pushed f96e8b6c97ba to distutils2:
http://hg.python.org/distutils2/rev/f96e8b6c97ba
changeset: 520:f96e8b6c97ba
parent: 515:7c9f24dc9fbc
parent: 519:8dc26ef8235d
user: ?ric Araujo <merwok at netwok.org>
date: Sun Aug 08 02:33:52 2010 +0200
summary: Merge from Jeremy
files: src/distutils2/command/build_py.py, src/distutils2/command/install_data.py, src/distutils2/command/sdist.py, src/distutils2/dist.py
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
@@ -371,7 +371,13 @@
return modules
def get_source_files(self):
- return [module[-1] for module in self.find_all_modules()]
+ sources = [module[-1] for module in self.find_all_modules()]
+ sources += [
+ os.path.join(src_dir, filename)
+ for package, src_dir, build_dir, filenames in self.data_files
+ for filename in filenames
+ ]
+ return sources
def get_module_outfile(self, build_dir, package, module):
outfile_path = [build_dir] + list(package) + [module + ".py"]
diff --git a/src/distutils2/command/install_data.py b/src/distutils2/command/install_data.py
--- a/src/distutils2/command/install_data.py
+++ b/src/distutils2/command/install_data.py
@@ -72,6 +72,21 @@
(out, _) = self.copy_file(data, dir)
self.outfiles.append(out)
+ def get_source_files(self):
+ sources = []
+ for item in self.data_files:
+ if isinstance(item, str): # plain file
+ item = convert_path(item)
+ if os.path.isfile(item):
+ sources.append(item)
+ else: # a (dirname, filenames) tuple
+ dirname, filenames = item
+ for f in filenames:
+ f = convert_path(f)
+ if os.path.isfile(f):
+ sources.append(f)
+ return sources
+
def get_inputs(self):
return self.data_files or []
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
@@ -170,14 +170,6 @@
# or zipfile, or whatever.
self.make_distribution()
- def check_metadata(self):
- """Deprecated API."""
- warn("distutils.command.sdist.check_metadata is deprecated, \
- use the check command instead", PendingDeprecationWarning)
- check = self.distribution.get_command_obj('check')
- check.ensure_finalized()
- check.run()
-
def get_file_list(self):
"""Figure out the list of files to include in the source
distribution, and put it in 'self.filelist'. This might involve
@@ -243,47 +235,10 @@
if files:
self.filelist.extend(files)
- # build_py is used to get:
- # - python modules
- # - files defined in package_data
- build_py = self.get_finalized_command('build_py')
-
- # getting python files
- if self.distribution.has_pure_modules():
- self.filelist.extend(build_py.get_source_files())
-
- # getting package_data files
- # (computed in build_py.data_files by build_py.finalize_options)
- for pkg, src_dir, build_dir, filenames in build_py.data_files:
- for filename in filenames:
- self.filelist.append(os.path.join(src_dir, filename))
-
- # getting distribution.data_files
- if self.distribution.has_data_files():
- for item in self.distribution.data_files:
- if isinstance(item, str): # plain file
- item = convert_path(item)
- if os.path.isfile(item):
- self.filelist.append(item)
- else: # a (dirname, filenames) tuple
- dirname, filenames = item
- for f in filenames:
- f = convert_path(f)
- if os.path.isfile(f):
- self.filelist.append(f)
-
- if self.distribution.has_ext_modules():
- build_ext = self.get_finalized_command('build_ext')
- self.filelist.extend(build_ext.get_source_files())
-
- if self.distribution.has_c_libraries():
- build_clib = self.get_finalized_command('build_clib')
- self.filelist.extend(build_clib.get_source_files())
-
- if self.distribution.has_scripts():
- build_scripts = self.get_finalized_command('build_scripts')
- self.filelist.extend(build_scripts.get_source_files())
-
+ for cmd_name in self.distribution.get_command_names():
+ cmd_obj = self.get_finalized_command(cmd_name)
+ self.filelist.extend(cmd_obj.get_source_files())
+
def prune_file_list(self):
"""Prune off branches that might slip into the file list as created
diff --git a/src/distutils2/dist.py b/src/distutils2/dist.py
--- a/src/distutils2/dist.py
+++ b/src/distutils2/dist.py
@@ -187,18 +187,18 @@
# These options are really the business of various commands, rather
# than of the Distribution itself. We provide aliases for them in
# Distribution as a convenience to the developer.
- self.packages = None
+ self.packages = []
self.package_data = {}
self.package_dir = None
- self.py_modules = None
- self.libraries = None
- self.headers = None
- self.ext_modules = None
+ self.py_modules = []
+ self.libraries = []
+ self.headers = []
+ self.ext_modules = []
self.ext_package = None
- self.include_dirs = None
+ self.include_dirs = []
self.extra_path = None
- self.scripts = None
- self.data_files = None
+ self.scripts = []
+ self.data_files = []
self.password = ''
self.use_2to3 = False
self.convert_2to3_doctests = []
@@ -697,6 +697,24 @@
print(" %-*s %s" % (max_length, cmd, description))
+ def _get_command_groups(self):
+ """Helper function to retrieve all the command class names divided
+ into "standard commands" (listed in distutils2.command.__all__)
+ and "extra commands" (mentioned in self.cmdclass, but not a standard
+ command).
+ """
+ import distutils2.command
+ std_commands = distutils2.command.__all__
+ is_std = {}
+ for cmd in std_commands:
+ is_std[cmd] = 1
+
+ extra_commands = []
+ for cmd in self.cmdclass:
+ if not is_std.get(cmd):
+ extra_commands.append(cmd)
+ return std_commands, extra_commands
+
def print_commands(self):
"""Print out a help message listing all available commands with a
description of each. The list is divided into "standard commands"
@@ -705,17 +723,7 @@
descriptions come from the command class attribute
'description'.
"""
- import distutils2.command
- std_commands = distutils2.command.__all__
- is_std = {}
- for cmd in std_commands:
- is_std[cmd] = 1
-
- extra_commands = []
- for cmd in self.cmdclass.keys():
- if not is_std.get(cmd):
- extra_commands.append(cmd)
-
+ std_commands, extra_commands = self._get_command_groups()
max_length = 0
for cmd in (std_commands + extra_commands):
if len(cmd) > max_length:
@@ -740,22 +748,8 @@
# Currently this is only used on Mac OS, for the Mac-only GUI
# Distutils interface (by Jack Jansen)
- import distutils2.command
- std_commands = distutils2.command.__all__
- is_std = {}
- for cmd in std_commands:
- is_std[cmd] = 1
-
- extra_commands = []
- for cmd in self.cmdclass.keys():
- if not is_std.get(cmd):
- extra_commands.append(cmd)
-
rv = []
- for cmd in (std_commands + extra_commands):
- cls = self.cmdclass.get(cmd)
- if not cls:
- cls = self.get_command_class(cmd)
+ for cls in self.get_command_classes():
try:
description = cls.description
except AttributeError:
@@ -777,6 +771,23 @@
self.command_packages = pkgs
return pkgs
+ def get_command_names(self):
+ """Return a list of command names."""
+ return [getattr(cls, 'command_name', cls.__name__)
+ for cls in self.get_command_classes()]
+
+ def get_command_classes(self):
+ """Return a list of all command classes."""
+ std_commands, extra_commands = self._get_command_groups()
+ classes = []
+ for cmd in (std_commands + extra_commands):
+ try:
+ cls = self.cmdclass[cmd]
+ except KeyError:
+ cls = self.get_command_class(cmd)
+ classes.append(cls)
+ return classes
+
def get_command_class(self, command):
"""Return the class that implements the Distutils command named by
'command'. First we check the 'cmdclass' dictionary; if the
--
Repository URL: http://hg.python.org/distutils2
More information about the Python-checkins
mailing list