diff --git a/news/3382.bugfix.md b/news/3382.bugfix.md new file mode 100644 index 0000000000..f3e8f0eee7 --- /dev/null +++ b/news/3382.bugfix.md @@ -0,0 +1 @@ +Add a dummy project name to the script environment pyproject.toml. diff --git a/src/pdm/cli/commands/run.py b/src/pdm/cli/commands/run.py index 2765f0c975..0eb2ad9a65 100644 --- a/src/pdm/cli/commands/run.py +++ b/src/pdm/cli/commands/run.py @@ -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) diff --git a/tests/test_integration.py b/tests/test_integration.py index 066a254d35..e232e080b4 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -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