diff --git a/pipenv/project.py b/pipenv/project.py index b96487c1..cb34f689 100644 --- a/pipenv/project.py +++ b/pipenv/project.py @@ -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) diff --git a/tests/integration/test_install_basic.py b/tests/integration/test_install_basic.py index 02d5b855..bf4d2f13 100644 --- a/tests/integration/test_install_basic.py +++ b/tests/integration/test_install_basic.py @@ -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"] +