diff options
| author | PJ Eby <distutils-sig@python.org> | 2006-03-17 16:57:23 +0000 | 
|---|---|---|
| committer | PJ Eby <distutils-sig@python.org> | 2006-03-17 16:57:23 +0000 | 
| commit | 92a61578a4b7d09ad6a6f9524163e67b62782e18 (patch) | |
| tree | 7d6a363dca53ef9f97f625100e9ce1006eb107b7 /setuptools/command/install_lib.py | |
| parent | 0b0d41cde67414ab19b030ea48b497e17134be19 (diff) | |
| download | python-setuptools-git-92a61578a4b7d09ad6a6f9524163e67b62782e18.tar.gz | |
Support namespace packages in conjunction with system packagers, by omitting
the installation of any ``__init__.py`` files for namespace packages, and
adding a special ``.pth`` file to create a working package in ``sys.modules``.
--HG--
branch : setuptools
extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4043119
Diffstat (limited to 'setuptools/command/install_lib.py')
| -rw-r--r-- | setuptools/command/install_lib.py | 61 | 
1 files changed, 59 insertions, 2 deletions
| diff --git a/setuptools/command/install_lib.py b/setuptools/command/install_lib.py index 75ff54b1..82afa142 100644 --- a/setuptools/command/install_lib.py +++ b/setuptools/command/install_lib.py @@ -1,4 +1,5 @@  from distutils.command.install_lib import install_lib as _install_lib +import os  class install_lib(_install_lib):      """Don't add compiled flags to filenames of non-Python files""" @@ -15,11 +16,67 @@ class install_lib(_install_lib):          return bytecode_files -      def run(self):          self.build()          outfiles = self.install()          if outfiles is not None:              # always compile, in case we have any extension stubs to deal with -            self.byte_compile(outfiles)  +            self.byte_compile(outfiles) + +    def get_exclusions(self): +        exclude = {} +        nsp = self.distribution.namespace_packages + +        if (nsp and self.get_finalized_command('install') +               .single_version_externally_managed +        ): +            for pkg in nsp: +                parts = pkg.split('.') +                while parts: +                    pkgdir = os.path.join(self.install_dir, *parts) +                    for f in '__init__.py', '__init__.pyc', '__init__.pyo': +                        exclude[os.path.join(pkgdir,f)] = 1 +                    parts.pop() +        return exclude + +    def copy_tree( +        self, infile, outfile, +        preserve_mode=1, preserve_times=1, preserve_symlinks=0, level=1 +    ): +        assert preserve_mode and preserve_times and not preserve_symlinks +        exclude = self.get_exclusions() + +        if not exclude: +            return _install_lib.copy_tree(self, infile, outfile) + +        # Exclude namespace package __init__.py* files from the output + +        from setuptools.archive_util import unpack_directory +        from distutils import log + +        outfiles = [] + +        def pf(src, dst): +            if dst in exclude: +                log.warn("Skipping installation of %s (namespace package)",dst) +                return False + +            log.info("copying %s -> %s", src, os.path.dirname(dst)) +            outfiles.append(dst) +            return dst + +        unpack_directory(infile, outfile, pf) +        return outfiles + +    def get_outputs(self): +        outputs = _install_lib.get_outputs(self) +        exclude = self.get_exclusions() +        if exclude: +            return [f for f in outputs if f not in exclude] +        return outputs + + + + + | 
