Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/3842.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Don't crash with an `IndexError` when listing scripts and one of them is blank. A blank script is now listed as `<BLANK_SCRIPT>`.
6 changes: 5 additions & 1 deletion src/pdm/cli/commands/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,11 @@ def short_description(self) -> str:
fallback = f" {termui.Emoji.ARROW_SEPARATOR} ".join(self.args)
else:
lines = [line.strip() for line in str(self.args).splitlines() if line.strip()]
fallback = f"{lines[0]}{termui.Emoji.ELLIPSIS}" if len(lines) > 1 else lines[0]
if not lines:
# a blank script leaves no lines at all; mark it rather than showing an empty cell
fallback = "<BLANK_SCRIPT>"
else:
fallback = f"{lines[0]}{termui.Emoji.ELLIPSIS}" if len(lines) > 1 else lines[0]
return self.options.get("help", fallback)


Expand Down
12 changes: 12 additions & 0 deletions tests/cli/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,18 @@ def test_run_show_list_of_scripts(project, pdm):
assert result_lines[4][1:-1].strip() == "test_shell │ shell │ shell command"


def test_run_show_list_of_scripts_with_blank_script(project, pdm):
project.pyproject.settings["scripts"] = {
"test_blank": " ",
"test_cmd": "flask db upgrade",
}
project.pyproject.write()
result = pdm(["run", "--list"], obj=project)
result_lines = result.output.splitlines()[3:]
assert result_lines[0][1:-1].strip() == "test_blank │ cmd │ <BLANK_SCRIPT>"
assert result_lines[1][1:-1].strip() == "test_cmd │ cmd │ flask db upgrade"


def test_run_show_list_of_scripts_hide_internals(project, pdm):
project.pyproject.settings["scripts"] = {
"public": "true",
Expand Down
Loading