Commit 13f43fe5 authored by Jason R. Coombs's avatar Jason R. Coombs

Use sets to determine presence of imported modules.

parent 373ed664
...@@ -115,8 +115,8 @@ def _do_download(version, download_base, to_dir, download_delay): ...@@ -115,8 +115,8 @@ def _do_download(version, download_base, to_dir, download_delay):
def use_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL, def use_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
to_dir=os.curdir, download_delay=15): to_dir=os.curdir, download_delay=15):
to_dir = os.path.abspath(to_dir) to_dir = os.path.abspath(to_dir)
was_imported = 'pkg_resources' in sys.modules or \ rep_modules = 'pkg_resources', 'setuptools'
'setuptools' in sys.modules imported = set(sys.modules).intersection(rep_modules)
try: try:
import pkg_resources import pkg_resources
except ImportError: except ImportError:
...@@ -127,7 +127,7 @@ def use_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL, ...@@ -127,7 +127,7 @@ def use_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
except pkg_resources.DistributionNotFound: except pkg_resources.DistributionNotFound:
return _do_download(version, download_base, to_dir, download_delay) return _do_download(version, download_base, to_dir, download_delay)
except pkg_resources.VersionConflict as VC_err: except pkg_resources.VersionConflict as VC_err:
if was_imported: if imported:
msg = textwrap.dedent(""" msg = textwrap.dedent("""
The required version of setuptools (>={version}) is not available, The required version of setuptools (>={version}) is not available,
and can't be installed while this script is running. Please and can't be installed while this script is running. Please
......
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