Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent breakage from vcs URL in lockfile from having package name @ Part II #6303

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pipenv/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 3 additions & 7 deletions pipenv/utils/locking.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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


Expand Down
49 changes: 49 additions & 0 deletions tests/integration/test_install_vcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", {})
Loading