From 9d6a6e5927ae0e67164383e419f3145fc154467e Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 4 Jan 2015 11:35:16 -0500 Subject: Use except/as, now supported by Python 2.6 --- setuptools/package_index.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'setuptools/package_index.py') diff --git a/setuptools/package_index.py b/setuptools/package_index.py index 58572ce6..5ed19130 100755 --- a/setuptools/package_index.py +++ b/setuptools/package_index.py @@ -699,25 +699,21 @@ class PackageIndex(Environment): return local_open(url) try: return open_with_auth(url, self.opener) - except (ValueError, httplib.InvalidURL): - v = sys.exc_info()[1] + except (ValueError, httplib.InvalidURL) as v: msg = ' '.join([str(arg) for arg in v.args]) if warning: self.warn(warning, msg) else: raise DistutilsError('%s %s' % (url, msg)) - except urllib2.HTTPError: - v = sys.exc_info()[1] + except urllib2.HTTPError as v: return v - except urllib2.URLError: - v = sys.exc_info()[1] + except urllib2.URLError as v: if warning: self.warn(warning, v.reason) else: raise DistutilsError("Download error for %s: %s" % (url, v.reason)) - except httplib.BadStatusLine: - v = sys.exc_info()[1] + except httplib.BadStatusLine as v: if warning: self.warn(warning, v.line) else: @@ -726,8 +722,7 @@ class PackageIndex(Environment): 'down, %s' % (url, v.line) ) - except httplib.HTTPException: - v = sys.exc_info()[1] + except httplib.HTTPException as v: if warning: self.warn(warning, v) else: -- cgit v1.2.1 From a631a0700d2ebcc9ee98c91d474f351974cc0b92 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 20 Mar 2015 13:30:51 -0400 Subject: Match Python 3 for bdist_dumb. --- setuptools/package_index.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'setuptools/package_index.py') diff --git a/setuptools/package_index.py b/setuptools/package_index.py index 5ed19130..963b4b41 100755 --- a/setuptools/package_index.py +++ b/setuptools/package_index.py @@ -140,8 +140,9 @@ def interpret_distro_name( parts = basename.split('-') if not py_version: for i,p in enumerate(parts[2:]): - if len(p)==5 and p.startswith('py2.'): - return # It's a bdist_dumb, not an sdist -- bail out + if p.match('py\d\.\d'): + # It's a bdist_dumb, not an sdist -- bail out + return for p in range(1,len(parts)+1): yield Distribution( -- cgit v1.2.1 From 00477b5b3e1f42b5ad9cdc553652e04beb675dbb Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 20 Mar 2015 13:31:38 -0400 Subject: Remove unused variable --- setuptools/package_index.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'setuptools/package_index.py') diff --git a/setuptools/package_index.py b/setuptools/package_index.py index 963b4b41..c117cb62 100755 --- a/setuptools/package_index.py +++ b/setuptools/package_index.py @@ -139,7 +139,7 @@ def interpret_distro_name( parts = basename.split('-') if not py_version: - for i,p in enumerate(parts[2:]): + for p in parts[2:]: if p.match('py\d\.\d'): # It's a bdist_dumb, not an sdist -- bail out return -- cgit v1.2.1 From edf097e299d4382700f819288cb08390c53e109d Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 20 Mar 2015 13:34:15 -0400 Subject: Flat is better than nested. --- setuptools/package_index.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'setuptools/package_index.py') diff --git a/setuptools/package_index.py b/setuptools/package_index.py index c117cb62..51769cdf 100755 --- a/setuptools/package_index.py +++ b/setuptools/package_index.py @@ -138,11 +138,9 @@ def interpret_distro_name( # versions in distribution archive names (sdist and bdist). parts = basename.split('-') - if not py_version: - for p in parts[2:]: - if p.match('py\d\.\d'): - # It's a bdist_dumb, not an sdist -- bail out - return + if not py_version and any(p.match('py\d\.\d') for p in parts[2:]): + # it is a bdist_dumb, not an sdist -- bail out + return for p in range(1,len(parts)+1): yield Distribution( -- cgit v1.2.1 From 01bb6e0e9217255cd835cefb8162463dac5d8e6d Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 20 Mar 2015 15:58:37 -0400 Subject: Correct regex usage --- setuptools/package_index.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'setuptools/package_index.py') diff --git a/setuptools/package_index.py b/setuptools/package_index.py index 963b4b41..95eb1cf3 100755 --- a/setuptools/package_index.py +++ b/setuptools/package_index.py @@ -140,7 +140,7 @@ def interpret_distro_name( parts = basename.split('-') if not py_version: for i,p in enumerate(parts[2:]): - if p.match('py\d\.\d'): + if re.match('py\d\.\d$', p): # It's a bdist_dumb, not an sdist -- bail out return -- cgit v1.2.1 From bb967deca4ff251c5aa8f0404b1223e94d9a301b Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 8 Dec 2015 19:04:13 -0500 Subject: Don't rely on repr for an HTML attribute value (could end up with 'u' prefix). Fixes #471. --- setuptools/package_index.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'setuptools/package_index.py') diff --git a/setuptools/package_index.py b/setuptools/package_index.py index cabf1039..dd2df229 100755 --- a/setuptools/package_index.py +++ b/setuptools/package_index.py @@ -1037,7 +1037,7 @@ def local_open(url): break elif os.path.isdir(os.path.join(filename,f)): f+='/' - files.append("%s" % (f,f)) + files.append('{name}'.format(name=f)) else: body = ("%s" % url) + \ "%s" % '\n'.join(files) -- cgit v1.2.1 From 59e47d76244bf25a9c385800328394e97be74b48 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 8 Dec 2015 19:06:03 -0500 Subject: Update syntax for modern style --- setuptools/package_index.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'setuptools/package_index.py') diff --git a/setuptools/package_index.py b/setuptools/package_index.py index dd2df229..330b8391 100755 --- a/setuptools/package_index.py +++ b/setuptools/package_index.py @@ -1031,12 +1031,12 @@ def local_open(url): elif path.endswith('/') and os.path.isdir(filename): files = [] for f in os.listdir(filename): - if f=='index.html': - with open(os.path.join(filename,f),'r') as fp: + if f == 'index.html': + with open(os.path.join(filename, f), 'r') as fp: body = fp.read() break - elif os.path.isdir(os.path.join(filename,f)): - f+='/' + elif os.path.isdir(os.path.join(filename, f)): + f += '/' files.append('{name}'.format(name=f)) else: body = ("%s" % url) + \ -- cgit v1.2.1 From 5a662289e866fb9bac77736ffede2fca05c79367 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 8 Dec 2015 19:06:41 -0500 Subject: Extract variable --- setuptools/package_index.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'setuptools/package_index.py') diff --git a/setuptools/package_index.py b/setuptools/package_index.py index 330b8391..1c156f07 100755 --- a/setuptools/package_index.py +++ b/setuptools/package_index.py @@ -1031,11 +1031,12 @@ def local_open(url): elif path.endswith('/') and os.path.isdir(filename): files = [] for f in os.listdir(filename): + filepath = os.path.join(filename, f) if f == 'index.html': - with open(os.path.join(filename, f), 'r') as fp: + with open(filepath, 'r') as fp: body = fp.read() break - elif os.path.isdir(os.path.join(filename, f)): + elif os.path.isdir(filepath): f += '/' files.append('{name}'.format(name=f)) else: -- cgit v1.2.1 From 95ac77a928a08c836c6f4ccc066a797357207abc Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 8 Dec 2015 19:14:04 -0500 Subject: Use new string formatting here as well --- setuptools/package_index.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'setuptools/package_index.py') diff --git a/setuptools/package_index.py b/setuptools/package_index.py index 1c156f07..525cb645 100755 --- a/setuptools/package_index.py +++ b/setuptools/package_index.py @@ -1040,8 +1040,9 @@ def local_open(url): f += '/' files.append('{name}'.format(name=f)) else: - body = ("%s" % url) + \ - "%s" % '\n'.join(files) + tmpl = ("{url}" + "{files}") + body = tmpl.format(url=url, files='\n'.join(files)) status, message = 200, "OK" else: status, message, body = 404, "Path not found", "Not found" -- cgit v1.2.1 From 5ba1d009e2c44b63fc2d2e1de09fd1d768c10fca Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 11 Dec 2015 10:13:30 -0500 Subject: Use context for opening file. --- setuptools/package_index.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'setuptools/package_index.py') diff --git a/setuptools/package_index.py b/setuptools/package_index.py index 525cb645..f81b8d78 100755 --- a/setuptools/package_index.py +++ b/setuptools/package_index.py @@ -359,8 +359,9 @@ class PackageIndex(Environment): self.scan_egg_link(item, entry) def scan_egg_link(self, path, entry): - lines = [_f for _f in map(str.strip, - open(os.path.join(path, entry))) if _f] + with open(os.path.join(path, entry)) as raw_lines: + # filter non-empty lines + lines = list(filter(None, map(str.strip, raw_lines))) if len(lines)==2: for dist in find_distributions(os.path.join(path, lines[0])): dist.location = os.path.join(path, *lines) -- cgit v1.2.1 From cd28f4e0eddf3f571cb0efe05a23fa4a7a254de7 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 11 Dec 2015 10:16:25 -0500 Subject: Replace nested code with short-circuit return. --- setuptools/package_index.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'setuptools/package_index.py') diff --git a/setuptools/package_index.py b/setuptools/package_index.py index f81b8d78..5adb8c2b 100755 --- a/setuptools/package_index.py +++ b/setuptools/package_index.py @@ -362,11 +362,15 @@ class PackageIndex(Environment): with open(os.path.join(path, entry)) as raw_lines: # filter non-empty lines lines = list(filter(None, map(str.strip, raw_lines))) - if len(lines)==2: - for dist in find_distributions(os.path.join(path, lines[0])): - dist.location = os.path.join(path, *lines) - dist.precedence = SOURCE_DIST - self.add(dist) + + if len(lines) != 2: + # format is not recognized; punt + return + + for dist in find_distributions(os.path.join(path, lines[0])): + dist.location = os.path.join(path, *lines) + dist.precedence = SOURCE_DIST + self.add(dist) def process_index(self,url,page): """Process the contents of a PyPI page""" -- cgit v1.2.1 From 2f7d95690e53fe92a82b055b82c4dc02b6a3339c Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 11 Dec 2015 10:18:38 -0500 Subject: Extract variables for improved documentation. --- setuptools/package_index.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'setuptools/package_index.py') diff --git a/setuptools/package_index.py b/setuptools/package_index.py index 5adb8c2b..36231f11 100755 --- a/setuptools/package_index.py +++ b/setuptools/package_index.py @@ -367,7 +367,9 @@ class PackageIndex(Environment): # format is not recognized; punt return - for dist in find_distributions(os.path.join(path, lines[0])): + egg_path, setup_path = lines + + for dist in find_distributions(os.path.join(path, egg_path)): dist.location = os.path.join(path, *lines) dist.precedence = SOURCE_DIST self.add(dist) -- cgit v1.2.1 From dacc24690e7c8503744ce433aae6dd74a50e2337 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 11 Dec 2015 10:26:16 -0500 Subject: Extract if in for loop --- setuptools/package_index.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'setuptools/package_index.py') diff --git a/setuptools/package_index.py b/setuptools/package_index.py index 36231f11..00ce3ea5 100755 --- a/setuptools/package_index.py +++ b/setuptools/package_index.py @@ -352,8 +352,8 @@ class PackageIndex(Environment): self.warn(msg, url) def scan_egg_links(self, search_path): - for item in search_path: - if os.path.isdir(item): + dirs = filter(os.path.isdir, search_path) + for item in dirs: for entry in os.listdir(item): if entry.endswith('.egg-link'): self.scan_egg_link(item, entry) -- cgit v1.2.1 From 6b8c9181fbb0ef5b223ba45ed361991c601d1d13 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 11 Dec 2015 10:28:36 -0500 Subject: Get filter from the future --- setuptools/package_index.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'setuptools/package_index.py') diff --git a/setuptools/package_index.py b/setuptools/package_index.py index 00ce3ea5..095688f9 100755 --- a/setuptools/package_index.py +++ b/setuptools/package_index.py @@ -20,7 +20,7 @@ from setuptools.compat import (urllib2, httplib, StringIO, HTTPError, urlparse, urlunparse, unquote, splituser, url2pathname, name2codepoint, unichr, urljoin, urlsplit, urlunsplit, - ConfigParser) + ConfigParser, filter) from setuptools.compat import filterfalse from fnmatch import translate from setuptools.py26compat import strip_fragment -- cgit v1.2.1 From 6667ea387d5694cf936644898acd20000ca7b1ec Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 11 Dec 2015 10:34:36 -0500 Subject: Replace nested for loop with dual-for generator expression. --- setuptools/package_index.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'setuptools/package_index.py') diff --git a/setuptools/package_index.py b/setuptools/package_index.py index 095688f9..3456f715 100755 --- a/setuptools/package_index.py +++ b/setuptools/package_index.py @@ -6,6 +6,7 @@ import shutil import socket import base64 import hashlib +import itertools from functools import wraps from pkg_resources import ( @@ -353,10 +354,13 @@ class PackageIndex(Environment): def scan_egg_links(self, search_path): dirs = filter(os.path.isdir, search_path) - for item in dirs: - for entry in os.listdir(item): - if entry.endswith('.egg-link'): - self.scan_egg_link(item, entry) + egg_links = ( + (path, entry) + for path in dirs + for entry in os.listdir(path) + if entry.endswith('.egg-link') + ) + list(itertools.starmap(self.scan_egg_link, egg_links)) def scan_egg_link(self, path, entry): with open(os.path.join(path, entry)) as raw_lines: -- cgit v1.2.1 From e99626c4eadf2e45ca5d729aaa3a5b4bb667536b Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 11 Dec 2015 10:36:25 -0500 Subject: Reclaim space from hanging indents --- setuptools/package_index.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'setuptools/package_index.py') diff --git a/setuptools/package_index.py b/setuptools/package_index.py index 3456f715..b0837628 100755 --- a/setuptools/package_index.py +++ b/setuptools/package_index.py @@ -17,11 +17,11 @@ from pkg_resources import ( from setuptools import ssl_support from distutils import log from distutils.errors import DistutilsError -from setuptools.compat import (urllib2, httplib, StringIO, HTTPError, - urlparse, urlunparse, unquote, splituser, - url2pathname, name2codepoint, - unichr, urljoin, urlsplit, urlunsplit, - ConfigParser, filter) +from setuptools.compat import ( + urllib2, httplib, StringIO, HTTPError, urlparse, urlunparse, unquote, + splituser, url2pathname, name2codepoint, unichr, urljoin, urlsplit, + urlunsplit, ConfigParser, filter, +) from setuptools.compat import filterfalse from fnmatch import translate from setuptools.py26compat import strip_fragment -- cgit v1.2.1 From 6a10b4afbad5dca346b7fc7a5d8bb6d08d3286b2 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 11 Dec 2015 10:37:09 -0500 Subject: Also use map from the future --- setuptools/package_index.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'setuptools/package_index.py') diff --git a/setuptools/package_index.py b/setuptools/package_index.py index b0837628..7c071457 100755 --- a/setuptools/package_index.py +++ b/setuptools/package_index.py @@ -20,7 +20,7 @@ from distutils.errors import DistutilsError from setuptools.compat import ( urllib2, httplib, StringIO, HTTPError, urlparse, urlunparse, unquote, splituser, url2pathname, name2codepoint, unichr, urljoin, urlsplit, - urlunsplit, ConfigParser, filter, + urlunsplit, ConfigParser, filter, map, ) from setuptools.compat import filterfalse from fnmatch import translate -- cgit v1.2.1 From ca4321bb5833e2daa7bee1a32a3dee37cb49f012 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Mon, 14 Dec 2015 04:55:43 -0500 Subject: Use the modern name for the configparser module --- setuptools/package_index.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'setuptools/package_index.py') diff --git a/setuptools/package_index.py b/setuptools/package_index.py index 7c071457..a26b58bc 100755 --- a/setuptools/package_index.py +++ b/setuptools/package_index.py @@ -20,7 +20,7 @@ from distutils.errors import DistutilsError from setuptools.compat import ( urllib2, httplib, StringIO, HTTPError, urlparse, urlunparse, unquote, splituser, url2pathname, name2codepoint, unichr, urljoin, urlsplit, - urlunsplit, ConfigParser, filter, map, + urlunsplit, configparser, filter, map, ) from setuptools.compat import filterfalse from fnmatch import translate @@ -945,14 +945,14 @@ class Credential(object): def __str__(self): return '%(username)s:%(password)s' % vars(self) -class PyPIConfig(ConfigParser.ConfigParser): +class PyPIConfig(configparser.ConfigParser): def __init__(self): """ Load from ~/.pypirc """ defaults = dict.fromkeys(['username', 'password', 'repository'], '') - ConfigParser.ConfigParser.__init__(self, defaults) + configparser.ConfigParser.__init__(self, defaults) rc = os.path.join(os.path.expanduser('~'), '.pypirc') if os.path.exists(rc): -- cgit v1.2.1 From 80adba1cb4b07f6d182c907b5c5f796eb7b6b93d Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Mon, 14 Dec 2015 05:31:46 -0500 Subject: Use SafeConfigParser in PyPIConfig file. Allows percent signs to be specified using two percent signs. Fixes #442. --- setuptools/package_index.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'setuptools/package_index.py') diff --git a/setuptools/package_index.py b/setuptools/package_index.py index a26b58bc..322f9a61 100755 --- a/setuptools/package_index.py +++ b/setuptools/package_index.py @@ -945,14 +945,14 @@ class Credential(object): def __str__(self): return '%(username)s:%(password)s' % vars(self) -class PyPIConfig(configparser.ConfigParser): +class PyPIConfig(configparser.SafeConfigParser): def __init__(self): """ Load from ~/.pypirc """ defaults = dict.fromkeys(['username', 'password', 'repository'], '') - configparser.ConfigParser.__init__(self, defaults) + configparser.SafeConfigParser.__init__(self, defaults) rc = os.path.join(os.path.expanduser('~'), '.pypirc') if os.path.exists(rc): -- cgit v1.2.1 From fbcbb51009bc76df9f2c66547439474799b9ab15 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Mon, 14 Dec 2015 05:38:30 -0500 Subject: Use RawConfigParser instead of SafeConfigParser in PyPIConfig class. Interpolated values are no longer supported. Since backward compatibility could not be retained in either case, prefer the simpler, more direct format. Ref #442. --- setuptools/package_index.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'setuptools/package_index.py') diff --git a/setuptools/package_index.py b/setuptools/package_index.py index 322f9a61..2c565e88 100755 --- a/setuptools/package_index.py +++ b/setuptools/package_index.py @@ -945,14 +945,14 @@ class Credential(object): def __str__(self): return '%(username)s:%(password)s' % vars(self) -class PyPIConfig(configparser.SafeConfigParser): +class PyPIConfig(configparser.RawConfigParser): def __init__(self): """ Load from ~/.pypirc """ defaults = dict.fromkeys(['username', 'password', 'repository'], '') - configparser.SafeConfigParser.__init__(self, defaults) + configparser.RawConfigParser.__init__(self, defaults) rc = os.path.join(os.path.expanduser('~'), '.pypirc') if os.path.exists(rc): -- cgit v1.2.1