Skip to content

Fixes to completions#355

Closed
Secrus wants to merge 2 commits intopython-poetry:mainfrom
Secrus:completions-v1
Closed

Fixes to completions#355
Secrus wants to merge 2 commits intopython-poetry:mainfrom
Secrus:completions-v1

Conversation

@Secrus
Copy link
Copy Markdown
Member

@Secrus Secrus commented Aug 20, 2023

Closes: #231

# FIXME: when generating completions via `python -m script completions`,
# we incorrectly infer `script_name` as `__main__.py`
script_name = self._io.input.script_name or inspect.stack()[-1][1]
script_name = self._io.input.script_name or self._get_prog_name_from_stack()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did this work for you? ik it works for click, but would need tweaking

what about unifying the logic from the help command, which prefers self._application.name if defined? that feels more consistent and what I would expect:

if self._application:
current_script = self._application.name
else:
current_script = inspect.stack()[-1][1]

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have only tested the _get_prog_name_from_stack method and it has returned the proper module name. Aplication.name is not always good, because you might have your program aliased on shell level (like having pipx installation with suffix).

f"# {cmd.name}",
*[
f"complete -c {script_name} -A "
f"-n '__fish_seen_subcommand_from {sanitize(command_name)}' "
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just to make sure I understand, the syntax error was already fixed here with 6cc808d right? we just haven't had a release since then

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, the fix was making '__fish_seen_subcommand_from \'command name\'' entry, while this fix changes it to being '__fish_seen_subcommand_from "command name"' which feels like a more "proper" way to nest quotes.

@Secrus
Copy link
Copy Markdown
Member Author

Secrus commented Oct 25, 2023

Superseded by #358

@Secrus Secrus closed this Oct 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

completions: support generation when running as module

2 participants