diff options
author | PJ Eby <distutils-sig@python.org> | 2005-11-18 04:37:31 +0000 |
---|---|---|
committer | PJ Eby <distutils-sig@python.org> | 2005-11-18 04:37:31 +0000 |
commit | 4cd66c4147bef3ee8096f7161d407fb37582f1c9 (patch) | |
tree | fa4e932d263aa02a1c9d80cc2cb80f33d5ce6f47 /setuptools/command/build_py.py | |
parent | f3694a0388e4e15d9cbdd84e4c8ca7817c87a52c (diff) | |
download | external_python_setuptools-4cd66c4147bef3ee8096f7161d407fb37582f1c9.tar.gz external_python_setuptools-4cd66c4147bef3ee8096f7161d407fb37582f1c9.tar.bz2 external_python_setuptools-4cd66c4147bef3ee8096f7161d407fb37582f1c9.zip |
Added the ``include_package_data`` keyword to ``setup()``, allowing you to
automatically include any package data listed in revision control or
``MANIFEST.in``. Now projects can manage their data files and source
manifests without having to maintain two ways to express the same file
list. Yay!
--HG--
branch : setuptools
extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041473
Diffstat (limited to 'setuptools/command/build_py.py')
-rw-r--r-- | setuptools/command/build_py.py | 90 |
1 files changed, 45 insertions, 45 deletions
diff --git a/setuptools/command/build_py.py b/setuptools/command/build_py.py index d13c46f2..fd09514f 100644 --- a/setuptools/command/build_py.py +++ b/setuptools/command/build_py.py @@ -3,7 +3,6 @@ from distutils.command.build_py import build_py as _build_py from distutils.util import convert_path from glob import glob - class build_py(_build_py): """Enhanced 'build_py' command that includes data files with packages @@ -17,7 +16,7 @@ class build_py(_build_py): def finalize_options(self): _build_py.finalize_options(self) self.package_data = self.distribution.package_data - self.data_files = self.get_data_files() + if 'data_files' in self.__dict__: del self.__dict__['data_files'] def run(self): """Build modules, packages, and copy data files to build directory""" @@ -35,12 +34,14 @@ class build_py(_build_py): # output files are. self.byte_compile(_build_py.get_outputs(self, include_bytecode=0)) + def __getattr__(self,attr): + if attr=='data_files': # lazily compute data files + self.data_files = files = self._get_data_files(); return files + return _build_py.__getattr__(self,attr) - - - - def get_data_files(self): + def _get_data_files(self): """Generate list of '(package,src_dir,build_dir,filenames)' tuples""" + self.analyze_manifest() data = [] for package in self.packages or (): # Locate package source directory @@ -63,7 +64,7 @@ class build_py(_build_py): """Return filenames for package's data files in 'src_dir'""" globs = (self.package_data.get('', []) + self.package_data.get(package, [])) - files = [] + files = self.manifest_files.get(package, [])[:] 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)))) @@ -79,45 +80,44 @@ class build_py(_build_py): self.copy_file(os.path.join(src_dir, filename), target) + def analyze_manifest(self): + self.manifest_files = mf = {} + if not self.distribution.include_package_data: + return - def get_outputs(self, include_bytecode=1): - """Return complete list of files copied to the build directory - - This includes both '.py' files and data files, as well as '.pyc' and - '.pyo' files if 'include_bytecode' is true. (This method is needed for - the 'install_lib' command to do its job properly, and to generate a - correct installation manifest.) - """ - return _build_py.get_outputs(self, include_bytecode) + [ - os.path.join(build_dir, filename) - for package, src_dir, build_dir,filenames in self.data_files - for filename in filenames - ] - - -if sys.version>="2.4": - # Python 2.4 already has the above code - build_py = _build_py - - - - - - - - - - - - - - - - - - - - + src_dirs = {} + for package in self.packages or (): + # Locate package source directory + src_dirs[self.get_package_dir(package)] = package + + self.run_command('egg_info') + ei_cmd = self.get_finalized_command('egg_info') + for path in ei_cmd.filelist.files: + if path.endswith('.py'): continue + d,f = os.path.split(path) + while d and d not in src_dirs: + d, df = os.path.split(d) + f = os.path.join(df, f) + if d in src_dirs: + mf.setdefault(src_dirs[d],[]).append(path) + + + def get_data_files(self): pass # kludge 2.4 for lazy computation + + if sys.version<"2.4": # Python 2.4 already has this code + def get_outputs(self, include_bytecode=1): + """Return complete list of files copied to the build directory + + This includes both '.py' files and data files, as well as '.pyc' + and '.pyo' files if 'include_bytecode' is true. (This method is + needed for the 'install_lib' command to do its job properly, and to + generate a correct installation manifest.) + """ + return _build_py.get_outputs(self, include_bytecode) + [ + os.path.join(build_dir, filename) + for package, src_dir, build_dir,filenames in self.data_files + for filename in filenames + ] |