Skip to content

Commit 8c3063d

Browse files
committed
Store requested source URL with install rather than eventual.
Fixes #329
1 parent 867d099 commit 8c3063d

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

src/manage/install_command.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,12 @@ def _find_one(cmd, source, tag, *, installed=None, by_id=False):
379379
downloader = IndexDownloader(cmd, source, Index, {}, download_cache)
380380
install = select_package(downloader, tag, cmd.default_platform, by_id=by_id)
381381

382+
# Ensure the requested source URL is in the install
383+
if install and source:
384+
if install.get("source") != source:
385+
LOGGER.verbose("Storing %s as source of package", sanitise_url(source))
386+
install = {**install, "source": source}
387+
382388
if by_id:
383389
return install
384390

tests/test_install_command.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,3 +517,33 @@ class Cmd:
517517
assert i["url"] == test_url_2
518518
assert i["data1"] == "a"
519519
assert i["data2"] == "c"
520+
521+
522+
def test_user_provided_source_retained(tmp_path, assert_log, monkeypatch):
523+
cmd = InstallCommandTestCmd(tmp_path, "1.1", force=False)
524+
525+
source1 = cmd.source
526+
source2 = "http://example.com/index-2.json"
527+
cmd.source = source2
528+
cmd.download_cache[source2] = json.dumps({
529+
"versions": [],
530+
"next": source1,
531+
})
532+
533+
def find_one(*args, _orig=IC._find_one, **kwargs):
534+
i = _orig(*args, **kwargs)
535+
assert i["source"] == cmd.source
536+
return i
537+
538+
monkeypatch.setattr(IC, "_find_one", find_one)
539+
540+
IC.execute(cmd)
541+
assert_log(
542+
assert_log.skip_until("Searching for Python matching %s", ["1.1"]),
543+
assert_log.skip_until("Fetching: %s", [source2]),
544+
assert_log.skip_until("No install found.+"),
545+
assert_log.skip_until("Fetching: %s", [source1]),
546+
assert_log.skip_until("Storing %s as source of package", [source2]),
547+
assert_log.skip_until("Installing %s", ["Test 1.1 (32)"]),
548+
("Tag: %s\\\\%s", ["Test", "1.1-32"]),
549+
)

0 commit comments

Comments
 (0)