Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: pdm export does not backfill source url for PyPI
Browse files Browse the repository at this point in the history
Fixes #3094

Signed-off-by: Frost Ming <[email protected]>
frostming committed Aug 13, 2024
1 parent fbaa7c1 commit 1166b1b
Showing 2 changed files with 11 additions and 7 deletions.
1 change: 1 addition & 0 deletions news/3094.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Backfill urls from configured indexed when exporting to requirements.txt.
17 changes: 10 additions & 7 deletions src/pdm/formats/requirements.py
Original file line number Diff line number Diff line change
@@ -227,20 +227,23 @@ def export(
elif options.editable_self:
lines.append("-e . # this package\n")

sources = project.pyproject.settings.get("source", [])
for source in sources:
url = source["url"]
project_sources = [s["name"] for s in project.pyproject.settings.get("source", [])]

for source in project.sources:
if source.name not in project_sources:
continue
assert source.url
if options.expandvars:
url = expand_env_vars_in_auth(url)
source_type = source.get("type", "index")
url = expand_env_vars_in_auth(source.url)
source_type = source.type or "index"
if source_type == "index":
prefix = "--index-url" if source["name"] == "pypi" else "--extra-index-url"
prefix = "--index-url" if source.name == "pypi" else "--extra-index-url"
elif source_type == "find_links":
prefix = "--find-links"
else:
raise ValueError(f"Unknown source type: {source_type}")
lines.append(f"{prefix} {url}\n")
if not source.get("verify_ssl", True):
if source.verify_ssl is not False:
host = urllib.parse.urlparse(url).hostname
lines.append(f"--trusted-host {host}\n")
return "".join(lines)

0 comments on commit 1166b1b

Please sign in to comment.