[Python-checkins] distutils2: `sdist.add_defaults()` now uses source files from all commands.
tarek.ziade
python-checkins at python.org
Sun Aug 8 11:50:48 CEST 2010
tarek.ziade pushed 32f887448cb0 to distutils2:
http://hg.python.org/distutils2/rev/32f887448cb0
changeset: 516:32f887448cb0
parent: 367:70b98f177413
user: Jeremy Kloth <jeremy.kloth at gmail.com>
date: Wed Jul 14 10:42:25 2010 -0600
summary: `sdist.add_defaults()` now uses source files from all commands.
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
@@ -372,7 +372,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
@@ -74,6 +74,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
@@ -244,47 +244,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
@@ -197,18 +197,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 = []
@@ -700,6 +700,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"
@@ -708,17 +726,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:
@@ -743,22 +751,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:
@@ -780,6 +774,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
@@ -818,7 +829,6 @@
raise DistutilsModuleError("invalid command '%s'" % command)
-
def get_command_obj(self, command, create=1):
"""Return the command object for 'command'. Normally this object
is cached on a previous call to 'get_command_obj()'; if no command
--
Repository URL: http://hg.python.org/distutils2
More information about the Python-checkins
mailing list