Sort packages alphabetically inside each category

When installing any package, sort all package names alphabetically inside the category, for easier reading.

Unsure if this is the best place or way to implement.
Small prototype to add to discussion in https://github.com/pypa/pipenv/issues/5964

Tests:

before patch:

```
AssertionError: assert ['atomicwrite...ama', 'build'] == ['atomicwrite...', 'colorama']
  At index 1 diff: 'colorama' != 'build'
  Full diff:
  - ['atomicwrites', 'build', 'colorama']
  ?                  ---------
  + ['atomicwrites', 'colorama', 'build']
  ?                            +++++++++
```

after patch: pass.
This commit is contained in:
Dave Schaefer
2023-10-04 21:35:16 -06:00
parent e45cc7a9ab
commit e87e2ceb05
2 changed files with 18 additions and 0 deletions
+1
View File
@@ -1226,6 +1226,7 @@ class Project:
newly_added = True
p[category][normalized_name] = entry
p[category] = dict(sorted(p[category].items()))
# Write Pipfile.
self.write_toml(p)
+17
View File
@@ -556,3 +556,20 @@ dataclasses-json = {file = "https://files.pythonhosted.org/packages/85/94/1b3021
assert c.returncode == 0
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):
with pipenv_instance_private_pypi() as p:
with open(p.pipfile_path, "w") as f:
contents = """
[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"]