Avoid RecursionError for circular_dependencies // Resolve #4228

This commit is contained in:
Ivan Kravets
2022-04-15 14:17:21 +03:00
parent 8d63591ce8
commit eaff7f307c
2 changed files with 60 additions and 1 deletions

View File

@ -76,6 +76,9 @@ class PackageManagerInstallMixin(object):
pkg = None
if pkg:
# avoid RecursionError for circular_dependencies
self._INSTALL_HISTORY[spec] = pkg
self.log.debug(
click.style(
"{name}@{version} is already installed".format(
@ -112,9 +115,12 @@ class PackageManagerInstallMixin(object):
)
self.memcache_reset()
# avoid RecursionError for circular_dependencies
self._INSTALL_HISTORY[spec] = pkg
if not skip_dependencies:
self.install_dependencies(pkg)
self._INSTALL_HISTORY[spec] = pkg
return pkg
def install_dependencies(self, pkg, print_header=True):

View File

@ -386,6 +386,59 @@ if action == "preuninstall":
(storage_dir / "preuninstall.flag").is_file()
def test_install_circular_dependencies(tmp_path: Path):
storage_dir = tmp_path / "storage"
# Foo
pkg_dir = storage_dir / "foo"
pkg_dir.mkdir(parents=True)
(pkg_dir / "library.json").write_text(
"""
{
"name": "Foo",
"version": "1.0.0",
"dependencies": {
"Bar": "*"
}
}
"""
)
# Bar
pkg_dir = storage_dir / "bar"
pkg_dir.mkdir(parents=True)
(pkg_dir / "library.json").write_text(
"""
{
"name": "Bar",
"version": "1.0.0",
"dependencies": {
"Foo": "*"
}
}
"""
)
lm = LibraryPackageManager(str(storage_dir))
lm.set_log_level(logging.ERROR)
assert len(lm.get_installed()) == 2
# root library
pkg_dir = tmp_path / "root"
pkg_dir.mkdir(parents=True)
(pkg_dir / "library.json").write_text(
"""
{
"name": "Root",
"version": "1.0.0",
"dependencies": {
"Foo": "^1.0.0",
"Bar": "^1.0.0"
}
}
"""
)
lm.install("file://%s" % str(pkg_dir))
def test_get_installed(isolated_pio_core, tmpdir_factory):
storage_dir = tmpdir_factory.mktemp("storage")
pm = ToolPackageManager(str(storage_dir))