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