if dist.key in self.by_key:
return # ignore hidden distros
+ # If we have a __requires__ then we can already tell if this
+ # dist is unsatisfactory, in which case we won't add it.
+ if __requires__ is not None:
+ for thisreqstr in __requires__:
+ for thisreq in parse_requirements(thisreqstr):
+ if thisreq.key == dist.key:
+ if dist not in thisreq:
+ return
+
+
self.by_key[dist.key] = dist
if dist.key not in keys:
keys.append(dist.key)
_initialize(globals())
# Prepare the master working set and make the ``require()`` API available
+__requires__ = None
_declare_state('object', working_set = WorkingSet())
try:
# Does the main program list any requirements?
# Yes: ensure the requirements are met, by prefixing sys.path if necessary
try:
working_set.require(__requires__)
- except VersionConflict: # try it without defaults already on sys.path
+ except (VersionConflict, DistributionNotFound): # try it without defaults already on sys.path
working_set = WorkingSet([]) # by starting with an empty path
- for dist in working_set.resolve(
- parse_requirements(__requires__), Environment()
- ):
- working_set.add(dist)
+ try:
+ for dist in working_set.resolve(
+ parse_requirements(__requires__), Environment()
+ ):
+ working_set.add(dist)
+ except DistributionNotFound:
+ pass
for entry in sys.path: # add any missing entries from sys.path
if entry not in working_set.entries:
working_set.add_entry(entry)
spec = str(dist.as_requirement())
is_script = is_python_script(script_text, script_name)
+ requires = [spec] + [str(r) for r in dist.requires()]
if is_script and dev_path:
script_text = get_script_header(script_text) + (
"# EASY-INSTALL-DEV-SCRIPT: %(spec)r,%(script_name)r\n"
- "__requires__ = %(spec)r\n"
+ "__requires__ = %(requires)r\n"
"from pkg_resources import require; require(%(spec)r)\n"
"del require\n"
"__file__ = %(dev_path)r\n"
elif is_script:
script_text = get_script_header(script_text) + (
"# EASY-INSTALL-SCRIPT: %(spec)r,%(script_name)r\n"
- "__requires__ = %(spec)r\n"
+ "__requires__ = %(requires)r\n"
"import pkg_resources\n"
"pkg_resources.run_script(%(spec)r, %(script_name)r)\n"
) % locals()
def get_script_args(dist, executable=sys_executable, wininst=False, script_dir=None):
"""Yield write_script() argument tuples for a distribution's entrypoints"""
spec = str(dist.as_requirement())
+ requires = [spec] + [str(r) for r in dist.requires()]
header = get_script_header("", executable, wininst)
generated_by = "# generated by zetuptoolz %s" % (setuptools_version,)
script_head, script_tail = ((
"# EASY-INSTALL-ENTRY-SCRIPT: %(spec)r,%(group)r,%(name)r\n"
"%(generated_by)s\n"
- "__requires__ = %(spec)r\n"
+ "__requires__ = %(requires)r\n"
"import sys\n"
"from pkg_resources import load_entry_point\n"
"\n"