未验证 提交 965d3a93 编写于 作者: F Frost Ming 提交者: GitHub

Merge pull request #93 from frostming/bugfix/92

only remove if it isn't required by any
Fix an issue of remove command that will unexpectedly uninstall packages in default section.
......@@ -392,6 +392,7 @@ class Synchronizer:
self.candidates = candidates
self.environment = environment
self.parallel = environment.project.config["parallel_install"]
self.all_candidates = environment.project.get_locked_candidates("__all__")
self.working_set = environment.get_working_set()
@contextlib.contextmanager
......@@ -425,15 +426,16 @@ class Synchronizer:
candidates = self.candidates.copy()
environment = self.environment.marker_environment
for key, dist in working_set.items():
if key not in candidates:
to_remove.append(key)
else:
if key in candidates:
can = candidates.pop(key)
if can.marker and not can.marker.evaluate(environment):
to_remove.append(key)
elif not _is_dist_editable(dist) and dist.version != can.version:
# XXX: An editable distribution is always considered as consistent.
to_update.append(key)
elif key not in self.all_candidates:
# Remove package only if it is not required by any section
to_remove.append(key)
to_add = list(
{
strip_extras(name)[0]
......
......@@ -277,6 +277,15 @@ def test_remove_package_not_exist(project, repository, working_set):
actions.do_remove(project, sync=False, packages=["django"])
def test_remove_package_exist_in_multi_section(project, repository, working_set):
actions.do_add(project, packages=["requests"])
actions.do_add(project, dev=True, packages=["urllib3"])
actions.do_remove(project, dev=True, packages=["urllib3"])
assert "urllib3" not in project.tool_settings["dev-dependencies"]
assert "urllib3" in working_set
assert "requests" in working_set
def test_add_remove_no_package(project, repository):
with pytest.raises(PdmUsageError):
actions.do_add(project, packages=())
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册