diff options
Diffstat (limited to 'setuptools/command')
-rwxr-xr-x | setuptools/command/easy_install.py | 4 | ||||
-rwxr-xr-x | setuptools/command/install_egg_info.py | 44 | ||||
-rw-r--r-- | setuptools/command/install_lib.py | 61 |
3 files changed, 83 insertions, 26 deletions
diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py index 828fb17f..c6b83be9 100755 --- a/setuptools/command/easy_install.py +++ b/setuptools/command/easy_install.py @@ -1288,6 +1288,8 @@ def get_exe_prefixes(exe_filename): break if len(parts)<>2 or not name.endswith('.pth'): continue + if name.endswith('-nspkg.pth'): + continue if parts[0] in ('PURELIB','PLATLIB'): pth = z.read(name).strip() prefixes[0] = ('PURELIB/%s/' % pth), '' @@ -1308,8 +1310,6 @@ def parse_requirement_arg(spec): ) - - class PthDistributions(Environment): """A .pth file with Distribution paths in it""" diff --git a/setuptools/command/install_egg_info.py b/setuptools/command/install_egg_info.py index 0b61a11d..a537b5e7 100755 --- a/setuptools/command/install_egg_info.py +++ b/setuptools/command/install_egg_info.py @@ -37,7 +37,7 @@ class install_egg_info(Command): self.execute(self.copytree, (), "Copying %s to %s" % (self.source, self.target) ) - + self.install_namespaces() def get_outputs(self): return self.outputs @@ -58,25 +58,25 @@ class install_egg_info(Command): unpack_archive(self.source, self.target, skimmer) - - - - - - - - - - - - - - - - - - - - - + def install_namespaces(self): + nsp = (self.distribution.namespace_packages or [])[:] + if not nsp: return + nsp.sort() # set up shorter names first + filename,ext = os.path.splitext(self.target) + filename += '-nspkg.pth'; self.outputs.append(filename) + log.info("Installing %s",filename) + if not self.dry_run: + f = open(filename,'wb') + for pkg in nsp: + pth = tuple(pkg.split('.')) + f.write( + "import sys,new; " + "m = sys.modules.setdefault(%(pkg)r,new.module(%(pkg)r)); " + "p = os.path.join(sys._getframe(1).f_locals['sitedir'], " + "*%(pth)r); " + "mp = m.__path__ = getattr(m,'__path__',[]); " + "(p not in mp) and mp.append(p)\n" + % locals() + ) + f.close() 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 + + + + + |