Commit 75b870b9 authored by Jason R. Coombs's avatar Jason R. Coombs

Feed the hobgoblins (delint).

parent cb9e3a35
...@@ -480,8 +480,10 @@ def get_build_platform(): ...@@ -480,8 +480,10 @@ def get_build_platform():
try: try:
version = _macosx_vers() version = _macosx_vers()
machine = os.uname()[4].replace(" ", "_") machine = os.uname()[4].replace(" ", "_")
return "macosx-%d.%d-%s" % (int(version[0]), int(version[1]), return "macosx-%d.%d-%s" % (
_macosx_arch(machine)) int(version[0]), int(version[1]),
_macosx_arch(machine),
)
except ValueError: except ValueError:
# if someone is running a non-Mac darwin system, this will fall # if someone is running a non-Mac darwin system, this will fall
# through to the default implementation # through to the default implementation
...@@ -806,7 +808,8 @@ class WorkingSet(object): ...@@ -806,7 +808,8 @@ class WorkingSet(object):
already-installed distribution; it should return a ``Distribution`` or already-installed distribution; it should return a ``Distribution`` or
``None``. ``None``.
Unless `replace_conflicting=True`, raises a VersionConflict exception if Unless `replace_conflicting=True`, raises a VersionConflict exception
if
any requirements are found on the path that have the correct name but any requirements are found on the path that have the correct name but
the wrong version. Otherwise, if an `installer` is supplied it will be the wrong version. Otherwise, if an `installer` is supplied it will be
invoked to obtain the correct version of the requirement and activate invoked to obtain the correct version of the requirement and activate
...@@ -885,8 +888,8 @@ class WorkingSet(object): ...@@ -885,8 +888,8 @@ class WorkingSet(object):
# return list of distros to activate # return list of distros to activate
return to_activate return to_activate
def find_plugins(self, plugin_env, full_env=None, installer=None, def find_plugins(
fallback=True): self, plugin_env, full_env=None, installer=None, fallback=True):
"""Find all activatable distributions in `plugin_env` """Find all activatable distributions in `plugin_env`
Example usage:: Example usage::
...@@ -1040,7 +1043,8 @@ class _ReqExtras(dict): ...@@ -1040,7 +1043,8 @@ class _ReqExtras(dict):
class Environment(object): class Environment(object):
"""Searchable snapshot of distributions on a search path""" """Searchable snapshot of distributions on a search path"""
def __init__(self, search_path=None, platform=get_supported_platform(), def __init__(
self, search_path=None, platform=get_supported_platform(),
python=PY_MAJOR): python=PY_MAJOR):
"""Snapshot distributions available on a search path """Snapshot distributions available on a search path
...@@ -1113,7 +1117,8 @@ class Environment(object): ...@@ -1113,7 +1117,8 @@ class Environment(object):
dists.append(dist) dists.append(dist)
dists.sort(key=operator.attrgetter('hashcmp'), reverse=True) dists.sort(key=operator.attrgetter('hashcmp'), reverse=True)
def best_match(self, req, working_set, installer=None, replace_conflicting=False): def best_match(
self, req, working_set, installer=None, replace_conflicting=False):
"""Find distribution best matching `req` and usable on `working_set` """Find distribution best matching `req` and usable on `working_set`
This calls the ``find(req)`` method of the `working_set` to see if a This calls the ``find(req)`` method of the `working_set` to see if a
...@@ -1248,8 +1253,8 @@ class ResourceManager: ...@@ -1248,8 +1253,8 @@ class ResourceManager:
tmpl = textwrap.dedent(""" tmpl = textwrap.dedent("""
Can't extract file(s) to egg cache Can't extract file(s) to egg cache
The following error occurred while trying to extract file(s) to the Python egg The following error occurred while trying to extract file(s)
cache: to the Python egg cache:
{old_exc} {old_exc}
...@@ -1257,9 +1262,9 @@ class ResourceManager: ...@@ -1257,9 +1262,9 @@ class ResourceManager:
{cache_path} {cache_path}
Perhaps your account does not have write access to this directory? You can Perhaps your account does not have write access to this directory?
change the cache directory by setting the PYTHON_EGG_CACHE environment You can change the cache directory by setting the PYTHON_EGG_CACHE
variable to point to an accessible directory. environment variable to point to an accessible directory.
""").lstrip() """).lstrip()
err = ExtractionError(tmpl.format(**locals())) err = ExtractionError(tmpl.format(**locals()))
err.manager = self err.manager = self
...@@ -1309,11 +1314,13 @@ class ResourceManager: ...@@ -1309,11 +1314,13 @@ class ResourceManager:
return return
mode = os.stat(path).st_mode mode = os.stat(path).st_mode
if mode & stat.S_IWOTH or mode & stat.S_IWGRP: if mode & stat.S_IWOTH or mode & stat.S_IWGRP:
msg = ("%s is writable by group/others and vulnerable to attack " msg = (
"%s is writable by group/others and vulnerable to attack "
"when " "when "
"used with get_resource_filename. Consider a more secure " "used with get_resource_filename. Consider a more secure "
"location (set with .set_extraction_path or the " "location (set with .set_extraction_path or the "
"PYTHON_EGG_CACHE environment variable)." % path) "PYTHON_EGG_CACHE environment variable)." % path
)
warnings.warn(msg, UserWarning) warnings.warn(msg, UserWarning)
def postprocess(self, tempname, filename): def postprocess(self, tempname, filename):
...@@ -1597,8 +1604,11 @@ class DefaultProvider(EggProvider): ...@@ -1597,8 +1604,11 @@ class DefaultProvider(EggProvider):
@classmethod @classmethod
def _register(cls): def _register(cls):
loader_cls = getattr(importlib_machinery, 'SourceFileLoader', loader_cls = getattr(
type(None)) importlib_machinery,
'SourceFileLoader',
type(None),
)
register_loader_type(loader_cls, cls) register_loader_type(loader_cls, cls)
...@@ -1766,7 +1776,10 @@ class ZipProvider(EggProvider): ...@@ -1766,7 +1776,10 @@ class ZipProvider(EggProvider):
if self._is_current(real_path, zip_path): if self._is_current(real_path, zip_path):
return real_path return real_path
outf, tmpnam = _mkstemp(".$extract", dir=os.path.dirname(real_path)) outf, tmpnam = _mkstemp(
".$extract",
dir=os.path.dirname(real_path),
)
os.write(outf, self.loader.get_data(zip_path)) os.write(outf, self.loader.get_data(zip_path))
os.close(outf) os.close(outf)
utime(tmpnam, (timestamp, timestamp)) utime(tmpnam, (timestamp, timestamp))
...@@ -1972,7 +1985,8 @@ def find_eggs_in_zip(importer, path_item, only=False): ...@@ -1972,7 +1985,8 @@ def find_eggs_in_zip(importer, path_item, only=False):
for subitem in metadata.resource_listdir('/'): for subitem in metadata.resource_listdir('/'):
if _is_egg_path(subitem): if _is_egg_path(subitem):
subpath = os.path.join(path_item, subitem) subpath = os.path.join(path_item, subitem)
for dist in find_eggs_in_zip(zipimport.zipimporter(subpath), subpath): dists = find_eggs_in_zip(zipimport.zipimporter(subpath), subpath)
for dist in dists:
yield dist yield dist
elif subitem.lower().endswith('.dist-info'): elif subitem.lower().endswith('.dist-info'):
subpath = os.path.join(path_item, subitem) subpath = os.path.join(path_item, subitem)
...@@ -1981,7 +1995,6 @@ def find_eggs_in_zip(importer, path_item, only=False): ...@@ -1981,7 +1995,6 @@ def find_eggs_in_zip(importer, path_item, only=False):
yield Distribution.from_location(path_item, subitem, submeta) yield Distribution.from_location(path_item, subitem, submeta)
register_finder(zipimport.zipimporter, find_eggs_in_zip) register_finder(zipimport.zipimporter, find_eggs_in_zip)
...@@ -2527,7 +2540,8 @@ class Distribution(object): ...@@ -2527,7 +2540,8 @@ class Distribution(object):
"""Wrap an actual or potential sys.path entry w/metadata""" """Wrap an actual or potential sys.path entry w/metadata"""
PKG_INFO = 'PKG-INFO' PKG_INFO = 'PKG-INFO'
def __init__(self, location=None, metadata=None, project_name=None, def __init__(
self, location=None, metadata=None, project_name=None,
version=None, py_version=PY_MAJOR, platform=None, version=None, py_version=PY_MAJOR, platform=None,
precedence=EGG_DIST): precedence=EGG_DIST):
self.project_name = safe_name(project_name or 'Unknown') self.project_name = safe_name(project_name or 'Unknown')
...@@ -2803,7 +2817,8 @@ class Distribution(object): ...@@ -2803,7 +2817,8 @@ class Distribution(object):
if replace: if replace:
break break
else: else:
# don't modify path (even removing duplicates) if found and not replace # don't modify path (even removing duplicates) if
# found and not replace
return return
elif item == bdir and self.precedence == EGG_DIST: elif item == bdir and self.precedence == EGG_DIST:
# if it's an .egg, give it precedence over its directory # if it's an .egg, give it precedence over its directory
...@@ -2900,7 +2915,10 @@ class EggInfoDistribution(Distribution): ...@@ -2900,7 +2915,10 @@ class EggInfoDistribution(Distribution):
class DistInfoDistribution(Distribution): class DistInfoDistribution(Distribution):
"""Wrap an actual or potential sys.path entry w/metadata, .dist-info style""" """
Wrap an actual or potential sys.path entry
w/metadata, .dist-info style.
"""
PKG_INFO = 'METADATA' PKG_INFO = 'METADATA'
EQEQ = re.compile(r"([\(,])\s*(\d.*?)\s*([,\)])") EQEQ = re.compile(r"([\(,])\s*(\d.*?)\s*([,\)])")
...@@ -2950,7 +2968,7 @@ _distributionImpl = { ...@@ -2950,7 +2968,7 @@ _distributionImpl = {
'.egg': Distribution, '.egg': Distribution,
'.egg-info': EggInfoDistribution, '.egg-info': EggInfoDistribution,
'.dist-info': DistInfoDistribution, '.dist-info': DistInfoDistribution,
} }
def issue_warning(*args, **kw): def issue_warning(*args, **kw):
...@@ -3035,7 +3053,8 @@ class Requirement(packaging.requirements.Requirement): ...@@ -3035,7 +3053,8 @@ class Requirement(packaging.requirements.Requirement):
def __hash__(self): def __hash__(self):
return self.__hash return self.__hash
def __repr__(self): return "Requirement.parse(%r)" % str(self) def __repr__(self):
return "Requirement.parse(%r)" % str(self)
@staticmethod @staticmethod
def parse(s): def parse(s):
...@@ -3169,7 +3188,10 @@ def _initialize_master_working_set(): ...@@ -3169,7 +3188,10 @@ def _initialize_master_working_set():
dist.activate(replace=False) dist.activate(replace=False)
for dist in working_set for dist in working_set
) )
add_activation_listener(lambda dist: dist.activate(replace=True), existing=False) add_activation_listener(
lambda dist: dist.activate(replace=True),
existing=False,
)
working_set.entries = [] working_set.entries = []
# match order # match order
list(map(working_set.add_entry, sys.path)) list(map(working_set.add_entry, sys.path))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment