Commit b1c62065 authored by Jason R. Coombs's avatar Jason R. Coombs Committed by GitHub

Merge pull request #1905 from mimi1vx/patch-1

Fix _imp module behaviour if is defined paths in find_spec call
parents c9fb0772 6b2490cd
Fixed test failure introduced in 41.6.0 when the 'tests' directory is not present.
...@@ -17,9 +17,18 @@ C_BUILTIN = 6 ...@@ -17,9 +17,18 @@ C_BUILTIN = 6
PY_FROZEN = 7 PY_FROZEN = 7
def find_spec(module, paths):
finder = (
importlib.machinery.PathFinder().find_spec
if isinstance(paths, list) else
importlib.util.find_spec
)
return finder(module, paths)
def find_module(module, paths=None): def find_module(module, paths=None):
"""Just like 'imp.find_module()', but with package support""" """Just like 'imp.find_module()', but with package support"""
spec = importlib.util.find_spec(module, paths) spec = find_spec(module, paths)
if spec is None: if spec is None:
raise ImportError("Can't find %s" % module) raise ImportError("Can't find %s" % module)
if not spec.has_location and hasattr(spec, 'submodule_search_locations'): if not spec.has_location and hasattr(spec, 'submodule_search_locations'):
...@@ -60,14 +69,14 @@ def find_module(module, paths=None): ...@@ -60,14 +69,14 @@ def find_module(module, paths=None):
def get_frozen_object(module, paths=None): def get_frozen_object(module, paths=None):
spec = importlib.util.find_spec(module, paths) spec = find_spec(module, paths)
if not spec: if not spec:
raise ImportError("Can't find %s" % module) raise ImportError("Can't find %s" % module)
return spec.loader.get_code(module) return spec.loader.get_code(module)
def get_module(module, paths, info): def get_module(module, paths, info):
spec = importlib.util.find_spec(module, paths) spec = find_spec(module, paths)
if not spec: if not spec:
raise ImportError("Can't find %s" % module) raise ImportError("Can't find %s" % module)
return module_from_spec(spec) return module_from_spec(spec)
...@@ -108,6 +108,11 @@ class TestDepends: ...@@ -108,6 +108,11 @@ class TestDepends:
assert not req.is_present() assert not req.is_present()
assert not req.is_current() assert not req.is_current()
@needs_bytecode
def test_require_present(self):
# In #1896, this test was failing for months with the only
# complaint coming from test runners (not end users).
# TODO: Evaluate if this code is needed at all.
req = Require('Tests', None, 'tests', homepage="http://example.com") req = Require('Tests', None, 'tests', homepage="http://example.com")
assert req.format is None assert req.format is None
assert req.attribute is None assert req.attribute is None
......
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