Commit b8865685 authored by Jason R. Coombs's avatar Jason R. Coombs

Normalize whitespace per more modern style conventions.

parent 3d4e1f72
...@@ -343,8 +343,10 @@ run_main = run_script ...@@ -343,8 +343,10 @@ run_main = run_script
def get_distribution(dist): def get_distribution(dist):
"""Return a current distribution object for a Requirement or string""" """Return a current distribution object for a Requirement or string"""
if isinstance(dist, basestring): dist = Requirement.parse(dist) if isinstance(dist, basestring):
if isinstance(dist, Requirement): dist = get_provider(dist) dist = Requirement.parse(dist)
if isinstance(dist, Requirement):
dist = get_provider(dist)
if not isinstance(dist, Distribution): if not isinstance(dist, Distribution):
raise TypeError("Expected string, Requirement, or Distribution", dist) raise TypeError("Expected string, Requirement, or Distribution", dist)
return dist return dist
...@@ -886,7 +888,8 @@ class Environment(object): ...@@ -886,7 +888,8 @@ class Environment(object):
def __iter__(self): def __iter__(self):
"""Yield the unique project names of the available distributions""" """Yield the unique project names of the available distributions"""
for key in self._distmap.keys(): for key in self._distmap.keys():
if self[key]: yield key if self[key]:
yield key
def __iadd__(self, other): def __iadd__(self, other):
"""In-place addition of a distribution or environment""" """In-place addition of a distribution or environment"""
...@@ -2014,7 +2017,8 @@ def fixup_namespace_packages(path_item, parent=None): ...@@ -2014,7 +2017,8 @@ def fixup_namespace_packages(path_item, parent=None):
try: try:
for package in _namespace_packages.get(parent,()): for package in _namespace_packages.get(parent,()):
subpath = _handle_ns(package, path_item) subpath = _handle_ns(package, path_item)
if subpath: fixup_namespace_packages(subpath, package) if subpath:
fixup_namespace_packages(subpath, package)
finally: finally:
imp.release_lock() imp.release_lock()
...@@ -2146,13 +2150,16 @@ def parse_version(s): ...@@ -2146,13 +2150,16 @@ def parse_version(s):
for part in _parse_version_parts(s.lower()): for part in _parse_version_parts(s.lower()):
if part.startswith('*'): if part.startswith('*'):
# remove '-' before a prerelease tag # remove '-' before a prerelease tag
if part<'*final': if part < '*final':
while parts and parts[-1]=='*final-': parts.pop() while parts and parts[-1] == '*final-':
parts.pop()
# remove trailing zeros from each series of numeric parts # remove trailing zeros from each series of numeric parts
while parts and parts[-1]=='00000000': while parts and parts[-1]=='00000000':
parts.pop() parts.pop()
parts.append(part) parts.append(part)
return tuple(parts) return tuple(parts)
class EntryPoint(object): class EntryPoint(object):
"""Object representing an advertised importable object""" """Object representing an advertised importable object"""
...@@ -2177,7 +2184,8 @@ class EntryPoint(object): ...@@ -2177,7 +2184,8 @@ class EntryPoint(object):
return "EntryPoint.parse(%r)" % str(self) return "EntryPoint.parse(%r)" % str(self)
def load(self, require=True, env=None, installer=None): def load(self, require=True, env=None, installer=None):
if require: self.require(env, installer) if require:
self.require(env, installer)
entry = __import__(self.module_name, globals(), globals(), entry = __import__(self.module_name, globals(), globals(),
['__name__']) ['__name__'])
for attr in self.attrs: for attr in self.attrs:
...@@ -2207,22 +2215,21 @@ class EntryPoint(object): ...@@ -2207,22 +2215,21 @@ class EntryPoint(object):
""" """
try: try:
attrs = extras = () attrs = extras = ()
name, value = src.split('=',1) name, value = src.split('=', 1)
if '[' in value: if '[' in value:
value, extras = value.split('[',1) value, extras = value.split('[', 1)
req = Requirement.parse("x["+extras) req = Requirement.parse("x[" + extras)
if req.specs: raise ValueError if req.specs:
raise ValueError
extras = req.extras extras = req.extras
if ':' in value: if ':' in value:
value, attrs = value.split(':',1) value, attrs = value.split(':', 1)
if not MODULE(attrs.rstrip()): if not MODULE(attrs.rstrip()):
raise ValueError raise ValueError
attrs = attrs.rstrip().split('.') attrs = attrs.rstrip().split('.')
except ValueError: except ValueError:
raise ValueError( msg = "EntryPoint must be in 'name=module:attrs [extras]' format"
"EntryPoint must be in 'name=module:attrs [extras]' format", raise ValueError(msg, src)
src
)
else: else:
return cls(name.strip(), value.strip(), attrs, extras, dist) return cls(name.strip(), value.strip(), attrs, extras, dist)
...@@ -2379,7 +2386,7 @@ class Distribution(object): ...@@ -2379,7 +2386,7 @@ class Distribution(object):
for extra, reqs in split_sections(self._get_metadata(name)): for extra, reqs in split_sections(self._get_metadata(name)):
if extra: if extra:
if ':' in extra: if ':' in extra:
extra, marker = extra.split(':',1) extra, marker = extra.split(':', 1)
if invalid_marker(marker): if invalid_marker(marker):
# XXX warn # XXX warn
reqs=[] reqs=[]
...@@ -2393,7 +2400,7 @@ class Distribution(object): ...@@ -2393,7 +2400,7 @@ class Distribution(object):
"""List of Requirements needed for this distro if `extras` are used""" """List of Requirements needed for this distro if `extras` are used"""
dm = self._dep_map dm = self._dep_map
deps = [] deps = []
deps.extend(dm.get(None,())) deps.extend(dm.get(None, ()))
for ext in extras: for ext in extras:
try: try:
deps.extend(dm[safe_extra(ext)]) deps.extend(dm[safe_extra(ext)])
...@@ -2410,7 +2417,8 @@ class Distribution(object): ...@@ -2410,7 +2417,8 @@ class Distribution(object):
def activate(self, path=None): def activate(self, path=None):
"""Ensure distribution is importable on `path` (default=sys.path)""" """Ensure distribution is importable on `path` (default=sys.path)"""
if path is None: path = sys.path if path is None:
path = sys.path
self.insert_on(path) self.insert_on(path)
if path is sys.path: if path is sys.path:
fixup_namespace_packages(self.location) fixup_namespace_packages(self.location)
...@@ -2426,7 +2434,7 @@ class Distribution(object): ...@@ -2426,7 +2434,7 @@ class Distribution(object):
) )
if self.platform: if self.platform:
filename += '-'+self.platform filename += '-' + self.platform
return filename return filename
def __repr__(self): def __repr__(self):
...@@ -2436,8 +2444,10 @@ class Distribution(object): ...@@ -2436,8 +2444,10 @@ class Distribution(object):
return str(self) return str(self)
def __str__(self): def __str__(self):
try: version = getattr(self,'version',None) try:
except ValueError: version = None version = getattr(self, 'version', None)
except ValueError:
version = None
version = version or "[unknown version]" version = version or "[unknown version]"
return "%s %s" % (self.project_name, version) return "%s %s" % (self.project_name, version)
...@@ -2493,9 +2503,9 @@ class Distribution(object): ...@@ -2493,9 +2503,9 @@ class Distribution(object):
npath= [(p and _normalize_cached(p) or p) for p in path] npath= [(p and _normalize_cached(p) or p) for p in path]
for p, item in enumerate(npath): for p, item in enumerate(npath):
if item==nloc: if item == nloc:
break break
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
if path is sys.path: if path is sys.path:
self.check_version_conflict() self.check_version_conflict()
...@@ -2509,7 +2519,7 @@ class Distribution(object): ...@@ -2509,7 +2519,7 @@ class Distribution(object):
return return
# p is the spot where we found or inserted loc; now remove duplicates # p is the spot where we found or inserted loc; now remove duplicates
while 1: while True:
try: try:
np = npath.index(nloc, p+1) np = npath.index(nloc, p+1)
except ValueError: except ValueError:
...@@ -2522,7 +2532,7 @@ class Distribution(object): ...@@ -2522,7 +2532,7 @@ class Distribution(object):
return return
def check_version_conflict(self): def check_version_conflict(self):
if self.key=='setuptools': if self.key == 'setuptools':
# ignore the inevitable setuptools self-conflicts :( # ignore the inevitable setuptools self-conflicts :(
return return
...@@ -2547,16 +2557,14 @@ class Distribution(object): ...@@ -2547,16 +2557,14 @@ class Distribution(object):
try: try:
self.version self.version
except ValueError: except ValueError:
issue_warning("Unbuilt egg for "+repr(self)) issue_warning("Unbuilt egg for " + repr(self))
return False return False
return True return True
def clone(self,**kw): def clone(self,**kw):
"""Copy this distribution, substituting in any changed keyword args""" """Copy this distribution, substituting in any changed keyword args"""
for attr in ( names = 'project_name version py_version platform location precedence'
'project_name', 'version', 'py_version', 'platform', 'location', for attr in names.split():
'precedence'
):
kw.setdefault(attr, getattr(self, attr, None)) kw.setdefault(attr, getattr(self, attr, None))
kw.setdefault('metadata', self._provider) kw.setdefault('metadata', self._provider)
return self.__class__(**kw) return self.__class__(**kw)
...@@ -2646,7 +2654,7 @@ def issue_warning(*args,**kw): ...@@ -2646,7 +2654,7 @@ def issue_warning(*args,**kw):
level += 1 level += 1
except ValueError: except ValueError:
pass pass
warnings.warn(stacklevel = level+1, *args, **kw) warnings.warn(stacklevel=level + 1, *args, **kw)
def parse_requirements(strs): def parse_requirements(strs):
...@@ -2690,7 +2698,8 @@ def parse_requirements(strs): ...@@ -2690,7 +2698,8 @@ def parse_requirements(strs):
match = TERMINATOR(line, p) match = TERMINATOR(line, p)
# skip the terminator, if any # skip the terminator, if any
if match: p = match.end() if match:
p = match.end()
return line, p, items return line, p, items
for line in lines: for line in lines:
...@@ -2736,11 +2745,15 @@ class Requirement: ...@@ -2736,11 +2745,15 @@ class Requirement:
def __str__(self): def __str__(self):
specs = ','.join([''.join(s) for s in self.specs]) specs = ','.join([''.join(s) for s in self.specs])
extras = ','.join(self.extras) extras = ','.join(self.extras)
if extras: extras = '[%s]' % extras if extras:
extras = '[%s]' % extras
return '%s%s%s' % (self.project_name, extras, specs) return '%s%s%s' % (self.project_name, extras, specs)
def __eq__(self, other): def __eq__(self, other):
return isinstance(other, Requirement) and self.hashCmp==other.hashCmp return (
isinstance(other, Requirement) and
self.hashCmp == other.hashCmp
)
def __contains__(self, item): def __contains__(self, item):
if isinstance(item, Distribution): if isinstance(item, Distribution):
...@@ -2757,16 +2770,17 @@ class Requirement: ...@@ -2757,16 +2770,17 @@ class Requirement:
for parsed, trans, op, ver in self.index: for parsed, trans, op, ver in self.index:
# Indexing: 0, 1, -1 # Indexing: 0, 1, -1
action = trans[compare(item, parsed)] action = trans[compare(item, parsed)]
if action=='F': if action == 'F':
return False return False
elif action=='T': elif action == 'T':
return True return True
elif action=='+': elif action == '+':
last = True last = True
elif action=='-' or last is None: elif action == '-' or last is None:
last = False last = False
# no rules encountered # no rules encountered
if last is None: last = True if last is None:
last = True
return last return last
def __hash__(self): def __hash__(self):
...@@ -2778,7 +2792,7 @@ class Requirement: ...@@ -2778,7 +2792,7 @@ class Requirement:
def parse(s): def parse(s):
reqs = list(parse_requirements(s)) reqs = list(parse_requirements(s))
if reqs: if reqs:
if len(reqs)==1: if len(reqs) == 1:
return reqs[0] return reqs[0]
raise ValueError("Expected only one requirement", s) raise ValueError("Expected only one requirement", s)
raise ValueError("No requirements found", s) raise ValueError("No requirements found", s)
......
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