From 80ce555a389fb553865f1d0261e31c74e8064c3c Mon Sep 17 00:00:00 2001 From: Matt Davis Date: Wed, 30 Oct 2024 22:40:43 -0400 Subject: [PATCH 1/2] Fix breakage that was almost released --- pipenv/project.py | 2 +- pipenv/utils/locking.py | 10 +++------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/pipenv/project.py b/pipenv/project.py index b169d3326..06ed15487 100644 --- a/pipenv/project.py +++ b/pipenv/project.py @@ -764,7 +764,7 @@ def lockfile(self, categories=None): for category in categories: lock_section = lockfile.get(category) if lock_section is None: - lockfile[category] = lock_section = {} + lockfile[category] = {} return lockfile diff --git a/pipenv/utils/locking.py b/pipenv/utils/locking.py index 413e2fc86..6d40bb81c 100644 --- a/pipenv/utils/locking.py +++ b/pipenv/utils/locking.py @@ -66,11 +66,8 @@ def format_requirement_for_lockfile( vcs = link.scheme.split("+", 1)[0] # Get VCS URL from original deps or normalize the link URL - if name in original_deps: - entry[vcs] = original_deps[name] - else: - vcs_url, _ = normalize_vcs_url(link.url) - entry[vcs] = vcs_url + vcs_url, _ = normalize_vcs_url(link.url) + entry[vcs] = vcs_url # Handle subdirectory information if pipfile_entry.get("subdirectory"): @@ -137,7 +134,7 @@ def get_locked_dep(project, dep, pipfile_section, current_entry=None): # initialize default values is_top_level = False - # # if the dependency has a name, find corresponding entry in pipfile + # if the dependency has a name, find corresponding entry in pipfile if isinstance(dep, dict) and dep.get("name"): dep_name = pep423_name(dep["name"]) for pipfile_key, pipfile_entry in pipfile_section.items(): @@ -183,7 +180,6 @@ def prepare_lockfile(project, results, pipfile, lockfile_section, old_lock_data= # If the current entry is a dict, merge the new details lockfile_section[dep_name].update(lockfile_entry[dep_name]) lockfile_section[dep_name] = translate_markers(lockfile_section[dep_name]) - return lockfile_section From c515552a8715e12535a5e08f9494c4e2b3db13dd Mon Sep 17 00:00:00 2001 From: Matt Davis Date: Wed, 30 Oct 2024 23:00:34 -0400 Subject: [PATCH 2/2] Add test of the kind of breakage experienced --- tests/integration/test_install_vcs.py | 49 +++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/tests/integration/test_install_vcs.py b/tests/integration/test_install_vcs.py index f1ddf7487..93272eb4f 100644 --- a/tests/integration/test_install_vcs.py +++ b/tests/integration/test_install_vcs.py @@ -71,3 +71,52 @@ def test_install_vcs_ref_by_commit_hash(pipenv_instance_private_pypi): ) assert "six" in p.pipfile["packages"] assert "six" in p.lockfile["default"] + + +@pytest.mark.vcs +@pytest.mark.dev +@pytest.mark.install +def test_vcs_dev_package_install(pipenv_instance_pypi): + """Ensure VCS packages can be properly installed into dev-packages via --dev flag with existing Pipfile.""" + with pipenv_instance_pypi() as p: + # Create a Pipfile with some existing packages + with open(p.pipfile_path, "w") as f: + contents = """ +[[source]] +url = "https://pypi.org/simple" +verify_ssl = true +name = "pypi" + +[packages] +six = "*" + +[dev-packages] +pytest-xdist = {git = "https://github.com/pytest-dev/pytest-xdist.git", ref = "v3.6.1"} + """.strip() + f.write(contents) + + # Install a VCS package with --dev flag + c = p.pipenv("install --dev -v") + assert c.returncode == 0 + + # Verify package appears in dev-packages in Pipfile + assert "pytest-xdist" in p.pipfile["dev-packages"] + assert p.pipfile["dev-packages"]["pytest-xdist"]["git"] == "https://github.com/pytest-dev/pytest-xdist.git" + assert p.pipfile["dev-packages"]["pytest-xdist"]["ref"] == "v3.6.1" + + # Verify package appears in develop section of lockfile + assert "pytest-xdist" in p.lockfile["develop"] + assert p.lockfile["develop"]["pytest-xdist"]["git"] == "git+https://github.com/pytest-dev/pytest-xdist.git" + assert p.lockfile["develop"]["pytest-xdist"]["ref"] == "4dd2978031eaf7017c84a1cc77667379a2b11c64" + + # Verify the package is importable + c = p.pipenv('run python -c "import xdist"') + assert c.returncode == 0 + + # Test that dependencies were also installed correctly + c = p.pipenv('run python -c "import execnet"') # pytest-xdist depends on execnet + assert c.returncode == 0 + + # Verify no duplicate entries in default packages + assert "pytest-xdist" not in p.pipfile.get("packages", {}) + assert "pytest-xdist" not in p.lockfile.get("default", {})