From 9382fa0c05e533400613e1c7c0a777cabb463390 Mon Sep 17 00:00:00 2001 From: Donald Stufft Date: Thu, 4 Sep 2014 21:04:06 -0400 Subject: Implement PEP 440 by using the packaging library --- setuptools/command/egg_info.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'setuptools/command') diff --git a/setuptools/command/egg_info.py b/setuptools/command/egg_info.py index 72493d0b..cb67255b 100755 --- a/setuptools/command/egg_info.py +++ b/setuptools/command/egg_info.py @@ -15,6 +15,7 @@ from setuptools.command.sdist import sdist from setuptools.compat import basestring, PY3, StringIO from setuptools import svn_utils from setuptools.command.sdist import walk_revctrl +from setuptools._vendor.packaging.version import Version from pkg_resources import ( parse_requirements, safe_name, parse_version, safe_version, yield_lines, EntryPoint, iter_entry_points, to_filename) @@ -68,9 +69,14 @@ class egg_info(Command): self.vtags = self.tags() self.egg_version = self.tagged_version() + parsed_version = parse_version(self.egg_version) + try: + spec = ( + "%s==%s" if isinstance(parsed_version, Version) else "%s===%s" + ) list( - parse_requirements('%s==%s' % (self.egg_name, + parse_requirements(spec % (self.egg_name, self.egg_version)) ) except ValueError: -- cgit v1.2.1 From a9541756f6a12c91704feffec4ddfee859f12c30 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 27 Sep 2014 16:10:17 -0400 Subject: Fix indent --- setuptools/command/egg_info.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'setuptools/command') diff --git a/setuptools/command/egg_info.py b/setuptools/command/egg_info.py index 9ba719fe..de43bf0c 100755 --- a/setuptools/command/egg_info.py +++ b/setuptools/command/egg_info.py @@ -76,8 +76,7 @@ class egg_info(Command): "%s==%s" if isinstance(parsed_version, Version) else "%s===%s" ) list( - parse_requirements(spec % (self.egg_name, - self.egg_version)) + parse_requirements(spec % (self.egg_name, self.egg_version)) ) except ValueError: raise distutils.errors.DistutilsOptionError( -- cgit v1.2.1 From 7d9c21a893431798ba77edd62b5490ff4ce47ecf Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 27 Sep 2014 16:13:48 -0400 Subject: Prefer packaging library if available. --- setuptools/command/egg_info.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'setuptools/command') diff --git a/setuptools/command/egg_info.py b/setuptools/command/egg_info.py index de43bf0c..43df87dc 100755 --- a/setuptools/command/egg_info.py +++ b/setuptools/command/egg_info.py @@ -10,12 +10,18 @@ import os import re import sys +try: + import packaging.version +except ImportError: + # fallback to vendored version + import setuptools._vendor.packaging.version + packaging = setuptools._vendor.packaging + from setuptools import Command from setuptools.command.sdist import sdist from setuptools.compat import basestring, PY3, StringIO from setuptools import svn_utils from setuptools.command.sdist import walk_revctrl -from setuptools._vendor.packaging.version import Version from pkg_resources import ( parse_requirements, safe_name, parse_version, safe_version, yield_lines, EntryPoint, iter_entry_points, to_filename) @@ -72,8 +78,9 @@ class egg_info(Command): parsed_version = parse_version(self.egg_version) try: + is_version = isinstance(parsed_version, packaging.version.Version) spec = ( - "%s==%s" if isinstance(parsed_version, Version) else "%s===%s" + "%s==%s" if is_version else "%s===%s" ) list( parse_requirements(spec % (self.egg_name, self.egg_version)) -- cgit v1.2.1 From 76906b7a50726de89307d55690338d0f40a5aadb Mon Sep 17 00:00:00 2001 From: "\"W. Trevor King\"" Date: Thu, 16 Oct 2014 17:31:16 -0700 Subject: egg_info: Search egg-base for files to add to the manifest Before this commit, this: $ mkdir -p /tmp/xyz/{home,lib,scripts,data,egg} $ cat >/tmp/xyz/home/.pydistutils.cfg < [egg_info] > egg-base = /tmp/xyz/egg > EOF $ export PYTHONPATH=/tmp/xyz/lib $ export HOME=/tmp/xyz/home $ setup.py install --home=/tmp/xyz/home --install-lib=/tmp/xyz/lib \ > --install-scripts=/tmp/xyz/scripts --install-data=/tmp/xyz/data drops a lot of metadata, installing only SOURCES.txt and zip-safe under EGG-INFO. The problem is that the metadata files are written to egg-base, but egg-base is not searched when creating the manifest because it's outside of the current directory. Work around this by explicitly searching egg-base with distutils.filelist.findall (which is really the version monkeypatched in by setuptools/__init__.py). Since findall records relative paths, prefix the returned paths with egg-base, so the include_pattern looking for the absolute ei_cmd.egg_info will match them. --- setuptools/command/egg_info.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'setuptools/command') diff --git a/setuptools/command/egg_info.py b/setuptools/command/egg_info.py index 43df87dc..2318e54d 100755 --- a/setuptools/command/egg_info.py +++ b/setuptools/command/egg_info.py @@ -6,6 +6,7 @@ from distutils.filelist import FileList as _FileList from distutils.util import convert_path from distutils import log import distutils.errors +import distutils.filelist import os import re import sys @@ -324,6 +325,10 @@ class manifest_maker(sdist): elif os.path.exists(self.manifest): self.read_manifest() ei_cmd = self.get_finalized_command('egg_info') + if ei_cmd.egg_base != os.curdir: + self.filelist.allfiles.extend([ + os.path.join(ei_cmd.egg_base, path) + for path in distutils.filelist.findall(ei_cmd.egg_base)]) self.filelist.include_pattern("*", prefix=ei_cmd.egg_info) def prune_file_list(self): -- cgit v1.2.1 From 03048c86ba6f955179cb4dcab5dd2db024609f19 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Thu, 16 Oct 2014 21:49:22 -0700 Subject: egg_info: Split manifest_maker._add_egg_info into its own method On Sat, Oct 11, 2014 at 04:23:37PM -0000, Jason R. Coombs wrote [1]: > I suggest implementing the functionality as a separate method with a > docstring explaining the purpose. so that's what we have here. The docstring is adapted from the cbd4f603 (egg_info: Search egg-base for files to add to the manifest, 2014-10-16) commit message. It's a lot of docs for a single command (although there is a newsted list comprehension), so I'm fine if you drop this commit before merging. The motivation behind the lines would still be available in the version control history: $ hg blame -c setuptools/command/egg_info.py | grep -A1 ei_cmd.egg_base cbd4f6038604: if ei_cmd.egg_base != os.curdir: cbd4f6038604: self.filelist.allfiles.extend([ cbd4f6038604: os.path.join(ei_cmd.egg_base, path) cbd4f6038604: for path in distutils.filelist.findall(ei_cmd.egg_base)]) 80108b046cb6: self.filelist.include_pattern("*", prefix=ei_cmd.egg_info) $ hg log -vr cbd4f6038604 changeset: 3163:cbd4f6038604 ... description: egg_info: Search egg-base for files to add to the manifest Before this commit, this: $ mkdir -p /tmp/xyz/{home,lib,scripts,data,egg} $ cat >/tmp/xyz/home/.pydistutils.cfg < Date: Mon, 3 Nov 2014 14:06:44 +0000 Subject: Make egg_info command write out setup requirements This commit makes the egg_info command write out setup requirements as well as install requirements, setup requirements are written to a setup_requires.txt file. The commit adds a new function write_setup_requirements which uses the existing _write_requirements function to write setup requirements out to a file and adds a new entry point to the egg_info.writers group. --- setuptools/command/egg_info.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'setuptools/command') diff --git a/setuptools/command/egg_info.py b/setuptools/command/egg_info.py index 06764a17..78d86981 100755 --- a/setuptools/command/egg_info.py +++ b/setuptools/command/egg_info.py @@ -382,6 +382,12 @@ def write_requirements(cmd, basename, filename): cmd.write_or_delete_file("requirements", filename, data.getvalue()) +def write_setup_requirements(cmd, basename, filename): + data = StringIO() + _write_requirements(data, cmd.distribution.setup_requires) + cmd.write_or_delete_file("setup-requirements", filename, data.getvalue()) + + def write_toplevel_names(cmd, basename, filename): pkgs = dict.fromkeys( [ -- cgit v1.2.1 From 9a010cff9c654b4224721111eed0a27bb5ce726a Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 13 Dec 2014 14:59:23 -0500 Subject: Edit docstring for imperative form --- setuptools/command/egg_info.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'setuptools/command') diff --git a/setuptools/command/egg_info.py b/setuptools/command/egg_info.py index 302d6874..cbc30ff8 100755 --- a/setuptools/command/egg_info.py +++ b/setuptools/command/egg_info.py @@ -330,12 +330,13 @@ class manifest_maker(sdist): self.filelist.include_pattern("*", prefix=ei_cmd.egg_info) def _add_egg_info(self, cmd): - """Add paths for egg-info files for an external egg-base. + """ + Add paths for egg-info files for an external egg-base. - The egg-info files are written to egg-base. If egg-base is - outside the current working directory, we need a separate step - (this method) to search the egg-base directory when creating - the manifest. We use distutils.filelist.findall (which is + The egg-info files are written to egg-base. If egg-base is + outside the current working directory, this method + searchs the egg-base directory for files to include + in the manifest. Uses distutils.filelist.findall (which is really the version monkeypatched in by setuptools/__init__.py) to perform the search. -- cgit v1.2.1 From 3ad4ef1f994dcacc32b1a5f77d4c119ec0ce75af Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 13 Dec 2014 15:00:07 -0500 Subject: Remove superfluous list construction. --- setuptools/command/egg_info.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'setuptools/command') diff --git a/setuptools/command/egg_info.py b/setuptools/command/egg_info.py index cbc30ff8..e7e4cd7e 100755 --- a/setuptools/command/egg_info.py +++ b/setuptools/command/egg_info.py @@ -345,9 +345,9 @@ class manifest_maker(sdist): (which is looking for the absolute cmd.egg_info) will match them. """ - self.filelist.allfiles.extend([ + self.filelist.allfiles.extend( os.path.join(cmd.egg_base, path) - for path in distutils.filelist.findall(cmd.egg_base)]) + for path in distutils.filelist.findall(cmd.egg_base)) def prune_file_list(self): build = self.get_finalized_command('build') -- cgit v1.2.1 From fec71bcbc8b0aa6bde0b0d054587bcd9c08019e9 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 13 Dec 2014 15:03:48 -0500 Subject: Extract variables to capture substeps. --- setuptools/command/egg_info.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'setuptools/command') diff --git a/setuptools/command/egg_info.py b/setuptools/command/egg_info.py index e7e4cd7e..782b2777 100755 --- a/setuptools/command/egg_info.py +++ b/setuptools/command/egg_info.py @@ -345,9 +345,9 @@ class manifest_maker(sdist): (which is looking for the absolute cmd.egg_info) will match them. """ - self.filelist.allfiles.extend( - os.path.join(cmd.egg_base, path) - for path in distutils.filelist.findall(cmd.egg_base)) + discovered = distutils.filelist.findall(cmd.egg_base) + resolved = (os.path.join(cmd.egg_base, path) for path in discovered) + self.filelist.allfiles.extend(resolved) def prune_file_list(self): build = self.get_finalized_command('build') -- cgit v1.2.1 From e0bd38e357b89880dde1340a4089aacc1af4a89b Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 13 Dec 2014 15:07:15 -0500 Subject: Move invocation bypass into function itself, pertinent to the docstring. --- setuptools/command/egg_info.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'setuptools/command') diff --git a/setuptools/command/egg_info.py b/setuptools/command/egg_info.py index 782b2777..e1324127 100755 --- a/setuptools/command/egg_info.py +++ b/setuptools/command/egg_info.py @@ -325,8 +325,7 @@ class manifest_maker(sdist): elif os.path.exists(self.manifest): self.read_manifest() ei_cmd = self.get_finalized_command('egg_info') - if ei_cmd.egg_base != os.curdir: - self._add_egg_info(cmd=ei_cmd) + self._add_egg_info(cmd=ei_cmd) self.filelist.include_pattern("*", prefix=ei_cmd.egg_info) def _add_egg_info(self, cmd): @@ -345,6 +344,10 @@ class manifest_maker(sdist): (which is looking for the absolute cmd.egg_info) will match them. """ + if cmd.egg_base == os.curdir: + # egg-info files were already added by something else + return + discovered = distutils.filelist.findall(cmd.egg_base) resolved = (os.path.join(cmd.egg_base, path) for path in discovered) self.filelist.allfiles.extend(resolved) -- cgit v1.2.1 From 5df137548ceab35e51a53f12664df130bc8f2a5f Mon Sep 17 00:00:00 2001 From: Donald Stufft Date: Thu, 18 Dec 2014 12:29:36 -0500 Subject: Silence PEP440Warning by default unless invoking easy_install --- setuptools/command/easy_install.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'setuptools/command') diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py index 2e00b996..a71a7f36 100755 --- a/setuptools/command/easy_install.py +++ b/setuptools/command/easy_install.py @@ -54,9 +54,14 @@ from pkg_resources import ( import pkg_resources +# Turn on PEP440Warnings +warnings.filterwarnings("default", category=pkg_resources.PEP440Warning) + + sys_executable = os.environ.get('__PYVENV_LAUNCHER__', os.path.normpath(sys.executable)) + __all__ = [ 'samefile', 'easy_install', 'PthDistributions', 'extract_wininst_cfg', 'main', 'get_exe_prefixes', -- cgit v1.2.1 From 8bedbb5ee574b2f005dd5f066638cb79dc90f0eb Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 23 Dec 2014 09:27:21 -0500 Subject: Use hasattr per recommendation in docs for dl. --- setuptools/command/build_ext.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'setuptools/command') diff --git a/setuptools/command/build_ext.py b/setuptools/command/build_ext.py index 53bf9cd3..684200ad 100644 --- a/setuptools/command/build_ext.py +++ b/setuptools/command/build_ext.py @@ -33,10 +33,8 @@ if sys.platform == "darwin": use_stubs = True elif os.name != 'nt': try: - from dl import RTLD_NOW - - have_rtld = True - use_stubs = True + import dl + use_stubs = have_rtld = hasattr(dl, 'RTLD_NOW') except ImportError: pass -- cgit v1.2.1 From 3b434b5bd5a1e5e04461302850d0e2248cc828b1 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 23 Dec 2014 09:59:01 -0500 Subject: Define if_dl using simple lambda. --- setuptools/command/build_ext.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'setuptools/command') diff --git a/setuptools/command/build_ext.py b/setuptools/command/build_ext.py index 684200ad..b30e6192 100644 --- a/setuptools/command/build_ext.py +++ b/setuptools/command/build_ext.py @@ -39,10 +39,7 @@ elif os.name != 'nt': pass -def if_dl(s): - if have_rtld: - return s - return '' +if_dl = lambda s: s if have_rtld else '' class build_ext(_build_ext): -- cgit v1.2.1 From 956dce0ba58ab95298b872155543259467054557 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 23 Dec 2014 10:01:15 -0500 Subject: Extract variables for clarity and simpler indentation. --- setuptools/command/build_ext.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'setuptools/command') diff --git a/setuptools/command/build_ext.py b/setuptools/command/build_ext.py index b30e6192..be5e974c 100644 --- a/setuptools/command/build_ext.py +++ b/setuptools/command/build_ext.py @@ -118,10 +118,10 @@ class build_ext(_build_ext): # XXX what to do with conflicts? self.ext_map[fullname.split('.')[-1]] = ext - ltd = ext._links_to_dynamic = \ - self.shlibs and self.links_to_dynamic(ext) or False - ext._needs_stub = ltd and use_stubs and not isinstance(ext, - Library) + ltd = self.shlibs and self.links_to_dynamic(ext) or False + ns = ltd and use_stubs and not isinstance(ext, Library) + ext._links_to_dynamic = ltd + ext._needs_stub = ns filename = ext._file_name = self.get_ext_filename(fullname) libdir = os.path.dirname(os.path.join(self.build_lib, filename)) if ltd and libdir not in ext.library_dirs: -- cgit v1.2.1 From 8f8ff1d8c42f1aeb371134abd9a96e3f876e09be Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 23 Dec 2014 10:02:30 -0500 Subject: Extract variable for simplicity of indentation. --- setuptools/command/build_ext.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'setuptools/command') diff --git a/setuptools/command/build_ext.py b/setuptools/command/build_ext.py index be5e974c..b6eb89eb 100644 --- a/setuptools/command/build_ext.py +++ b/setuptools/command/build_ext.py @@ -181,9 +181,8 @@ class build_ext(_build_ext): self.compiler = self.shlib_compiler _build_ext.build_extension(self, ext) if ext._needs_stub: - self.write_stub( - self.get_finalized_command('build_py').build_lib, ext - ) + cmd = self.get_finalized_command('build_py').build_lib + self.write_stub(cmd, ext) finally: self.compiler = _compiler -- cgit v1.2.1 From d9de5582d21b62794bbdb39c0da11d711889c442 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 23 Dec 2014 10:04:35 -0500 Subject: Rewrite short-circuit for/if/else loop as any on generator expression. --- setuptools/command/build_ext.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'setuptools/command') diff --git a/setuptools/command/build_ext.py b/setuptools/command/build_ext.py index b6eb89eb..dae9c81e 100644 --- a/setuptools/command/build_ext.py +++ b/setuptools/command/build_ext.py @@ -193,10 +193,7 @@ class build_ext(_build_ext): # XXX static-compiled version libnames = dict.fromkeys([lib._full_name for lib in self.shlibs]) pkg = '.'.join(ext._full_name.split('.')[:-1] + ['']) - for libname in ext.libraries: - if pkg + libname in libnames: - return True - return False + return any(pkg + libname in libnames for libname in ext.libraries) def get_outputs(self): outputs = _build_ext.get_outputs(self) -- cgit v1.2.1 From 7fe63f7e3e848af843baa909930c1a61dcc2fbdd Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 23 Dec 2014 10:06:35 -0500 Subject: Extract filtering of extensions that need stubs. --- setuptools/command/build_ext.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'setuptools/command') diff --git a/setuptools/command/build_ext.py b/setuptools/command/build_ext.py index dae9c81e..5327a030 100644 --- a/setuptools/command/build_ext.py +++ b/setuptools/command/build_ext.py @@ -198,8 +198,8 @@ class build_ext(_build_ext): def get_outputs(self): outputs = _build_ext.get_outputs(self) optimize = self.get_finalized_command('build_py').optimize - for ext in self.extensions: - if ext._needs_stub: + ns_ext = (ext for ext in self.extensions if ext._needs_stub) + for ext in ns_ext: base = os.path.join(self.build_lib, *ext._full_name.split('.')) outputs.append(base + '.py') outputs.append(base + '.pyc') -- cgit v1.2.1 From 0b538cb95cbaf496897fcffb3c67a217d56f2511 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 23 Dec 2014 10:06:44 -0500 Subject: Reindent --- setuptools/command/build_ext.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'setuptools/command') diff --git a/setuptools/command/build_ext.py b/setuptools/command/build_ext.py index 5327a030..414ad166 100644 --- a/setuptools/command/build_ext.py +++ b/setuptools/command/build_ext.py @@ -200,11 +200,11 @@ class build_ext(_build_ext): optimize = self.get_finalized_command('build_py').optimize ns_ext = (ext for ext in self.extensions if ext._needs_stub) for ext in ns_ext: - base = os.path.join(self.build_lib, *ext._full_name.split('.')) - outputs.append(base + '.py') - outputs.append(base + '.pyc') - if optimize: - outputs.append(base + '.pyo') + base = os.path.join(self.build_lib, *ext._full_name.split('.')) + outputs.append(base + '.py') + outputs.append(base + '.pyc') + if optimize: + outputs.append(base + '.pyo') return outputs def write_stub(self, output_dir, ext, compile=False): -- cgit v1.2.1 From 2050af11f662a28f9c2c834552c195d90a5ac73e Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 23 Dec 2014 10:11:47 -0500 Subject: Rewrite function to use extend and a generator expression. --- setuptools/command/build_ext.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'setuptools/command') diff --git a/setuptools/command/build_ext.py b/setuptools/command/build_ext.py index 414ad166..b5c2738c 100644 --- a/setuptools/command/build_ext.py +++ b/setuptools/command/build_ext.py @@ -197,14 +197,13 @@ class build_ext(_build_ext): def get_outputs(self): outputs = _build_ext.get_outputs(self) - optimize = self.get_finalized_command('build_py').optimize + fn_exts = ['.py', '.pyc'] + if self.get_finalized_command('build_py').optimize: + fn_exts.append('.pyo') ns_ext = (ext for ext in self.extensions if ext._needs_stub) for ext in ns_ext: base = os.path.join(self.build_lib, *ext._full_name.split('.')) - outputs.append(base + '.py') - outputs.append(base + '.pyc') - if optimize: - outputs.append(base + '.pyo') + outputs.extend(base + fnext for fnext in fn_exts) return outputs def write_stub(self, output_dir, ext, compile=False): -- cgit v1.2.1 From b19c06058c720418db8a4496410cb82cc3526d54 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 23 Dec 2014 10:16:45 -0500 Subject: Extract method for clarity. --- setuptools/command/build_ext.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'setuptools/command') diff --git a/setuptools/command/build_ext.py b/setuptools/command/build_ext.py index b5c2738c..c85351b4 100644 --- a/setuptools/command/build_ext.py +++ b/setuptools/command/build_ext.py @@ -196,7 +196,10 @@ class build_ext(_build_ext): return any(pkg + libname in libnames for libname in ext.libraries) def get_outputs(self): - outputs = _build_ext.get_outputs(self) + return _build_ext.get_outputs(self) + self.__get_stubs_outputs() + + def __get_stubs_outputs(self): + outputs = [] fn_exts = ['.py', '.pyc'] if self.get_finalized_command('build_py').optimize: fn_exts.append('.pyo') -- cgit v1.2.1 From 2b880cc89d0ce6845c4bdd072ac518a7ed9baa08 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 23 Dec 2014 10:20:49 -0500 Subject: Use itertools.product to pair each base with each extension. --- setuptools/command/build_ext.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'setuptools/command') diff --git a/setuptools/command/build_ext.py b/setuptools/command/build_ext.py index c85351b4..2651beae 100644 --- a/setuptools/command/build_ext.py +++ b/setuptools/command/build_ext.py @@ -6,6 +6,7 @@ from distutils.errors import DistutilsError from distutils import log import os import sys +import itertools from setuptools.extension import Library @@ -199,15 +200,16 @@ class build_ext(_build_ext): return _build_ext.get_outputs(self) + self.__get_stubs_outputs() def __get_stubs_outputs(self): - outputs = [] fn_exts = ['.py', '.pyc'] if self.get_finalized_command('build_py').optimize: fn_exts.append('.pyo') ns_ext = (ext for ext in self.extensions if ext._needs_stub) - for ext in ns_ext: - base = os.path.join(self.build_lib, *ext._full_name.split('.')) - outputs.extend(base + fnext for fnext in fn_exts) - return outputs + ns_ext_bases = ( + os.path.join(self.build_lib, *ext._full_name.split('.')) + for ext in ns_ext + ) + pairs = itertools.product(ns_ext_bases, fn_exts) + return (base + fnext for base, fnext in pairs) def write_stub(self, output_dir, ext, compile=False): log.info("writing stub loader for %s to %s", ext._full_name, -- cgit v1.2.1 From 3ade3c11402c161a623e54502472fdd6cc7bd0dc Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 23 Dec 2014 10:21:19 -0500 Subject: Collapse two generator expressions. --- setuptools/command/build_ext.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'setuptools/command') diff --git a/setuptools/command/build_ext.py b/setuptools/command/build_ext.py index 2651beae..78155223 100644 --- a/setuptools/command/build_ext.py +++ b/setuptools/command/build_ext.py @@ -203,10 +203,10 @@ class build_ext(_build_ext): fn_exts = ['.py', '.pyc'] if self.get_finalized_command('build_py').optimize: fn_exts.append('.pyo') - ns_ext = (ext for ext in self.extensions if ext._needs_stub) ns_ext_bases = ( os.path.join(self.build_lib, *ext._full_name.split('.')) - for ext in ns_ext + for ext in self.extensions + if ext._needs_stub ) pairs = itertools.product(ns_ext_bases, fn_exts) return (base + fnext for base, fnext in pairs) -- cgit v1.2.1 From df765dcb6204366f4662004217997af35590fb9b Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 23 Dec 2014 10:24:46 -0500 Subject: Extract logic for getting the extensions for outputs. --- setuptools/command/build_ext.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'setuptools/command') diff --git a/setuptools/command/build_ext.py b/setuptools/command/build_ext.py index 78155223..2df3bc70 100644 --- a/setuptools/command/build_ext.py +++ b/setuptools/command/build_ext.py @@ -200,17 +200,20 @@ class build_ext(_build_ext): return _build_ext.get_outputs(self) + self.__get_stubs_outputs() def __get_stubs_outputs(self): - fn_exts = ['.py', '.pyc'] - if self.get_finalized_command('build_py').optimize: - fn_exts.append('.pyo') ns_ext_bases = ( os.path.join(self.build_lib, *ext._full_name.split('.')) for ext in self.extensions if ext._needs_stub ) - pairs = itertools.product(ns_ext_bases, fn_exts) + pairs = itertools.product(ns_ext_bases, self.__get_output_extensions()) return (base + fnext for base, fnext in pairs) + def __get_output_extensions(self): + yield '.py' + yield '.pyc' + if self.get_finalized_command('build_py').optimize: + yield '.pyo' + def write_stub(self, output_dir, ext, compile=False): log.info("writing stub loader for %s to %s", ext._full_name, output_dir) -- cgit v1.2.1 From 82390398562436f2928083066d8b1d2e786643fc Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 23 Dec 2014 10:28:35 -0500 Subject: Add comments for clarity. --- setuptools/command/build_ext.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'setuptools/command') diff --git a/setuptools/command/build_ext.py b/setuptools/command/build_ext.py index 2df3bc70..f0913115 100644 --- a/setuptools/command/build_ext.py +++ b/setuptools/command/build_ext.py @@ -200,11 +200,13 @@ class build_ext(_build_ext): return _build_ext.get_outputs(self) + self.__get_stubs_outputs() def __get_stubs_outputs(self): + # assemble the base name for each extension that needs a stub ns_ext_bases = ( os.path.join(self.build_lib, *ext._full_name.split('.')) for ext in self.extensions if ext._needs_stub ) + # pair each base with the extension pairs = itertools.product(ns_ext_bases, self.__get_output_extensions()) return (base + fnext for base, fnext in pairs) -- cgit v1.2.1 From 7bcbb5cbc893e97109c15cba3ea561aa0d462148 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 23 Dec 2014 10:29:02 -0500 Subject: Force list type for easy concatenation. --- setuptools/command/build_ext.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'setuptools/command') diff --git a/setuptools/command/build_ext.py b/setuptools/command/build_ext.py index f0913115..e4b2c593 100644 --- a/setuptools/command/build_ext.py +++ b/setuptools/command/build_ext.py @@ -208,7 +208,7 @@ class build_ext(_build_ext): ) # pair each base with the extension pairs = itertools.product(ns_ext_bases, self.__get_output_extensions()) - return (base + fnext for base, fnext in pairs) + return list(base + fnext for base, fnext in pairs) def __get_output_extensions(self): yield '.py' -- cgit v1.2.1 From 9063c163e105545bacb67865f5d35056eb342a49 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 24 Dec 2014 17:02:04 -0500 Subject: Move vendored packaging module into pkg_resources._vendor, restoring independence of pkg_resources from setuptools. Fixes #311. --- setuptools/command/egg_info.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'setuptools/command') diff --git a/setuptools/command/egg_info.py b/setuptools/command/egg_info.py index e1324127..dfbab0e9 100755 --- a/setuptools/command/egg_info.py +++ b/setuptools/command/egg_info.py @@ -15,8 +15,8 @@ try: import packaging.version except ImportError: # fallback to vendored version - import setuptools._vendor.packaging.version - packaging = setuptools._vendor.packaging + import pkg_resources._vendor.packaging.version + packaging = pkg_resources._vendor.packaging from setuptools import Command from setuptools.command.sdist import sdist -- cgit v1.2.1 From 170657b68f4b92e7e1bf82f5e19a831f5744af67 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 24 Dec 2014 17:11:49 -0500 Subject: Setuptools now uses the 'packaging' package from pkg_resources, unifying the behavior around resolution of that package. --- setuptools/command/egg_info.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'setuptools/command') diff --git a/setuptools/command/egg_info.py b/setuptools/command/egg_info.py index dfbab0e9..88ab0b82 100755 --- a/setuptools/command/egg_info.py +++ b/setuptools/command/egg_info.py @@ -11,13 +11,6 @@ import os import re import sys -try: - import packaging.version -except ImportError: - # fallback to vendored version - import pkg_resources._vendor.packaging.version - packaging = pkg_resources._vendor.packaging - from setuptools import Command from setuptools.command.sdist import sdist from setuptools.compat import basestring, PY3, StringIO @@ -28,6 +21,7 @@ from pkg_resources import ( safe_version, yield_lines, EntryPoint, iter_entry_points, to_filename) import setuptools.unicode_utils as unicode_utils +from pkg_resources import packaging class egg_info(Command): description = "create a distribution's .egg-info directory" -- cgit v1.2.1 From a7e5648bda737683c4ad220e61c44c1d17b73d87 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 24 Dec 2014 18:25:45 -0500 Subject: Removed svn support from setuptools. Ref #313. --- setuptools/command/egg_info.py | 8 +++++- setuptools/command/sdist.py | 57 ------------------------------------------ 2 files changed, 7 insertions(+), 58 deletions(-) (limited to 'setuptools/command') diff --git a/setuptools/command/egg_info.py b/setuptools/command/egg_info.py index 88ab0b82..526e0a8f 100755 --- a/setuptools/command/egg_info.py +++ b/setuptools/command/egg_info.py @@ -11,10 +11,14 @@ import os import re import sys +try: + from setuptools_svn import svn_utils +except ImportError: + pass + from setuptools import Command from setuptools.command.sdist import sdist from setuptools.compat import basestring, PY3, StringIO -from setuptools import svn_utils from setuptools.command.sdist import walk_revctrl from pkg_resources import ( parse_requirements, safe_name, parse_version, @@ -190,6 +194,8 @@ class egg_info(Command): @staticmethod def get_svn_revision(): + if 'svn_utils' not in globals(): + return "0" return str(svn_utils.SvnInfo.load(os.curdir).get_revision()) def find_sources(self): diff --git a/setuptools/command/sdist.py b/setuptools/command/sdist.py index a77c39f2..371bf547 100755 --- a/setuptools/command/sdist.py +++ b/setuptools/command/sdist.py @@ -1,12 +1,9 @@ from glob import glob -from distutils.util import convert_path from distutils import log import distutils.command.sdist as orig import os -import re import sys -from setuptools import svn_utils from setuptools.compat import PY3 from setuptools.utils import cs_path_exists @@ -22,60 +19,6 @@ def walk_revctrl(dirname=''): yield item -# TODO will need test case -class re_finder(object): - """ - Finder that locates files based on entries in a file matched by a - regular expression. - """ - - def __init__(self, path, pattern, postproc=lambda x: x): - self.pattern = pattern - self.postproc = postproc - self.entries_path = convert_path(path) - - def _finder(self, dirname, filename): - f = open(filename, 'rU') - try: - data = f.read() - finally: - f.close() - for match in self.pattern.finditer(data): - path = match.group(1) - # postproc was formerly used when the svn finder - # was an re_finder for calling unescape - path = self.postproc(path) - yield svn_utils.joinpath(dirname, path) - - def find(self, dirname=''): - path = svn_utils.joinpath(dirname, self.entries_path) - - if not os.path.isfile(path): - # entries file doesn't exist - return - for path in self._finder(dirname, path): - if os.path.isfile(path): - yield path - elif os.path.isdir(path): - for item in self.find(path): - yield item - - __call__ = find - - -def _default_revctrl(dirname=''): - 'Primary svn_cvs entry point' - for finder in finders: - for item in finder(dirname): - yield item - - -finders = [ - re_finder('CVS/Entries', re.compile(r"^\w?/([^/]+)/", re.M)), - svn_utils.svn_finder, -] - - class sdist(orig.sdist): """Smart sdist that finds anything supported by revision control""" -- cgit v1.2.1 From 4a7ea62f3efc4297bcc8c2a8094fa687474fb5f1 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Mon, 29 Dec 2014 14:06:26 -0500 Subject: Reindent using textwrap --- setuptools/command/easy_install.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'setuptools/command') diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py index a71a7f36..d368e1a3 100755 --- a/setuptools/command/easy_install.py +++ b/setuptools/command/easy_install.py @@ -2121,10 +2121,10 @@ def main(argv=None, **kw): from setuptools.dist import Distribution import distutils.core - USAGE = """\ -usage: %(script)s [options] requirement_or_url ... - or: %(script)s --help -""" + USAGE = textwrap.dedent(""" + usage: %(script)s [options] requirement_or_url ... + or: %(script)s --help + """).lstrip() def gen_usage(script_name): return USAGE % dict( -- cgit v1.2.1 From 8826a85c8c2dd4b3b5080de725486b0b30e79e4f Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Mon, 29 Dec 2014 14:29:09 -0500 Subject: Extract _patch_usage and re-implement as a context manager. --- setuptools/command/easy_install.py | 50 ++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 23 deletions(-) (limited to 'setuptools/command') diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py index d368e1a3..125ceba2 100755 --- a/setuptools/command/easy_install.py +++ b/setuptools/command/easy_install.py @@ -34,6 +34,7 @@ import textwrap import warnings import site import struct +import contextlib from setuptools import Command from setuptools.sandbox import run_setup @@ -2119,39 +2120,42 @@ def bootstrap(): def main(argv=None, **kw): from setuptools import setup from setuptools.dist import Distribution - import distutils.core - - USAGE = textwrap.dedent(""" - usage: %(script)s [options] requirement_or_url ... - or: %(script)s --help - """).lstrip() - - def gen_usage(script_name): - return USAGE % dict( - script=os.path.basename(script_name), - ) - - def with_ei_usage(f): - old_gen_usage = distutils.core.gen_usage - try: - distutils.core.gen_usage = gen_usage - return f() - finally: - distutils.core.gen_usage = old_gen_usage class DistributionWithoutHelpCommands(Distribution): common_usage = "" def _show_help(self, *args, **kw): - with_ei_usage(lambda: Distribution._show_help(self, *args, **kw)) + with _patch_usage(): + Distribution._show_help(self, *args, **kw) if argv is None: argv = sys.argv[1:] - with_ei_usage( - lambda: setup( + with _patch_usage(): + setup( script_args=['-q', 'easy_install', '-v'] + argv, script_name=sys.argv[0] or 'easy_install', distclass=DistributionWithoutHelpCommands, **kw ) - ) + + +@contextlib.contextmanager +def _patch_usage(): + import distutils.core + USAGE = textwrap.dedent(""" + usage: %(script)s [options] requirement_or_url ... + or: %(script)s --help + """).lstrip() + + def gen_usage(script_name): + return USAGE % dict( + script=os.path.basename(script_name), + ) + + saved = distutils.core.gen_usage + distutils.core.gen_usage = gen_usage + try: + yield + finally: + distutils.core.gen_usage = saved + -- cgit v1.2.1 From 10197f6d76a56d358236ceb35435d3789d0fd2b0 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 30 Dec 2014 09:45:51 -0500 Subject: Extract variable for clarity of reading --- setuptools/command/easy_install.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'setuptools/command') diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py index 125ceba2..1a2f56ae 100755 --- a/setuptools/command/easy_install.py +++ b/setuptools/command/easy_install.py @@ -1549,10 +1549,14 @@ class PthDistributions(Environment): def add(self, dist): """Add `dist` to the distribution map""" - if (dist.location not in self.paths and ( - dist.location not in self.sitedirs or - dist.location == os.getcwd() # account for '.' being in PYTHONPATH - )): + new_path = ( + dist.location not in self.paths and ( + dist.location not in self.sitedirs or + # account for '.' being in PYTHONPATH + dist.location == os.getcwd() + ) + ) + if new_path: self.paths.append(dist.location) self.dirty = True Environment.add(self, dist) -- cgit v1.2.1 From 314d143ffcc838e1dbf7177b601c139f8d0b609f Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 31 Dec 2014 10:15:10 -0500 Subject: Restore _default_revctrl implementation (stubbed). Fixes #320. --- setuptools/command/sdist.py | 1 + 1 file changed, 1 insertion(+) (limited to 'setuptools/command') diff --git a/setuptools/command/sdist.py b/setuptools/command/sdist.py index 371bf547..a4e8288a 100755 --- a/setuptools/command/sdist.py +++ b/setuptools/command/sdist.py @@ -11,6 +11,7 @@ import pkg_resources READMES = ('README', 'README.rst', 'README.txt') +_default_revctrl = list def walk_revctrl(dirname=''): """Find all files under revision control""" -- cgit v1.2.1 From 7e6639875e34bd8150a2c430f4d214da9c197e94 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 31 Dec 2014 10:19:25 -0500 Subject: Remove superfluous parentheses --- setuptools/command/sdist.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'setuptools/command') diff --git a/setuptools/command/sdist.py b/setuptools/command/sdist.py index a4e8288a..3d33df80 100755 --- a/setuptools/command/sdist.py +++ b/setuptools/command/sdist.py @@ -9,7 +9,7 @@ from setuptools.utils import cs_path_exists import pkg_resources -READMES = ('README', 'README.rst', 'README.txt') +READMES = 'README', 'README.rst', 'README.txt' _default_revctrl = list -- cgit v1.2.1 From 80a28fa8c044ccb74e4ae54544be8c449ebd03e8 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 31 Dec 2014 12:35:32 -0500 Subject: Use underlying invocation of ._load directly --- setuptools/command/test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'setuptools/command') diff --git a/setuptools/command/test.py b/setuptools/command/test.py index 1038da71..2bf5cb16 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -172,4 +172,4 @@ class test(Command): if val is None: return parsed = EntryPoint.parse("x=" + val) - return parsed.load(require=False)() + return parsed._load()() -- cgit v1.2.1