Skip to content

Commit

Permalink
poetry run: deprecate uninstalled entry points (#7606)
Browse files Browse the repository at this point in the history
  • Loading branch information
wagnerluis1982 committed Apr 5, 2023
1 parent 7585c37 commit 161b19c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/poetry/console/commands/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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")
14 changes: 14 additions & 0 deletions tests/console/commands/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 161b19c

Please sign in to comment.