Implement pipfile sorting for uninstall

using sorting directive
This commit is contained in:
Dave Schaefer
2023-10-08 09:51:40 -06:00
parent 9bc4ffa506
commit 7b33b04374
2 changed files with 53 additions and 0 deletions
+2
View File
@@ -1117,6 +1117,8 @@ class Project:
p = self.parsed_pipfile
if name:
del p[category][name]
if self.settings.get("sort_pipfile"):
p[category] = dict(sorted(p[category].items()))
self.write_toml(p)
return True
return False
+51
View File
@@ -243,3 +243,54 @@ def test_uninstall_multiple_categories(pipenv_instance_private_pypi):
assert "six" not in p.lockfile.get("prereq", {})
assert "six" not in p.lockfile["default"]
@pytest.mark.uninstall
def test_category_sorted_alphabetically_with_directive(pipenv_instance_private_pypi):
with pipenv_instance_private_pypi() as p:
with open(p.pipfile_path, "w") as f:
contents = """
[pipenv]
sort_pipfile = true
[packages]
parse = "*"
colorama = "*"
build = "*"
atomicwrites = "*"
""".strip()
f.write(contents)
c = p.pipenv("install")
assert c.returncode == 0
c = p.pipenv("uninstall build")
assert c.returncode == 0
assert "build" not in p.pipfile["packages"]
assert list(p.pipfile["packages"].keys()) == ["atomicwrites", "colorama", "parse"]
@pytest.mark.uninstall
def test_category_not_sorted_without_directive(pipenv_instance_private_pypi):
with pipenv_instance_private_pypi() as p:
with open(p.pipfile_path, "w") as f:
contents = """
[packages]
parse = "*"
colorama = "*"
build = "*"
atomicwrites = "*"
""".strip()
f.write(contents)
c = p.pipenv("install")
assert c.returncode == 0
c = p.pipenv("uninstall build")
assert c.returncode == 0
assert "build" not in p.pipfile["packages"]
assert list(p.pipfile["packages"].keys()) == [
"parse",
"colorama",
"atomicwrites",
]