Skip to content

completions: support generation when running as module #231

@branchv

Description

@branchv

When generating completions, we use the following logic to infer the command name:

# 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_path = posixpath.realpath(script_name)
script_name = os.path.basename(script_path)

As stated, this doesn't work when running the script as a module via python -m:

$ poetry completions zsh | head -1
#compdef poetry
$ python -m poetry completions zsh | head -1
#compdef __main__.py

We should fix this

Note: I noticed this since Arch Linux has to work around it: https://github.com/archlinux/svntogit-community/blob/packages/python-poetry/trunk/poetry-completions-generator

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions