未验证 提交 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: ...@@ -392,6 +392,7 @@ class Synchronizer:
self.candidates = candidates self.candidates = candidates
self.environment = environment self.environment = environment
self.parallel = environment.project.config["parallel_install"] self.parallel = environment.project.config["parallel_install"]
self.all_candidates = environment.project.get_locked_candidates("__all__")
self.working_set = environment.get_working_set() self.working_set = environment.get_working_set()
@contextlib.contextmanager @contextlib.contextmanager
...@@ -425,15 +426,16 @@ class Synchronizer: ...@@ -425,15 +426,16 @@ class Synchronizer:
candidates = self.candidates.copy() candidates = self.candidates.copy()
environment = self.environment.marker_environment environment = self.environment.marker_environment
for key, dist in working_set.items(): for key, dist in working_set.items():
if key not in candidates: if key in candidates:
to_remove.append(key)
else:
can = candidates.pop(key) can = candidates.pop(key)
if can.marker and not can.marker.evaluate(environment): if can.marker and not can.marker.evaluate(environment):
to_remove.append(key) to_remove.append(key)
elif not _is_dist_editable(dist) and dist.version != can.version: elif not _is_dist_editable(dist) and dist.version != can.version:
# XXX: An editable distribution is always considered as consistent. # XXX: An editable distribution is always considered as consistent.
to_update.append(key) 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( to_add = list(
{ {
strip_extras(name)[0] strip_extras(name)[0]
......
...@@ -277,6 +277,15 @@ def test_remove_package_not_exist(project, repository, working_set): ...@@ -277,6 +277,15 @@ def test_remove_package_not_exist(project, repository, working_set):
actions.do_remove(project, sync=False, packages=["django"]) 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): def test_add_remove_no_package(project, repository):
with pytest.raises(PdmUsageError): with pytest.raises(PdmUsageError):
actions.do_add(project, packages=()) actions.do_add(project, packages=())
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册