Added new Pipenv option sort_alphabetical

Sort packages alphabetically inside each category.
Currently runs on `install`.
This commit is contained in:
Dave Schaefer
2023-10-07 11:01:53 -06:00
parent e87e2ceb05
commit 8e189035a3
2 changed files with 30 additions and 4 deletions
+3 -1
View File
@@ -1226,7 +1226,9 @@ class Project:
newly_added = True
p[category][normalized_name] = entry
p[category] = dict(sorted(p[category].items()))
if self.settings.get("sort_alphabetical"):
p[category] = dict(sorted(p[category].items()))
# Write Pipfile.
self.write_toml(p)
+27 -3
View File
@@ -557,9 +557,30 @@ dataclasses-json = {file = "https://files.pythonhosted.org/packages/85/94/1b3021
c = p.pipenv("""run python -c "from dataclasses_json import dataclass_json" """)
assert c.returncode == 0
@pytest.mark.basic
@pytest.mark.install
def test_packages_sorted_alphabetically_in_category(pipenv_instance_private_pypi):
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_alphabetical = true
[packages]
atomicwrites = "*"
colorama = "*"
""".strip()
f.write(contents)
c = p.pipenv("install build")
assert c.returncode == 0
assert "build" in p.pipfile["packages"]
assert list(p.pipfile["packages"].keys()) == ["atomicwrites", "build", "colorama"]
@pytest.mark.basic
@pytest.mark.install
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 = """
@@ -571,5 +592,8 @@ colorama = "*"
c = p.pipenv("install build")
assert c.returncode == 0
assert "build" in p.pipfile["packages"]
assert list(p.pipfile["packages"].keys()) == ["atomicwrites", "build", "colorama"]
assert list(p.pipfile["packages"].keys()) == [
"atomicwrites",
"colorama",
"build",
]