From 8423e1ed14ac1691c2863c6e8cac9230cf558d7b Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Fri, 19 Mar 2004 20:53:14 +0000 Subject: Initial checkin of setuptools 0.0.1. --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4040869 --- setuptools/command/install_lib.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 setuptools/command/install_lib.py (limited to 'setuptools/command/install_lib.py') diff --git a/setuptools/command/install_lib.py b/setuptools/command/install_lib.py new file mode 100644 index 00000000..ec406f7e --- /dev/null +++ b/setuptools/command/install_lib.py @@ -0,0 +1,17 @@ +from distutils.command.install_lib import install_lib as _install_lib + +class install_lib(_install_lib): + """Don't add compiled flags to filenames of non-Python files""" + + def _bytecode_filenames (self, py_filenames): + bytecode_files = [] + for py_file in py_filenames: + if not py_file.endswith('.py'): + continue + if self.compile: + bytecode_files.append(py_file + "c") + if self.optimize > 0: + bytecode_files.append(py_file + "o") + + return bytecode_files + -- cgit v1.2.1 From ba79fc03ef4aa6399aa7207bebcd65f35c3b93ad Mon Sep 17 00:00:00 2001 From: Fred Drake Date: Mon, 5 Apr 2004 19:59:11 +0000 Subject: remove trailing blank line --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4040894 --- setuptools/command/install_lib.py | 1 - 1 file changed, 1 deletion(-) (limited to 'setuptools/command/install_lib.py') diff --git a/setuptools/command/install_lib.py b/setuptools/command/install_lib.py index ec406f7e..63e2468c 100644 --- a/setuptools/command/install_lib.py +++ b/setuptools/command/install_lib.py @@ -14,4 +14,3 @@ class install_lib(_install_lib): bytecode_files.append(py_file + "o") return bytecode_files - -- cgit v1.2.1 From cca060c2d83301f1aae9fc4be26612a75a1c38c3 Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Fri, 13 Jan 2006 23:52:42 +0000 Subject: Ensure installed stubs get compiled, even if there are no "pure" modules present. Also, don't bother compiling the stub prior to installation. --HG-- branch : setuptools extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4042037 --- setuptools/command/install_lib.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'setuptools/command/install_lib.py') diff --git a/setuptools/command/install_lib.py b/setuptools/command/install_lib.py index 63e2468c..75ff54b1 100644 --- a/setuptools/command/install_lib.py +++ b/setuptools/command/install_lib.py @@ -14,3 +14,12 @@ class install_lib(_install_lib): bytecode_files.append(py_file + "o") 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) + -- cgit v1.2.1 From 92a61578a4b7d09ad6a6f9524163e67b62782e18 Mon Sep 17 00:00:00 2001 From: PJ Eby Date: Fri, 17 Mar 2006 16:57:23 +0000 Subject: 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 --- setuptools/command/install_lib.py | 61 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 2 deletions(-) (limited to 'setuptools/command/install_lib.py') 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 + + + + + -- cgit v1.2.1 From 646d7585da63b3fe5b4b2d5bf057b3795ac21241 Mon Sep 17 00:00:00 2001 From: William Grzybowski Date: Mon, 16 Dec 2013 22:44:35 -0200 Subject: Do not override _bytecode_filenames The overridden version cannot handle Python 3.x while distutils verion can handle it just fine. --HG-- extra : rebase_source : 86fa56285849e97780e91eff405881bfb72184d5 --- setuptools/command/install_lib.py | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'setuptools/command/install_lib.py') diff --git a/setuptools/command/install_lib.py b/setuptools/command/install_lib.py index 82afa142..c508cd33 100644 --- a/setuptools/command/install_lib.py +++ b/setuptools/command/install_lib.py @@ -4,18 +4,6 @@ import os class install_lib(_install_lib): """Don't add compiled flags to filenames of non-Python files""" - def _bytecode_filenames (self, py_filenames): - bytecode_files = [] - for py_file in py_filenames: - if not py_file.endswith('.py'): - continue - if self.compile: - bytecode_files.append(py_file + "c") - if self.optimize > 0: - bytecode_files.append(py_file + "o") - - return bytecode_files - def run(self): self.build() outfiles = self.install() -- cgit v1.2.1 From 4ca7386a58ba92c5c89d0872933384f7d1fea115 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Thu, 13 Mar 2014 22:48:41 -0400 Subject: Reindent and remove excess whitespace --- setuptools/command/install_lib.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'setuptools/command/install_lib.py') diff --git a/setuptools/command/install_lib.py b/setuptools/command/install_lib.py index c508cd33..63dc11fe 100644 --- a/setuptools/command/install_lib.py +++ b/setuptools/command/install_lib.py @@ -14,10 +14,9 @@ class install_lib(_install_lib): def get_exclusions(self): exclude = {} nsp = self.distribution.namespace_packages - - if (nsp and self.get_finalized_command('install') - .single_version_externally_managed - ): + svem = (nsp and self.get_finalized_command('install') + .single_version_externally_managed) + if svem: for pkg in nsp: parts = pkg.split('.') while parts: @@ -62,9 +61,3 @@ class install_lib(_install_lib): if exclude: return [f for f in outputs if f not in exclude] return outputs - - - - - - -- cgit v1.2.1 From 573c2c86d4d4f506a87a1fc16060f32c1386ad38 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 30 Apr 2014 17:38:29 -0400 Subject: Correct indentation and clarify meaning by using namespacing --HG-- extra : amend_source : 20ab7547c8478eb084767fe701e627bdd462ba16 --- setuptools/command/install_lib.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'setuptools/command/install_lib.py') diff --git a/setuptools/command/install_lib.py b/setuptools/command/install_lib.py index 63dc11fe..747fbabb 100644 --- a/setuptools/command/install_lib.py +++ b/setuptools/command/install_lib.py @@ -1,7 +1,7 @@ -from distutils.command.install_lib import install_lib as _install_lib +import distutils.command.install_lib as orig import os -class install_lib(_install_lib): +class install_lib(orig.install_lib): """Don't add compiled flags to filenames of non-Python files""" def run(self): @@ -34,7 +34,7 @@ class install_lib(_install_lib): exclude = self.get_exclusions() if not exclude: - return _install_lib.copy_tree(self, infile, outfile) + return orig.install_lib.copy_tree(self, infile, outfile) # Exclude namespace package __init__.py* files from the output @@ -56,7 +56,7 @@ class install_lib(_install_lib): return outfiles def get_outputs(self): - outputs = _install_lib.get_outputs(self) + outputs = orig.install_lib.get_outputs(self) exclude = self.get_exclusions() if exclude: return [f for f in outputs if f not in exclude] -- cgit v1.2.1 From 8e3f9d3253d1d0fb820dad4249d5110d017595c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Gr=C3=B6nholm?= Date: Wed, 18 Jun 2014 20:31:05 +0300 Subject: Fixed PEP 8 compliancy of the setuptools.command package --- setuptools/command/install_lib.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'setuptools/command/install_lib.py') diff --git a/setuptools/command/install_lib.py b/setuptools/command/install_lib.py index 747fbabb..d7e117f0 100644 --- a/setuptools/command/install_lib.py +++ b/setuptools/command/install_lib.py @@ -1,6 +1,7 @@ import distutils.command.install_lib as orig import os + class install_lib(orig.install_lib): """Don't add compiled flags to filenames of non-Python files""" @@ -15,20 +16,20 @@ class install_lib(orig.install_lib): exclude = {} nsp = self.distribution.namespace_packages svem = (nsp and self.get_finalized_command('install') - .single_version_externally_managed) + .single_version_externally_managed) if svem: 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 + 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 + 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() @@ -45,7 +46,8 @@ class install_lib(orig.install_lib): def pf(src, dst): if dst in exclude: - log.warn("Skipping installation of %s (namespace package)",dst) + log.warn("Skipping installation of %s (namespace package)", + dst) return False log.info("copying %s -> %s", src, os.path.dirname(dst)) -- cgit v1.2.1 From e66c4d9c3aefaf98a7d8d9b19ce5948fe7840c49 Mon Sep 17 00:00:00 2001 From: Melvyn Sopacua Date: Sat, 5 Jul 2014 17:43:39 +0200 Subject: Fix exclude list on python 3.2+ imp.get_tag() is only available on 3.2+. Since 2 Date: Sat, 5 Jul 2014 18:41:12 +0200 Subject: Commit the fix we did when testing python3 I shall `hg status` before submitting PRs. I shall `hg status` before submitting PRs. I shall `hg status` before submitting PRs. --- setuptools/command/install_lib.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'setuptools/command/install_lib.py') diff --git a/setuptools/command/install_lib.py b/setuptools/command/install_lib.py index cf5375f6..7692e0f3 100644 --- a/setuptools/command/install_lib.py +++ b/setuptools/command/install_lib.py @@ -18,7 +18,7 @@ class install_lib(orig.install_lib): .single_version_externally_managed) exclude_names = ['__init__.py', '__init__.pyc', '__init__.pyo'] if hasattr(imp, 'get_tag') : - exclude_names.extend( + exclude_names.extend(( os.path.join( '__pycache__', '__init__.' + imp.get_tag() + '.pyc' @@ -27,7 +27,7 @@ class install_lib(orig.install_lib): '__pycache__', '__init__.' + imp.get_tag() + '.pyo' ), - ) + )) if svem: for pkg in nsp: parts = pkg.split('.') -- cgit v1.2.1 From 63ddca7cd1011b8d4b1348315c02fe9fd6a404e2 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 26 Sep 2014 09:54:15 -0400 Subject: Normalize syntax --- setuptools/command/install_lib.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'setuptools/command/install_lib.py') diff --git a/setuptools/command/install_lib.py b/setuptools/command/install_lib.py index 7692e0f3..c0c271a4 100644 --- a/setuptools/command/install_lib.py +++ b/setuptools/command/install_lib.py @@ -17,7 +17,7 @@ class install_lib(orig.install_lib): svem = (nsp and self.get_finalized_command('install') .single_version_externally_managed) exclude_names = ['__init__.py', '__init__.pyc', '__init__.pyo'] - if hasattr(imp, 'get_tag') : + if hasattr(imp, 'get_tag'): exclude_names.extend(( os.path.join( '__pycache__', @@ -33,7 +33,7 @@ class install_lib(orig.install_lib): parts = pkg.split('.') while parts: pkgdir = os.path.join(self.install_dir, *parts) - for f in exclude_names : + for f in exclude_names: exclude[os.path.join(pkgdir, f)] = 1 parts.pop() return exclude -- cgit v1.2.1 From a7dbe706890eab7ba330c51ea59349c28080dfde Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 26 Sep 2014 10:02:01 -0400 Subject: Extract method for generating exclude names --- setuptools/command/install_lib.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'setuptools/command/install_lib.py') diff --git a/setuptools/command/install_lib.py b/setuptools/command/install_lib.py index c0c271a4..259f0899 100644 --- a/setuptools/command/install_lib.py +++ b/setuptools/command/install_lib.py @@ -16,6 +16,22 @@ class install_lib(orig.install_lib): nsp = self.distribution.namespace_packages svem = (nsp and self.get_finalized_command('install') .single_version_externally_managed) + if svem: + for pkg in nsp: + parts = pkg.split('.') + while parts: + pkgdir = os.path.join(self.install_dir, *parts) + for f in self._gen_exclude_names(): + exclude[os.path.join(pkgdir, f)] = 1 + parts.pop() + return exclude + + @staticmethod + def _gen_exclude_names(): + """ + Generate the list of file paths to be excluded for namespace + packages (bytecode cache files). + """ exclude_names = ['__init__.py', '__init__.pyc', '__init__.pyo'] if hasattr(imp, 'get_tag'): exclude_names.extend(( @@ -28,15 +44,7 @@ class install_lib(orig.install_lib): '__init__.' + imp.get_tag() + '.pyo' ), )) - if svem: - for pkg in nsp: - parts = pkg.split('.') - while parts: - pkgdir = os.path.join(self.install_dir, *parts) - for f in exclude_names: - exclude[os.path.join(pkgdir, f)] = 1 - parts.pop() - return exclude + return exclude_names def copy_tree( self, infile, outfile, -- cgit v1.2.1 From 4e5bbb8e5175b35f8cbaace630bd0dd3091d6946 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 26 Sep 2014 10:05:18 -0400 Subject: Generate the filenames more directly. --- setuptools/command/install_lib.py | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) (limited to 'setuptools/command/install_lib.py') diff --git a/setuptools/command/install_lib.py b/setuptools/command/install_lib.py index 259f0899..3f39d945 100644 --- a/setuptools/command/install_lib.py +++ b/setuptools/command/install_lib.py @@ -29,22 +29,18 @@ class install_lib(orig.install_lib): @staticmethod def _gen_exclude_names(): """ - Generate the list of file paths to be excluded for namespace - packages (bytecode cache files). + Generate file paths to be excluded for namespace packages (bytecode + cache files). """ - exclude_names = ['__init__.py', '__init__.pyc', '__init__.pyo'] - if hasattr(imp, 'get_tag'): - exclude_names.extend(( - os.path.join( - '__pycache__', - '__init__.' + imp.get_tag() + '.pyc' - ), - os.path.join( - '__pycache__', - '__init__.' + imp.get_tag() + '.pyo' - ), - )) - return exclude_names + yield '__init__.py' + yield '__init__.pyc' + yield '__init__.pyo' + + if not hasattr(imp, 'get_tag'): + return + + yield os.path.join('__pycache__', '__init__.' + imp.get_tag() + '.pyc') + yield os.path.join('__pycache__', '__init__.' + imp.get_tag() + '.pyo') def copy_tree( self, infile, outfile, -- cgit v1.2.1 From f6f409ac7dc06be2524211a717182cd96b21e13f Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 26 Sep 2014 10:06:35 -0400 Subject: Extract calculation of base path --- setuptools/command/install_lib.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'setuptools/command/install_lib.py') diff --git a/setuptools/command/install_lib.py b/setuptools/command/install_lib.py index 3f39d945..d1c91b7b 100644 --- a/setuptools/command/install_lib.py +++ b/setuptools/command/install_lib.py @@ -39,8 +39,9 @@ class install_lib(orig.install_lib): if not hasattr(imp, 'get_tag'): return - yield os.path.join('__pycache__', '__init__.' + imp.get_tag() + '.pyc') - yield os.path.join('__pycache__', '__init__.' + imp.get_tag() + '.pyo') + base = os.path.join('__pycache__', '__init__.' + imp.get_tag()) + yield base + '.pyc' + yield base + '.pyo' def copy_tree( self, infile, outfile, -- cgit v1.2.1 From 23f5f548a9dfffe5c04f40eee461d2270ecf5f53 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 26 Sep 2014 10:07:07 -0400 Subject: Add comment --- setuptools/command/install_lib.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'setuptools/command/install_lib.py') diff --git a/setuptools/command/install_lib.py b/setuptools/command/install_lib.py index d1c91b7b..a1cbd2aa 100644 --- a/setuptools/command/install_lib.py +++ b/setuptools/command/install_lib.py @@ -32,7 +32,9 @@ class install_lib(orig.install_lib): Generate file paths to be excluded for namespace packages (bytecode cache files). """ + # always exclude the package module itself yield '__init__.py' + yield '__init__.pyc' yield '__init__.pyo' -- cgit v1.2.1 From 03fe70a1793ea5dae7685323f1146eb12c2a0e0e Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 26 Sep 2014 10:08:48 -0400 Subject: Construct exclusions as a set --- setuptools/command/install_lib.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'setuptools/command/install_lib.py') diff --git a/setuptools/command/install_lib.py b/setuptools/command/install_lib.py index a1cbd2aa..f4b295cc 100644 --- a/setuptools/command/install_lib.py +++ b/setuptools/command/install_lib.py @@ -12,7 +12,7 @@ class install_lib(orig.install_lib): self.byte_compile(outfiles) def get_exclusions(self): - exclude = {} + exclude = set() nsp = self.distribution.namespace_packages svem = (nsp and self.get_finalized_command('install') .single_version_externally_managed) @@ -22,9 +22,9 @@ class install_lib(orig.install_lib): while parts: pkgdir = os.path.join(self.install_dir, *parts) for f in self._gen_exclude_names(): - exclude[os.path.join(pkgdir, f)] = 1 + exclude.add(os.path.join(pkgdir, f)) parts.pop() - return exclude + return dict.fromkeys(exclude, 1) @staticmethod def _gen_exclude_names(): -- cgit v1.2.1 From e8914480487426305fece22422fdb725f88add7f Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 26 Sep 2014 10:19:36 -0400 Subject: Add docstring for get_exclusions. Just return the set as it is a sized container. --- setuptools/command/install_lib.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'setuptools/command/install_lib.py') diff --git a/setuptools/command/install_lib.py b/setuptools/command/install_lib.py index f4b295cc..91d2b25d 100644 --- a/setuptools/command/install_lib.py +++ b/setuptools/command/install_lib.py @@ -12,6 +12,10 @@ class install_lib(orig.install_lib): self.byte_compile(outfiles) def get_exclusions(self): + """ + Return a collections.Sized collections.Container of paths to be + excluded for single_version_externally_managed installations. + """ exclude = set() nsp = self.distribution.namespace_packages svem = (nsp and self.get_finalized_command('install') @@ -24,7 +28,7 @@ class install_lib(orig.install_lib): for f in self._gen_exclude_names(): exclude.add(os.path.join(pkgdir, f)) parts.pop() - return dict.fromkeys(exclude, 1) + return exclude @staticmethod def _gen_exclude_names(): -- cgit v1.2.1 From bd62121950280590c9388db065df389cf2d8280d Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 26 Sep 2014 10:29:38 -0400 Subject: Extract method for calculating namespace packages for single_version_externally_managed --- setuptools/command/install_lib.py | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) (limited to 'setuptools/command/install_lib.py') diff --git a/setuptools/command/install_lib.py b/setuptools/command/install_lib.py index 91d2b25d..bf587a04 100644 --- a/setuptools/command/install_lib.py +++ b/setuptools/command/install_lib.py @@ -17,19 +17,31 @@ class install_lib(orig.install_lib): excluded for single_version_externally_managed installations. """ exclude = set() - nsp = self.distribution.namespace_packages - svem = (nsp and self.get_finalized_command('install') - .single_version_externally_managed) - if svem: - for pkg in nsp: - parts = pkg.split('.') - while parts: - pkgdir = os.path.join(self.install_dir, *parts) - for f in self._gen_exclude_names(): - exclude.add(os.path.join(pkgdir, f)) - parts.pop() + for pkg in self._get_SVEM_NSPs(): + parts = pkg.split('.') + while parts: + pkgdir = os.path.join(self.install_dir, *parts) + for f in self._gen_exclude_names(): + exclude.add(os.path.join(pkgdir, f)) + parts.pop() return exclude + def _get_SVEM_NSPs(self): + """ + Get namespace packages (list) but only for + single_version_externally_managed installations and empty otherwise. + """ + # TODO: is it necessary to short-circuit here? i.e. what's the cost + # if get_finalized_command is called even when namespace_packages is + # False? + if not self.distribution.namespace_packages: + return [] + + install_cmd = self.get_finalized_command('install') + svem = install_cmd.single_version_externally_managed + + return self.distribution.namespace_packages if svem else [] + @staticmethod def _gen_exclude_names(): """ -- cgit v1.2.1 From 82c2101634a423ae9ccf003612b89fbd230f8303 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 26 Sep 2014 10:39:53 -0400 Subject: Extract method for computing parent packages of a package --- setuptools/command/install_lib.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'setuptools/command/install_lib.py') diff --git a/setuptools/command/install_lib.py b/setuptools/command/install_lib.py index bf587a04..88b35972 100644 --- a/setuptools/command/install_lib.py +++ b/setuptools/command/install_lib.py @@ -17,15 +17,24 @@ class install_lib(orig.install_lib): excluded for single_version_externally_managed installations. """ exclude = set() - for pkg in self._get_SVEM_NSPs(): - parts = pkg.split('.') - while parts: + for ns_pkg in self._get_SVEM_NSPs(): + for pkg in self._all_packages(ns_pkg): + parts = pkg.split('.') pkgdir = os.path.join(self.install_dir, *parts) for f in self._gen_exclude_names(): exclude.add(os.path.join(pkgdir, f)) - parts.pop() return exclude + @staticmethod + def _all_packages(pkg_name): + """ + >>> list(install_lib._all_packages('foo.bar.baz')) + ['foo.bar.baz', 'foo.bar', 'foo'] + """ + while pkg_name: + yield pkg_name + pkg_name, sep, child = pkg_name.partition('.') + def _get_SVEM_NSPs(self): """ Get namespace packages (list) but only for -- cgit v1.2.1 From 10e504abc7f0a0c45157bf4d6cbbd63dea6a67dd Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 26 Sep 2014 10:41:49 -0400 Subject: Extract path calculation for paths --- setuptools/command/install_lib.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'setuptools/command/install_lib.py') diff --git a/setuptools/command/install_lib.py b/setuptools/command/install_lib.py index 88b35972..92490b6e 100644 --- a/setuptools/command/install_lib.py +++ b/setuptools/command/install_lib.py @@ -17,12 +17,11 @@ class install_lib(orig.install_lib): excluded for single_version_externally_managed installations. """ exclude = set() + pkg_path = lambda pkg: os.path.join(self.install_dir, *pkg.split('.')) for ns_pkg in self._get_SVEM_NSPs(): for pkg in self._all_packages(ns_pkg): - parts = pkg.split('.') - pkgdir = os.path.join(self.install_dir, *parts) for f in self._gen_exclude_names(): - exclude.add(os.path.join(pkgdir, f)) + exclude.add(os.path.join(pkg_path(pkg), f)) return exclude @staticmethod -- cgit v1.2.1 From b43f75980dd674153cafec047709092438d54b5c Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 26 Sep 2014 10:43:35 -0400 Subject: Rewrite package traversal as a generator expression --- setuptools/command/install_lib.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'setuptools/command/install_lib.py') diff --git a/setuptools/command/install_lib.py b/setuptools/command/install_lib.py index 92490b6e..7f157a0f 100644 --- a/setuptools/command/install_lib.py +++ b/setuptools/command/install_lib.py @@ -18,8 +18,12 @@ class install_lib(orig.install_lib): """ exclude = set() pkg_path = lambda pkg: os.path.join(self.install_dir, *pkg.split('.')) - for ns_pkg in self._get_SVEM_NSPs(): - for pkg in self._all_packages(ns_pkg): + all_packages = ( + pkg + for ns_pkg in self._get_SVEM_NSPs() + for pkg in self._all_packages(ns_pkg) + ) + for pkg in all_packages: for f in self._gen_exclude_names(): exclude.add(os.path.join(pkg_path(pkg), f)) return exclude -- cgit v1.2.1 From c6340e42c8a06a35048659d7178efb329cda3249 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 26 Sep 2014 10:43:43 -0400 Subject: Reindent --- setuptools/command/install_lib.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'setuptools/command/install_lib.py') diff --git a/setuptools/command/install_lib.py b/setuptools/command/install_lib.py index 7f157a0f..371a9e72 100644 --- a/setuptools/command/install_lib.py +++ b/setuptools/command/install_lib.py @@ -24,8 +24,8 @@ class install_lib(orig.install_lib): for pkg in self._all_packages(ns_pkg) ) for pkg in all_packages: - for f in self._gen_exclude_names(): - exclude.add(os.path.join(pkg_path(pkg), f)) + for f in self._gen_exclude_names(): + exclude.add(os.path.join(pkg_path(pkg), f)) return exclude @staticmethod -- cgit v1.2.1 From b908527864443899b89cf568ac9397aef7ad16c9 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 26 Sep 2014 10:46:14 -0400 Subject: Use itertools.product for a cross-product of two iterables --- setuptools/command/install_lib.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'setuptools/command/install_lib.py') diff --git a/setuptools/command/install_lib.py b/setuptools/command/install_lib.py index 371a9e72..c2730568 100644 --- a/setuptools/command/install_lib.py +++ b/setuptools/command/install_lib.py @@ -1,5 +1,6 @@ import distutils.command.install_lib as orig import os, imp +from itertools import product class install_lib(orig.install_lib): """Don't add compiled flags to filenames of non-Python files""" @@ -23,9 +24,8 @@ class install_lib(orig.install_lib): for ns_pkg in self._get_SVEM_NSPs() for pkg in self._all_packages(ns_pkg) ) - for pkg in all_packages: - for f in self._gen_exclude_names(): - exclude.add(os.path.join(pkg_path(pkg), f)) + for pkg, f in product(all_packages, self._gen_exclude_names()): + exclude.add(os.path.join(pkg_path(pkg), f)) return exclude @staticmethod -- cgit v1.2.1 From 38b6f23637bcf8db5b9237393399041fbe36c65f Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 26 Sep 2014 10:46:37 -0400 Subject: Reorganize imports --- setuptools/command/install_lib.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'setuptools/command/install_lib.py') diff --git a/setuptools/command/install_lib.py b/setuptools/command/install_lib.py index c2730568..cc531c01 100644 --- a/setuptools/command/install_lib.py +++ b/setuptools/command/install_lib.py @@ -1,6 +1,7 @@ -import distutils.command.install_lib as orig -import os, imp +import os +import imp from itertools import product +import distutils.command.install_lib as orig class install_lib(orig.install_lib): """Don't add compiled flags to filenames of non-Python files""" -- cgit v1.2.1 From b925f19a4ef1b214650b770c74a083fc4f982758 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 26 Sep 2014 10:52:20 -0400 Subject: Incorporate the exclusion path in the _exclude function. --- setuptools/command/install_lib.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'setuptools/command/install_lib.py') diff --git a/setuptools/command/install_lib.py b/setuptools/command/install_lib.py index cc531c01..f36d8651 100644 --- a/setuptools/command/install_lib.py +++ b/setuptools/command/install_lib.py @@ -19,14 +19,18 @@ class install_lib(orig.install_lib): excluded for single_version_externally_managed installations. """ exclude = set() - pkg_path = lambda pkg: os.path.join(self.install_dir, *pkg.split('.')) + + def _exclude(pkg, exclusion_path): + parts = pkg.split('.') + [exclusion_path] + return os.path.join(self.install_dir, *parts) + all_packages = ( pkg for ns_pkg in self._get_SVEM_NSPs() for pkg in self._all_packages(ns_pkg) ) for pkg, f in product(all_packages, self._gen_exclude_names()): - exclude.add(os.path.join(pkg_path(pkg), f)) + exclude.add(_exclude(pkg, f)) return exclude @staticmethod -- cgit v1.2.1 From 86f35df37c309d2192a95259e77c6b4ba7f73876 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 26 Sep 2014 10:56:24 -0400 Subject: Return the exclusions directly --- setuptools/command/install_lib.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'setuptools/command/install_lib.py') diff --git a/setuptools/command/install_lib.py b/setuptools/command/install_lib.py index f36d8651..dcd85dec 100644 --- a/setuptools/command/install_lib.py +++ b/setuptools/command/install_lib.py @@ -1,6 +1,6 @@ import os import imp -from itertools import product +from itertools import product, starmap import distutils.command.install_lib as orig class install_lib(orig.install_lib): @@ -18,9 +18,11 @@ class install_lib(orig.install_lib): Return a collections.Sized collections.Container of paths to be excluded for single_version_externally_managed installations. """ - exclude = set() - def _exclude(pkg, exclusion_path): + """ + Given a package name and exclusion path within that package, + compute the full exclusion path. + """ parts = pkg.split('.') + [exclusion_path] return os.path.join(self.install_dir, *parts) @@ -29,9 +31,9 @@ class install_lib(orig.install_lib): for ns_pkg in self._get_SVEM_NSPs() for pkg in self._all_packages(ns_pkg) ) - for pkg, f in product(all_packages, self._gen_exclude_names()): - exclude.add(_exclude(pkg, f)) - return exclude + + excl_specs = product(all_packages, self._gen_exclude_names()) + return set(starmap(_exclude, excl_specs)) @staticmethod def _all_packages(pkg_name): -- cgit v1.2.1 From e301ab4639508fd7d9d4a3beb51974d211d1c109 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 26 Sep 2014 10:59:09 -0400 Subject: Move inline function into an instance method and rename for clarity. --- setuptools/command/install_lib.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'setuptools/command/install_lib.py') diff --git a/setuptools/command/install_lib.py b/setuptools/command/install_lib.py index dcd85dec..3cd16a8f 100644 --- a/setuptools/command/install_lib.py +++ b/setuptools/command/install_lib.py @@ -18,22 +18,22 @@ class install_lib(orig.install_lib): Return a collections.Sized collections.Container of paths to be excluded for single_version_externally_managed installations. """ - def _exclude(pkg, exclusion_path): - """ - Given a package name and exclusion path within that package, - compute the full exclusion path. - """ - parts = pkg.split('.') + [exclusion_path] - return os.path.join(self.install_dir, *parts) - all_packages = ( pkg for ns_pkg in self._get_SVEM_NSPs() for pkg in self._all_packages(ns_pkg) ) - excl_specs = product(all_packages, self._gen_exclude_names()) - return set(starmap(_exclude, excl_specs)) + excl_specs = product(all_packages, self._gen_exclusion_paths()) + return set(starmap(self._exclude_pkg_path, excl_specs)) + + def _exclude_pkg_path(self, pkg, exclusion_path): + """ + Given a package name and exclusion path within that package, + compute the full exclusion path. + """ + parts = pkg.split('.') + [exclusion_path] + return os.path.join(self.install_dir, *parts) @staticmethod def _all_packages(pkg_name): @@ -62,7 +62,7 @@ class install_lib(orig.install_lib): return self.distribution.namespace_packages if svem else [] @staticmethod - def _gen_exclude_names(): + def _gen_exclusion_paths(): """ Generate file paths to be excluded for namespace packages (bytecode cache files). -- cgit v1.2.1 From 5802fd80e413b63af8be9198f14da1ade47d409c Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 27 Sep 2014 09:29:53 -0400 Subject: Use rpartition here, essential to the algorithm. Fixes #259. --HG-- extra : amend_source : d7b3c001b4db616a67793dcc57d5c13e3828ad3a --- setuptools/command/install_lib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'setuptools/command/install_lib.py') diff --git a/setuptools/command/install_lib.py b/setuptools/command/install_lib.py index 3cd16a8f..9b772227 100644 --- a/setuptools/command/install_lib.py +++ b/setuptools/command/install_lib.py @@ -43,7 +43,7 @@ class install_lib(orig.install_lib): """ while pkg_name: yield pkg_name - pkg_name, sep, child = pkg_name.partition('.') + pkg_name, sep, child = pkg_name.rpartition('.') def _get_SVEM_NSPs(self): """ -- cgit v1.2.1 From 32237eae19b3722b2a1c87bc0a74613c5f12d6fd Mon Sep 17 00:00:00 2001 From: sunpoet Date: Fri, 20 Nov 2015 05:54:41 +0800 Subject: Fix package list inconsistency caused by namespace package on Python 3.5 namespace package will be skipped during installation. Since Python 3.5, .pyo files are removed and new .opt-1.pyc (and .opt-2.pyc) files are introduced [1]. However setuptools does not understand that new naming therefore the corresponding foo.opt-1.pyc is still added into package list (via --record). The inconsistency leads to a packaging error. [1] https://www.python.org/dev/peps/pep-0488/ --- setuptools/command/install_lib.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'setuptools/command/install_lib.py') diff --git a/setuptools/command/install_lib.py b/setuptools/command/install_lib.py index 9b772227..78fe6891 100644 --- a/setuptools/command/install_lib.py +++ b/setuptools/command/install_lib.py @@ -79,6 +79,8 @@ class install_lib(orig.install_lib): base = os.path.join('__pycache__', '__init__.' + imp.get_tag()) yield base + '.pyc' yield base + '.pyo' + yield base + '.opt-1.pyc' + yield base + '.opt-2.pyc' def copy_tree( self, infile, outfile, -- cgit v1.2.1 From 6d11e88f938f09ef16db4c6064b6e74acba4db1d Mon Sep 17 00:00:00 2001 From: stepshal Date: Tue, 12 Jul 2016 22:00:43 +0700 Subject: Fix quantity of blank lines after code object. --- setuptools/command/install_lib.py | 1 + 1 file changed, 1 insertion(+) (limited to 'setuptools/command/install_lib.py') diff --git a/setuptools/command/install_lib.py b/setuptools/command/install_lib.py index 78fe6891..2b31c3e3 100644 --- a/setuptools/command/install_lib.py +++ b/setuptools/command/install_lib.py @@ -3,6 +3,7 @@ import imp from itertools import product, starmap import distutils.command.install_lib as orig + class install_lib(orig.install_lib): """Don't add compiled flags to filenames of non-Python files""" -- cgit v1.2.1 From eb7436b36f9967d1becd2b822da548bd59b35d05 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Mon, 8 Jul 2019 09:32:21 -0700 Subject: Fix some usage of deprecated `imp` module --- setuptools/command/install_lib.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'setuptools/command/install_lib.py') diff --git a/setuptools/command/install_lib.py b/setuptools/command/install_lib.py index 2b31c3e3..07d65933 100644 --- a/setuptools/command/install_lib.py +++ b/setuptools/command/install_lib.py @@ -1,5 +1,5 @@ import os -import imp +import sys from itertools import product, starmap import distutils.command.install_lib as orig @@ -74,10 +74,10 @@ class install_lib(orig.install_lib): yield '__init__.pyc' yield '__init__.pyo' - if not hasattr(imp, 'get_tag'): + if not hasattr(sys, 'implementation'): return - base = os.path.join('__pycache__', '__init__.' + imp.get_tag()) + base = os.path.join('__pycache__', '__init__.' + sys.implementation.cache_tag) yield base + '.pyc' yield base + '.pyo' yield base + '.opt-1.pyc' -- cgit v1.2.1 From 3d4d8b9dde61b87271861b8c7ebeb168ac4fa72b Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 19 Jan 2020 12:46:30 -0500 Subject: =?UTF-8?q?=F0=9F=91=B9=20Feed=20the=20hobgoblins=20(delint).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- setuptools/command/install_lib.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'setuptools/command/install_lib.py') diff --git a/setuptools/command/install_lib.py b/setuptools/command/install_lib.py index 07d65933..2e9d8757 100644 --- a/setuptools/command/install_lib.py +++ b/setuptools/command/install_lib.py @@ -77,7 +77,8 @@ class install_lib(orig.install_lib): if not hasattr(sys, 'implementation'): return - base = os.path.join('__pycache__', '__init__.' + sys.implementation.cache_tag) + base = os.path.join( + '__pycache__', '__init__.' + sys.implementation.cache_tag) yield base + '.pyc' yield base + '.pyo' yield base + '.opt-1.pyc' -- cgit v1.2.1