try:
version = _macosx_vers()
machine = os.uname()[4].replace(" ", "_")
- return "macosx-%d.%d-%s" % (int(version[0]), int(version[1]),
- _macosx_arch(machine))
+ return "macosx-%d.%d-%s" % (
+ int(version[0]), int(version[1]),
+ _macosx_arch(machine),
+ )
except ValueError:
# if someone is running a non-Mac darwin system, this will fall
# through to the default implementation
already-installed distribution; it should return a ``Distribution`` or
``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
the wrong version. Otherwise, if an `installer` is supplied it will be
invoked to obtain the correct version of the requirement and activate
# return list of distros to activate
return to_activate
- def find_plugins(self, plugin_env, full_env=None, installer=None,
- fallback=True):
+ def find_plugins(
+ self, plugin_env, full_env=None, installer=None, fallback=True):
"""Find all activatable distributions in `plugin_env`
Example usage::
class Environment(object):
"""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):
"""Snapshot distributions available on a search path
dists.append(dist)
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`
This calls the ``find(req)`` method of the `working_set` to see if a
tmpl = textwrap.dedent("""
Can't extract file(s) to egg cache
- The following error occurred while trying to extract file(s) to the Python egg
- cache:
+ The following error occurred while trying to extract file(s)
+ to the Python egg cache:
{old_exc}
{cache_path}
- Perhaps your account does not have write access to this directory? You can
- change the cache directory by setting the PYTHON_EGG_CACHE environment
- variable to point to an accessible directory.
+ Perhaps your account does not have write access to this directory?
+ You can change the cache directory by setting the PYTHON_EGG_CACHE
+ environment variable to point to an accessible directory.
""").lstrip()
err = ExtractionError(tmpl.format(**locals()))
err.manager = self
return
mode = os.stat(path).st_mode
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 "
"used with get_resource_filename. Consider a more secure "
"location (set with .set_extraction_path or the "
- "PYTHON_EGG_CACHE environment variable)." % path)
+ "PYTHON_EGG_CACHE environment variable)." % path
+ )
warnings.warn(msg, UserWarning)
def postprocess(self, tempname, filename):
@classmethod
def _register(cls):
- loader_cls = getattr(importlib_machinery, 'SourceFileLoader',
- type(None))
+ loader_cls = getattr(
+ importlib_machinery,
+ 'SourceFileLoader',
+ type(None),
+ )
register_loader_type(loader_cls, cls)
if self._is_current(real_path, zip_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.close(outf)
utime(tmpnam, (timestamp, timestamp))
for subitem in metadata.resource_listdir('/'):
if _is_egg_path(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
elif subitem.lower().endswith('.dist-info'):
subpath = os.path.join(path_item, subitem)
yield Distribution.from_location(path_item, subitem, submeta)
-
register_finder(zipimport.zipimporter, find_eggs_in_zip)
self.name = name
self.module_name = module_name
self.attrs = tuple(attrs)
- self.extras = Requirement.parse(("x[%s]" % ','.join(extras))).extras
+ self.extras = tuple(extras)
self.dist = dist
def __str__(self):
"""Wrap an actual or potential sys.path entry w/metadata"""
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,
precedence=EGG_DIST):
self.project_name = safe_name(project_name or 'Unknown')
if replace:
break
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
elif item == bdir and self.precedence == EGG_DIST:
# if it's an .egg, give it precedence over its directory
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'
EQEQ = re.compile(r"([\(,])\s*(\d.*?)\s*([,\)])")
'.egg': Distribution,
'.egg-info': EggInfoDistribution,
'.dist-info': DistInfoDistribution,
- }
+}
def issue_warning(*args, **kw):
def __hash__(self):
return self.__hash
- def __repr__(self): return "Requirement.parse(%r)" % str(self)
+ def __repr__(self):
+ return "Requirement.parse(%r)" % str(self)
@staticmethod
def parse(s):
dist.activate(replace=False)
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 = []
# match order
list(map(working_set.add_entry, sys.path))