Skip to content

Commit 2ea22f3

Browse files
committed
Prevent issue with upgrading when no packages are specified to install. Prevent issue with duplicated sources being added to Pipfile.
1 parent 2383420 commit 2ea22f3

File tree

4 files changed

+27
-11
lines changed

4 files changed

+27
-11
lines changed

pipenv/project.py

+24-5
Original file line numberDiff line numberDiff line change
@@ -1273,26 +1273,45 @@ def src_name_from_url(self, index_url):
12731273
return name
12741274

12751275
def add_index_to_pipfile(self, index, verify_ssl=True):
1276-
"""Adds a given index to the Pipfile."""
1276+
"""
1277+
Adds a given index to the Pipfile if it doesn't already exist.
1278+
Returns the source name regardless of whether it was newly added or already existed.
1279+
"""
12771280
# Read and append Pipfile.
12781281
p = self.parsed_pipfile
12791282
source = None
1283+
1284+
# Try to find existing source by URL or name
12801285
try:
12811286
source = self.get_source(url=index)
12821287
except SourceNotFound:
12831288
with contextlib.suppress(SourceNotFound):
12841289
source = self.get_source(name=index)
12851290

1291+
# If we found an existing source with a name, return it
12861292
if source is not None and source.get("name"):
12871293
return source["name"]
1288-
source = {"url": index, "verify_ssl": verify_ssl}
1289-
source["name"] = self.src_name_from_url(index)
1290-
# Add the package to the group.
1294+
1295+
# Check if the URL already exists in any source
1296+
if "source" in p:
1297+
for existing_source in p["source"]:
1298+
if existing_source.get("url") == index:
1299+
return existing_source.get("name")
1300+
1301+
# If we reach here, the source doesn't exist, so create and add it
1302+
source = {
1303+
"url": index,
1304+
"verify_ssl": verify_ssl,
1305+
"name": self.src_name_from_url(index),
1306+
}
1307+
1308+
# Add the source to the group
12911309
if "source" not in p:
12921310
p["source"] = [tomlkit.item(source)]
12931311
else:
12941312
p["source"].append(tomlkit.item(source))
1295-
# Write Pipfile.
1313+
1314+
# Write Pipfile
12961315
self.write_toml(p)
12971316
return source["name"]
12981317

pipenv/routines/install.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def handle_new_packages(
109109
project.update_settings({"allow_prereleases": pre})
110110

111111
# Use the update routine for new packages
112-
if perform_upgrades:
112+
if perform_upgrades and (packages or editable_packages):
113113
try:
114114
do_update(
115115
project,

pipenv/routines/update.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -280,10 +280,7 @@ def upgrade(
280280

281281
index_name = None
282282
if index_url:
283-
if project.get_index_by_url(index_url):
284-
index_name = project.get_index_by_url(index_url)["name"]
285-
else:
286-
index_name = add_index_to_pipfile(project, index_url)
283+
index_name = add_index_to_pipfile(project, index_url)
287284

288285
if extra_pip_args:
289286
os.environ["PIPENV_EXTRA_PIP_ARGS"] = json.dumps(extra_pip_args)

tests/integration/test_install_vcs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def test_vcs_dev_package_install(pipenv_instance_pypi):
106106

107107
# Verify package appears in develop section of lockfile
108108
assert "pytest-xdist" in p.lockfile["develop"]
109-
assert p.lockfile["develop"]["pytest-xdist"]["git"] == "git+https://github.com/pytest-dev/pytest-xdist.git"
109+
assert p.lockfile["develop"]["pytest-xdist"]["git"] == "https://github.com/pytest-dev/pytest-xdist.git"
110110
assert p.lockfile["develop"]["pytest-xdist"]["ref"] == "4dd2978031eaf7017c84a1cc77667379a2b11c64"
111111

112112
# Verify the package is importable

0 commit comments

Comments
 (0)