From b5235e553fbc76d0d7441af16cddc27968c681b1 Mon Sep 17 00:00:00 2001 From: Pluttodk Date: Fri, 26 Apr 2024 15:16:40 +0200 Subject: [PATCH 1/5] Create activate to also work for windows, and updated docs for azure artifacts --- docs/usage/config.md | 12 ++++++++++++ src/pdm/cli/commands/venv/activate.py | 3 +++ 2 files changed, 15 insertions(+) diff --git a/docs/usage/config.md b/docs/usage/config.md index 31bf5f504d..e7fecdbd13 100644 --- a/docs/usage/config.md +++ b/docs/usage/config.md @@ -300,6 +300,18 @@ Alternatively, if you have installed a copy of keyring globally, make sure the C export PATH=$PATH:path/to/keyring/bin ``` +### Password management with keyring for Azure Artifacts + +When trying to authenticate towards azure artifacts, this can be achieved by either using AD groups to authenticate: `pdm self add keyring artifacts-keyring` ensuring that artifacts-keyring will be used for authentication. + +And then adding the artifacts url to `pyproject.toml` + +``` +[[tool.pdm.source]] +name = "NameOfFeed" +url = "https://pkgs.dev.azure.com/[org name]/_packaging/[feed name]/pypi/simple/" +``` + ## Override the resolved package versions +++ 1.12.0 diff --git a/src/pdm/cli/commands/venv/activate.py b/src/pdm/cli/commands/venv/activate.py index d7bbb639b4..753edfa3f7 100644 --- a/src/pdm/cli/commands/venv/activate.py +++ b/src/pdm/cli/commands/venv/activate.py @@ -1,6 +1,7 @@ import argparse import shlex from pathlib import Path +import platform import shellingham @@ -55,6 +56,8 @@ def get_activate_command(self, venv: VirtualEnv) -> str: # pragma: no cover command, filename = "source", "activate" activate_script = venv.interpreter.with_name(filename) if activate_script.exists(): + if platform.system() == "Windows": + return f"{shlex.quote(str(activate_script))}" return f"{command} {shlex.quote(str(activate_script))}" # Conda backed virtualenvs don't have activate scripts return f"conda activate {shlex.quote(str(venv.root))}" From 694813e9ab580c9290aab52eef8349c618dc327b Mon Sep 17 00:00:00 2001 From: Pluttodk Date: Fri, 26 Apr 2024 15:39:01 +0200 Subject: [PATCH 2/5] Create test for the windows venv activate --- tests/cli/test_venv.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/cli/test_venv.py b/tests/cli/test_venv.py index 8b04977aa1..051c7c89ee 100644 --- a/tests/cli/test_venv.py +++ b/tests/cli/test_venv.py @@ -189,6 +189,23 @@ def test_venv_activate_no_shell(pdm, mocker, project): assert result.output.startswith("source") +@pytest.mark.usefixtures("venv_backends") +def test_venv_activate_windows(pdm, mocker, project): + project.project_config["venv.in_project"] = False + result = pdm(["venv", "create"], obj=project) + assert result.exit_code == 0, result.stderr + venv_path = re.match(r"Virtualenv (.+) is created successfully", result.output).group(1) + key = os.path.basename(venv_path)[len(get_venv_prefix(project)) :] + + mocker.patch("shellingham.detect_shell", return_value=("pwsh", None)) + mocker.patch("platform.system", return_value="Windows") + result = pdm(["venv", "activate", key], obj=project) + assert result.exit_code == 0, result.stderr + + assert result.output.strip("'\"\n").endswith("Activate.ps1") + assert not result.output.startswith(". ") + + @pytest.mark.usefixtures("fake_create") @pytest.mark.parametrize("keep_pypackages", [True, False]) def test_venv_auto_create(pdm, mocker, project, keep_pypackages): From 6eb1fdd6061ca8d7d09e07e7fd5bb532bb9ef900 Mon Sep 17 00:00:00 2001 From: Pluttodk Date: Fri, 26 Apr 2024 15:40:00 +0200 Subject: [PATCH 3/5] Added news segment --- news/2851.bugfix.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 news/2851.bugfix.md diff --git a/news/2851.bugfix.md b/news/2851.bugfix.md new file mode 100644 index 0000000000..bf5721a778 --- /dev/null +++ b/news/2851.bugfix.md @@ -0,0 +1 @@ +Fixed pdm venv activate, to also work for windows. And added documentation on how to authenticate to Azure Artifacts \ No newline at end of file From 4509a35c7594024ac4407365d0dd9167cd1e3cce Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 26 Apr 2024 13:49:23 +0000 Subject: [PATCH 4/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/pdm/cli/commands/venv/activate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pdm/cli/commands/venv/activate.py b/src/pdm/cli/commands/venv/activate.py index 753edfa3f7..c29bed1eff 100644 --- a/src/pdm/cli/commands/venv/activate.py +++ b/src/pdm/cli/commands/venv/activate.py @@ -1,7 +1,7 @@ import argparse +import platform import shlex from pathlib import Path -import platform import shellingham From f819bb598c47ab01b29246e089a82ccd9809ad83 Mon Sep 17 00:00:00 2001 From: Pluttodk Date: Fri, 26 Apr 2024 16:07:04 +0200 Subject: [PATCH 5/5] Refactored test to fit previous code --- tests/cli/test_venv.py | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/tests/cli/test_venv.py b/tests/cli/test_venv.py index 051c7c89ee..a7d3fa876c 100644 --- a/tests/cli/test_venv.py +++ b/tests/cli/test_venv.py @@ -1,4 +1,5 @@ import os +import platform import re import shutil import sys @@ -133,7 +134,10 @@ def test_venv_activate(pdm, mocker, project): assert result.output.startswith("conda activate") else: assert result.output.strip("'\"\n").endswith("activate") - assert result.output.startswith("source") + if platform.system() == "Windows": + assert not result.output.startswith("source") + else: + assert result.output.startswith("source") @pytest.mark.usefixtures("venv_backends") @@ -186,24 +190,10 @@ def test_venv_activate_no_shell(pdm, mocker, project): assert result.output.startswith("conda activate") else: assert result.output.strip("'\"\n").endswith("activate") - assert result.output.startswith("source") - - -@pytest.mark.usefixtures("venv_backends") -def test_venv_activate_windows(pdm, mocker, project): - project.project_config["venv.in_project"] = False - result = pdm(["venv", "create"], obj=project) - assert result.exit_code == 0, result.stderr - venv_path = re.match(r"Virtualenv (.+) is created successfully", result.output).group(1) - key = os.path.basename(venv_path)[len(get_venv_prefix(project)) :] - - mocker.patch("shellingham.detect_shell", return_value=("pwsh", None)) - mocker.patch("platform.system", return_value="Windows") - result = pdm(["venv", "activate", key], obj=project) - assert result.exit_code == 0, result.stderr - - assert result.output.strip("'\"\n").endswith("Activate.ps1") - assert not result.output.startswith(". ") + if platform.system() == "Windows": + assert not result.output.startswith("source") + else: + assert result.output.startswith("source") @pytest.mark.usefixtures("fake_create")