diff --git a/src/poetry/console/commands/run.py b/src/poetry/console/commands/run.py index 63af286d3b1..5b008a2fc53 100644 --- a/src/poetry/console/commands/run.py +++ b/src/poetry/console/commands/run.py @@ -63,6 +63,9 @@ def run_script(self, script: str | dict[str, str], args: list[str]) -> int: if script_path.exists(): args = [str(script_path), *args[1:]] break + else: + # If we reach this point, the script is not installed + self._warning_not_installed_script(args[0]) if isinstance(script, dict): script = script["callable"] @@ -81,3 +84,14 @@ def run_script(self, script: str | dict[str, str], args: list[str]) -> int: ] return self.env.execute(*cmd) + + def _warning_not_installed_script(self, script: str) -> None: + message = f"""\ +Warning: '{script}' is an entry point defined in pyproject.toml, but it's not \ +installed as a script. You may get improper `sys.argv[0]`. + +The support to run uninstalled scripts will be removed in a future release. + +Run `poetry install` to resolve and get rid of this message. +""" + self.line_error(message, style="warning") diff --git a/tests/console/commands/test_run.py b/tests/console/commands/test_run.py index 6b5bd95a728..7442ac10f37 100644 --- a/tests/console/commands/test_run.py +++ b/tests/console/commands/test_run.py @@ -180,3 +180,17 @@ def test_run_script_sys_argv0( ) argv1 = "absolute" if installed_script else "relative" assert tester.execute(f"check-argv0 {argv1}") == 0 + + if installed_script: + expected_message = "" + else: + expected_message = """\ +Warning: 'check-argv0' is an entry point defined in pyproject.toml, but it's not \ +installed as a script. You may get improper `sys.argv[0]`. + +The support to run uninstalled scripts will be removed in a future release. + +Run `poetry install` to resolve and get rid of this message. + +""" + assert tester.io.fetch_error() == expected_message