Skip to content

Commit

Permalink
fix: PDM fails running a script with PEP723 metadata with uv (#3383)
Browse files Browse the repository at this point in the history
* fix: PDM fails running a script with  PEP723 metadata with `uv`
Fixes #3382

Signed-off-by: Frost Ming <[email protected]>

* use venv

Signed-off-by: Frost Ming <[email protected]>
  • Loading branch information
frostming authored Jan 27, 2025
1 parent 9d11d30 commit f86d2cb
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions news/3382.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add a dummy project name to the script environment pyproject.toml.
2 changes: 1 addition & 1 deletion src/pdm/cli/commands/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def _get_script_env(self, script_file: str) -> BaseEnvironment:
return self.project.environment
tool_config = metadata.pop("tool", {})
script_project = self.project.core.create_project()
script_project.pyproject.set_data({"project": metadata, "tool": tool_config})
script_project.pyproject.set_data({"project": {"name": "temp-project", **metadata}, "tool": tool_config})
md5_kwargs = {"usedforsecurity": False}
venv_name = hashlib.md5(os.path.realpath(script_file).encode("utf-8"), **md5_kwargs).hexdigest()
venv_backend = BACKENDS[script_project.config["venv.backend"]](script_project, None)
Expand Down
1 change: 1 addition & 0 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def get_python_versions():
def test_basic_integration(python_version, core, tmp_path, pdm):
"""An e2e test case to ensure PDM works on all supported Python versions"""
project = core.create_project(tmp_path)
project.project_config["python.use_venv"] = True
project.pyproject.set_data(PYPROJECT)
project.root.joinpath("foo.py").write_text("import django\n")
project._environment = None
Expand Down

0 comments on commit f86d2cb

Please sign in to comment.