Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def make_resolver(self, filename, module_name):
module = resolve.Local(filename, module_name, self.py_fs)
return resolve.Resolver(self.path, module)
def ordered_deps_list(self):
deps = []
for k, v in self.deps_list():
deps.append((k, sorted(v)))
return list(sorted(deps))
def ordered_sorted_source_files(self):
return [list(sorted(x)) for x in self.sorted_source_files()]
# Deps = { file : ([resolved deps], [broken deps], {dep_file:provenance}) }
SIMPLE_DEPS = {
"a.py": (["b.py", "c.py"], [],
{"b.py": resolve.Local("b.py", "b", "fs1"),
"c.py": resolve.Local("c.py", "c", "fs2")
}),
"b.py": (["d.py"], ["e"],
{"d.py": resolve.System("d.py", "d")})
}
SIMPLE_CYCLIC_DEPS = {
"a.py": (["b.py", "c.py"], ["e"], {}),
"b.py": (["d.py", "a.py"], ["f"], {}),
}
class TestDependencyGraph(unittest.TestCase):
"""Tests for DependencyGraph."""
def check_order(self, xs, *args):
"""Checks that args form an increasing sequence within xs."""
def ordered_deps_list(self):
deps = []
for k, v in self.deps_list():
deps.append((k, sorted(v)))
return list(sorted(deps))
def ordered_sorted_source_files(self):
return [list(sorted(x)) for x in self.sorted_source_files()]
# Deps = { file : ([resolved deps], [broken deps], {dep_file:provenance}) }
SIMPLE_DEPS = {
"a.py": (["b.py", "c.py"], [],
{"b.py": resolve.Local("b.py", "b", "fs1"),
"c.py": resolve.Local("c.py", "c", "fs2")
}),
"b.py": (["d.py"], ["e"],
{"d.py": resolve.System("d.py", "d")})
}
SIMPLE_NONPY_DEPS = {"a.pyi": (["b.py"], [], {})}
SIMPLE_CYCLIC_DEPS = {
"a.py": (["b.py", "c.py"], ["e"], {}),
"b.py": (["d.py", "a.py"], ["f"], {}),
}
SIMPLE_SYSTEM_DEPS = {
"a.py": (["b.py"], [], {"b.py": resolve.System("b.py", "b")}),
"b.py": (["c.py"], [], {"c.py": resolve.System("c.py", "c")}),
}
def ordered_deps_list(self):
deps = []
for k, v in self.deps_list():
deps.append((k, sorted(v)))
return list(sorted(deps))
def ordered_sorted_source_files(self):
return [list(sorted(x)) for x in self.sorted_source_files()]
# Deps = { file : ([resolved deps], [broken deps], {dep_file:provenance}) }
SIMPLE_DEPS = {
"a.py": (["b.py", "c.py"], [],
{"b.py": resolve.Local("b.py", "b", "fs1"),
"c.py": resolve.Local("c.py", "c", "fs2")
}),
"b.py": (["d.py"], ["e"],
{"d.py": resolve.System("d.py", "d")})
}
SIMPLE_NONPY_DEPS = {"a.pyi": (["b.py"], [], {})}
SIMPLE_CYCLIC_DEPS = {
"a.py": (["b.py", "c.py"], ["e"], {}),
"b.py": (["d.py", "a.py"], ["f"], {}),
}
SIMPLE_SYSTEM_DEPS = {
"a.py": (["b.py"], [], {"b.py": resolve.System("b.py", "b")}),
"b.py": (["c.py"], [], {"c.py": resolve.System("c.py", "c")}),
def __init__(self, path, module_name, fs):
super(Local, self).__init__(path, module_name)
self.fs = fs
for module_name, path in files:
for fs in self.fs_path:
f = self._find_file(fs, path)
if not f or f == self.current_module.path:
# We cannot import a file from itself.
continue
if item.is_relative():
package_name = self.current_module.package_name
if package_name is None:
# Relative import in non-package
raise ImportException(name)
module_name = get_absolute_name(package_name, module_name)
if isinstance(self.current_module, System):
return System(f, module_name)
return Local(f, module_name, fs)
# If the module isn't found in the explicit pythonpath, see if python
# itself resolved it.
if item.source:
prefix, ext = os.path.splitext(item.source)
mod_name = name
# We need to check for importing a symbol here too.
if short_name:
mod = prefix.replace(os.path.sep, '.')
mod = utils.strip_suffix(mod, '.__init__')
if not mod.endswith(name) and mod.endswith(short_name):
mod_name = short_name
if ext == '.pyc':
pyfile = prefix + '.py'
if os.path.exists(pyfile):