Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
matteius committed Oct 30, 2024
1 parent 4da8862 commit 3be159f
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 20 deletions.
44 changes: 24 additions & 20 deletions pipenv/routines/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ def get_modified_pipfile_entries(project, pipfile_categories):
Returns a dict mapping categories to sets of modified package names.
"""
modified = defaultdict(set)

lockfile = project.lockfile()

for pipfile_category in pipfile_categories:
Expand All @@ -191,38 +190,43 @@ def get_modified_pipfile_entries(project, pipfile_categories):
locked_packages = lockfile.get(lockfile_category, {})

for package_name, pipfile_entry in pipfile_packages.items():
# Check if package exists in lockfile
if package_name not in locked_packages:
modified[lockfile_category].add(package_name)
continue

locked_entry = locked_packages.get(package_name)
if not locked_entry:
modified[lockfile_category].add(package_name)
continue

# Compare version specs
pipfile_version = (
str(pipfile_entry)
if isinstance(pipfile_entry, str)
else pipfile_entry.get("version")
)
if locked_entry:
locked_version = locked_entry.get("version", "")
# We might want to eventually improve this check to consider full constraints but for now ...
if pipfile_version == locked_version:
continue
modified[lockfile_category].add(package_name)
else: # Hasn't been added to lock yet
modified[lockfile_category].add(package_name)
if locked_version := locked_entry.get("version", ""):
if pipfile_version != locked_version:
modified[lockfile_category].add(package_name)

# Handle VCS/path dependencies
vcs_keys = ["ref", "subdirectory"]
vcs_keys.extend(VCS_LIST)
has_vcs_changed = any(
pipfile_entry.get(key) != locked_entry.get(key)
for key in vcs_keys
if isinstance(pipfile_entry, dict) and key in pipfile_entry
)
# Compare extras
if isinstance(pipfile_entry, dict) and "extras" in pipfile_entry:
pipfile_extras = set(pipfile_entry["extras"])
locked_extras = set(locked_entry.get("extras", []))
if pipfile_extras != locked_extras:
modified[lockfile_category].add(package_name)

if has_vcs_changed:
modified[lockfile_category].add(package_name)
# Handle VCS/path dependencies
if isinstance(pipfile_entry, dict):
vcs_keys = ["ref", "subdirectory"]
vcs_keys.extend(VCS_LIST)
has_vcs_changed = any(
pipfile_entry.get(key) != locked_entry.get(key)
for key in vcs_keys
if key in pipfile_entry
)
if has_vcs_changed:
modified[lockfile_category].add(package_name)

return modified

Expand Down
58 changes: 58 additions & 0 deletions tests/integration/test_install_twists.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,64 @@ def test_local_extras_install(pipenv_instance_pypi):
assert "six" in p.lockfile["default"]


@pytest.mark.extras
@pytest.mark.install
@pytest.mark.local
def test_local_extras_install_alternate(pipenv_instance_pypi):
"""Ensure local package with extras installs correctly using pyproject.toml."""
with pipenv_instance_pypi() as p:
# Create pyproject.toml
pyproject_toml = os.path.join(p.path, "pyproject.toml")
with open(pyproject_toml, "w") as fh:
contents = """
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[project]
name = "testpipenv"
version = "0.1"
description = "Pipenv Test Package"
authors = [{name = "Pipenv Test", email = "[email protected]"}]
requires-python = ">=3.8"
[project.optional-dependencies]
dev = ["six"]
""".strip()
fh.write(contents)

# Create basic package structure
pkg_dir = os.path.join(p.path, "testpipenv")
os.makedirs(pkg_dir)
with open(os.path.join(pkg_dir, "__init__.py"), "w") as fh:
fh.write("")

# Test with both Pipfile syntax and direct install
for install_method in ["pipfile", "direct"]:
if install_method == "pipfile":
with open(os.path.join(p.path, "Pipfile"), "w") as fh:
fh.write("""
[packages]
testpipenv = {path = ".", editable = true, extras = ["dev"]}
[dev-packages]
""".strip())
c = p.pipenv("install")
else:
p.lockfile_path.unlink()
c = p.pipenv("install -e .[dev]")

assert c.returncode == 0
assert "testpipenv" in p.lockfile["default"]
assert p.lockfile["default"]["testpipenv"]["extras"] == ["dev"]
assert "six" in p.lockfile["default"]

if install_method == "pipfile":
assert p.pipfile["packages"]["testpipenv"]["extras"] == ["dev"]

c = p.pipenv("uninstall --all")
assert c.returncode == 0

@pytest.mark.local
@pytest.mark.install
@pytest.mark.needs_internet
Expand Down

0 comments on commit 3be159f

Please sign in to comment.