Skip to content

Commit 3be159f

Browse files
committed
fix tests
1 parent 4da8862 commit 3be159f

File tree

2 files changed

+82
-20
lines changed

2 files changed

+82
-20
lines changed

pipenv/routines/update.py

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ def get_modified_pipfile_entries(project, pipfile_categories):
182182
Returns a dict mapping categories to sets of modified package names.
183183
"""
184184
modified = defaultdict(set)
185-
186185
lockfile = project.lockfile()
187186

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

193192
for package_name, pipfile_entry in pipfile_packages.items():
194-
# Check if package exists in lockfile
195193
if package_name not in locked_packages:
196194
modified[lockfile_category].add(package_name)
197195
continue
198196

199197
locked_entry = locked_packages.get(package_name)
198+
if not locked_entry:
199+
modified[lockfile_category].add(package_name)
200+
continue
201+
200202
# Compare version specs
201203
pipfile_version = (
202204
str(pipfile_entry)
203205
if isinstance(pipfile_entry, str)
204206
else pipfile_entry.get("version")
205207
)
206-
if locked_entry:
207-
locked_version = locked_entry.get("version", "")
208-
# We might want to eventually improve this check to consider full constraints but for now ...
209-
if pipfile_version == locked_version:
210-
continue
211-
modified[lockfile_category].add(package_name)
212-
else: # Hasn't been added to lock yet
213-
modified[lockfile_category].add(package_name)
208+
if locked_version := locked_entry.get("version", ""):
209+
if pipfile_version != locked_version:
210+
modified[lockfile_category].add(package_name)
214211

215-
# Handle VCS/path dependencies
216-
vcs_keys = ["ref", "subdirectory"]
217-
vcs_keys.extend(VCS_LIST)
218-
has_vcs_changed = any(
219-
pipfile_entry.get(key) != locked_entry.get(key)
220-
for key in vcs_keys
221-
if isinstance(pipfile_entry, dict) and key in pipfile_entry
222-
)
212+
# Compare extras
213+
if isinstance(pipfile_entry, dict) and "extras" in pipfile_entry:
214+
pipfile_extras = set(pipfile_entry["extras"])
215+
locked_extras = set(locked_entry.get("extras", []))
216+
if pipfile_extras != locked_extras:
217+
modified[lockfile_category].add(package_name)
223218

224-
if has_vcs_changed:
225-
modified[lockfile_category].add(package_name)
219+
# Handle VCS/path dependencies
220+
if isinstance(pipfile_entry, dict):
221+
vcs_keys = ["ref", "subdirectory"]
222+
vcs_keys.extend(VCS_LIST)
223+
has_vcs_changed = any(
224+
pipfile_entry.get(key) != locked_entry.get(key)
225+
for key in vcs_keys
226+
if key in pipfile_entry
227+
)
228+
if has_vcs_changed:
229+
modified[lockfile_category].add(package_name)
226230

227231
return modified
228232

tests/integration/test_install_twists.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,64 @@ def test_local_extras_install(pipenv_instance_pypi):
8787
assert "six" in p.lockfile["default"]
8888

8989

90+
@pytest.mark.extras
91+
@pytest.mark.install
92+
@pytest.mark.local
93+
def test_local_extras_install_alternate(pipenv_instance_pypi):
94+
"""Ensure local package with extras installs correctly using pyproject.toml."""
95+
with pipenv_instance_pypi() as p:
96+
# Create pyproject.toml
97+
pyproject_toml = os.path.join(p.path, "pyproject.toml")
98+
with open(pyproject_toml, "w") as fh:
99+
contents = """
100+
[build-system]
101+
requires = ["hatchling"]
102+
build-backend = "hatchling.build"
103+
104+
[project]
105+
name = "testpipenv"
106+
version = "0.1"
107+
description = "Pipenv Test Package"
108+
authors = [{name = "Pipenv Test", email = "test@pipenv.package"}]
109+
requires-python = ">=3.8"
110+
111+
[project.optional-dependencies]
112+
dev = ["six"]
113+
""".strip()
114+
fh.write(contents)
115+
116+
# Create basic package structure
117+
pkg_dir = os.path.join(p.path, "testpipenv")
118+
os.makedirs(pkg_dir)
119+
with open(os.path.join(pkg_dir, "__init__.py"), "w") as fh:
120+
fh.write("")
121+
122+
# Test with both Pipfile syntax and direct install
123+
for install_method in ["pipfile", "direct"]:
124+
if install_method == "pipfile":
125+
with open(os.path.join(p.path, "Pipfile"), "w") as fh:
126+
fh.write("""
127+
[packages]
128+
testpipenv = {path = ".", editable = true, extras = ["dev"]}
129+
130+
[dev-packages]
131+
""".strip())
132+
c = p.pipenv("install")
133+
else:
134+
p.lockfile_path.unlink()
135+
c = p.pipenv("install -e .[dev]")
136+
137+
assert c.returncode == 0
138+
assert "testpipenv" in p.lockfile["default"]
139+
assert p.lockfile["default"]["testpipenv"]["extras"] == ["dev"]
140+
assert "six" in p.lockfile["default"]
141+
142+
if install_method == "pipfile":
143+
assert p.pipfile["packages"]["testpipenv"]["extras"] == ["dev"]
144+
145+
c = p.pipenv("uninstall --all")
146+
assert c.returncode == 0
147+
90148
@pytest.mark.local
91149
@pytest.mark.install
92150
@pytest.mark.needs_internet

0 commit comments

Comments
 (0)