mirror of
https://github.com/kennethreitz/pipenv.git
synced 2026-06-05 06:46:15 +00:00
Implement pipfile sorting for uninstall
using sorting directive
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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",
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user