Skip to content

Commit

Permalink
fix: pdm export support env variables in credentials
Browse files Browse the repository at this point in the history
Fixes #1939

Signed-off-by: Frost Ming <[email protected]>
  • Loading branch information
frostming committed May 22, 2023
1 parent 37886fb commit f161a14
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
1 change: 1 addition & 0 deletions news/1939.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Keep the variables in the URL credentials when exporting.
3 changes: 1 addition & 2 deletions src/pdm/formats/requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

from pdm.formats.base import make_array
from pdm.models.requirements import Requirement, parse_requirement
from pdm.utils import expand_env_vars_in_auth

if TYPE_CHECKING:
from argparse import Namespace
Expand Down Expand Up @@ -191,7 +190,7 @@ def export(
lines.append("\n")
sources = project.pyproject.settings.get("source", [])
for source in sources:
url = expand_env_vars_in_auth(source["url"])
url = source["url"]
prefix = "--index-url" if source["name"] == "pypi" else "--extra-index-url"
lines.append(f"{prefix} {url}\n")
if not source.get("verify_ssl", True):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,12 @@ def test_import_requirements_with_group(project):
assert not result.get("dependencies")


def test_export_expand_env_vars_in_source(project, monkeypatch):
def test_keep_env_vars_in_source(project, monkeypatch):
monkeypatch.setenv("USER", "foo")
monkeypatch.setenv("PASSWORD", "bar")
project.pyproject.settings["source"] = [{"url": "https://${USER}:${PASSWORD}@test.pypi.org/simple", "name": "pypi"}]
result = requirements.export(project, [], Namespace())
assert result.strip().splitlines()[-1] == "--index-url https://foo:bar@test.pypi.org/simple"
assert result.strip().splitlines()[-1] == "--index-url https://${USER}:${PASSWORD}@test.pypi.org/simple"


def test_export_replace_project_root(project):
Expand Down

0 comments on commit f161a14

Please sign in to comment.