From d989230127c6e16c505096f6150db977e61478b3 Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Thu, 15 Dec 2005 02:45:03 +0000 Subject: Added the ``exclude_package_data`` keyword to ``setup()``, allowing you to trim back files included via the ``package_data`` and ``include_package_data`` options. --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041693 --- setuptools/command/build_py.py | 47 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) (limited to 'setuptools/command/build_py.py') diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index 35b9c57e..4d779f57 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -1,4 +1,4 @@ -import os.path, sys +import os.path, sys, fnmatch from distutils.command.build_py import build_py as _build_py from distutils.util import convert_path from glob import glob @@ -12,10 +12,10 @@ class build_py(_build_py): Also, this version of the 'build_py' command allows you to specify both 'py_modules' and 'packages' in the same setup operation. """ - def finalize_options(self): _build_py.finalize_options(self) self.package_data = self.distribution.package_data + self.exclude_package_data = self.distribution.exclude_package_data or {} if 'data_files' in self.__dict__: del self.__dict__['data_files'] def run(self): @@ -68,7 +68,7 @@ class build_py(_build_py): for pattern in globs: # Each pattern has to be converted to a platform-specific path files.extend(glob(os.path.join(src_dir, convert_path(pattern)))) - return files + return self.exclude_data_files(package, src_dir, files) def build_package_data(self): """Copy data files into build directory""" @@ -155,6 +155,47 @@ class build_py(_build_py): def initialize_options(self): self.packages_checked={} _build_py.initialize_options(self) + + + + + + + + def exclude_data_files(self, package, src_dir, files): + """Filter filenames for package's data files in 'src_dir'""" + globs = (self.exclude_package_data.get('', []) + + self.exclude_package_data.get(package, [])) + bad = [] + for pattern in globs: + bad.extend( + fnmatch.filter( + files, os.path.join(src_dir, convert_path(pattern)) + ) + ) + bad = dict.fromkeys(bad) + return [f for f in files if f not in bad] + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.1