Skip to content

completions: support generation when running as module #231

Closed

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

Activity

  1. added this to the 1.1 milestone on Sep 5, 2022
  2. modified the milestones: 2.1 , Future on Jan 22, 2023
  3. modified the milestones: Future, 2.1 on Jul 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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