inducer / pudb

Full-screen console debugger for Python
https://documen.tician.de/pudb/
Other
2.97k stars 229 forks source link

Support more shells by shtab #546

Closed Freed-Wu closed 2 years ago

Freed-Wu commented 2 years ago

Support more shells by shtab

The disadvantage is importing a new dependency. However, shtab can support more shells (bash/zsh/tcsh, and fish/posh in plan), and it can provide an option --print-completion for user and packager to generate shell completion and for developer to test, so I think it may be acceptable.

❯ pudb3 --print-completion bash|sudo tee /usr/share/bash-completion/completions/pudb3
❯ pudb3 --print-completion zsh|sudo tee /usr/share/zsh/site-functions/_pudb3
❯ pudb3 --print-completion tcsh|sudo tee /etc/profile.d/pudb3.completion.csh

I have tested bash/zsh can work. (I don't have installed tcsh)

BTW, shtab has a bug for zsh, that is pudb3 has script_args which nargs is argparse.REMINDER, but shtab cannot support. I temporarily fix it in my fork and send a PR to shtab.

This is a version after fixing. You can put it directed to the correct directory.

❯ pudb3 --print-completion zsh
#compdef pudb3

# AUTOMATCALLY GENERATED by `shtab`

_shtab_pudb3_commands() {
  local _commands=(

  )
  _describe 'pudb3 commands' _commands
}

_shtab_pudb3_options=(
  "(- : *)"{-h,--help}"[show this help message and exit]"
  "(- : *)--print-completion[print shell completion script]:print_completion:(bash zsh tcsh)"
  {-s,--steal-output}"[]"
  {-m,--module}"[Debug as module or package instead of as a script]"
  {-le,--log-errors}"[Log internal errors to the given file]:log_errors:_files"
  "--pre-run[Run command before each program run]:pre_run:_command_names -e"
  "(- : *)--version[show program\'s version number and exit]"
  "(-)*:Arguments to pass to script or module:_script_args"
)

_shtab_pudb3() {
  local context state line curcontext="$curcontext"

  local one_or_more='(-)*'
  local reminder='(*)'
  if ((${_shtab_you_get_options[(I)${(q)one_or_more}*]} + ${_shtab_you_get_options[(I)${(q)reminder}*]} == 0)); then  # noqa: E501
    _shtab_pudb3_options+=(': :_shtab_pudb3_commands' '*::: :->pudb3')
  fi
  _arguments -C $_shtab_pudb3_options

  case $state in
    pudb3)
      words=($line[1] "${words[@]}")
      (( CURRENT += 1 ))
      curcontext="${curcontext%:*:*}:_shtab_pudb3-$line[1]:"
      case $line[1] in

      esac
  esac
}

# Custom Preamble
_script_args() {
  _arguments -S -s '(-)1:script_args:_files -g *.py' '*: :_files'
}

# End Custom Preamble

typeset -A opt_args
_shtab_pudb3 "$@"

Result:

❯ pudb3 <TAB>  # complete *.py and dirs, because pudb3 must run a py file
script_args
debug_me.py     doc/            examples/       manual-tests/   pudb/           pudb.egg-info/  test/
❯ pudb3 pudb/debug_me.py <TAB>  # complete all files, because we don't know pudb/debug_me.py's command line usage
file
debug_me.py           examples/             MANIFEST.in           pudb/                 README.rst            setup.cfg             test/
doc/                  LICENSE               manual-tests/         pudb.egg-info/        requirements.dev.txt  setup.py              try-the-debugger.sh*

The test failed. However, I haven't change pudb/var_view.py. What happened?

./pudb/var_view.py:50:1: B024 PudbCollection is an abstract base class, but it has no abstract methods. Remember to use @abstractmethod, @abstractclassmethod and/or @abstractproperty decorators.
./pudb/var_view.py:83:1: B024 PudbSequence is an abstract base class, but it has no abstract methods. Remember to use @abstractmethod, @abstractclassmethod and/or @abstractproperty decorators.
./pudb/var_view.py:116:1: B024 PudbMapping is an abstract base class, but it has no abstract methods. Remember to use @abstractmethod, @abstractclassmethod and/or @abstractproperty decorators.
inducer commented 2 years ago

It looks like much of the diff here consists of spurious white space changes from code reformatting, making it harder to review than necessary. Please refrain from making such changes, and undo the ones you've made. Thanks!

inducer commented 2 years ago

Also, see the linter failures here.

Freed-Wu commented 2 years ago

OK. All checks have passed.

inducer commented 2 years ago

This is nice. Thanks!