Skip to content
Myr

:bug: Do not show an error on completion eval if the program is not installed (#83)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* :bug: Fix Fish completion script * :bug: Do not show an error on completion eval if the program is not installed * :sparkles: Add stderr redirect to /dev/null for Fish too * :white_check_mark: Update completion tests

authored by Sebastián Ramírez · committed by GitHub · parent e445bd1 · Browse files · 4 files+22 added−11 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+22 added−11 removed

  • tests:+19 added−8 removed
  • other:+3 added−3 removed

4 files+22 added−11 removed

modified:tests/test_completion/test_completion_install_source.py+5 added-3 removed
15 unmodified lines
16 "_TYPER_COMPLETE_TESTING": "True",17 },18 )19 assert (20 'eval "$(_TUTORIAL001.PY_COMPLETE=source_bash tutorial001.py)"' in result.stdout20 'eval "$(_TUTORIAL001.PY_COMPLETE=source_bash tutorial001.py 2>/dev/null)"'21 in result.stdout22 )232425def test_completion_install_source_zsh():
8 unmodified lines
34 "_TYPER_COMPLETE_TESTING": "True",35 },36 )37 assert (37 'eval "$(_TUTORIAL001.PY_COMPLETE=source_zsh tutorial001.py)"' in result.stdout38 'eval "$(_TUTORIAL001.PY_COMPLETE=source_zsh tutorial001.py 2>/dev/null)"'39 in result.stdout40 )414243def test_completion_install_source_fish():
8 unmodified lines
52 "_TYPER_COMPLETE_TESTING": "True",53 },54 )55 assert (54 "eval (env _TUTORIAL001.PY_COMPLETE=source_fish tutorial001.py)"56 "eval (env _TUTORIAL001.PY_COMPLETE=source_fish tutorial001.py 2>/dev/null)"57 in result.stdout58 )5960
49 unmodified lines
modified:tests/test_completion/test_completion_install.py+10 added-4 removed
45 unmodified lines
46 },47 )48 new_text = bash_completion_path.read_text()49 bash_completion_path.write_text(text)50 install_script = 'eval "$(_TUTORIAL001.PY_COMPLETE=source_bash tutorial001.py)'50 install_script = (51 'eval "$(_TUTORIAL001.PY_COMPLETE=source_bash tutorial001.py 2>/dev/null)'52 )53 assert install_script not in text54 assert install_script in new_text55 assert "completion installed in" in result.stdout56 assert "Completion will take effect once you restart the terminal." in result.stdout
16 unmodified lines
73 },74 )75 new_text = completion_path.read_text()76 completion_path.write_text(text)75 install_script = 'eval "$(_TUTORIAL001.PY_COMPLETE=source_zsh tutorial001.py)"'77 install_script = (78 'eval "$(_TUTORIAL001.PY_COMPLETE=source_zsh tutorial001.py 2>/dev/null)"'79 )80 assert install_script not in text81 assert install_script in new_text82 assert "completion installed in" in result.stdout83 assert "Completion will take effect once you restart the terminal." in result.stdout
17 unmodified lines
101 },102 )103 new_text = completion_path.read_text()104 completion_path.write_text(text)101 install_script = "eval (env _TUTORIAL001.PY_COMPLETE=source_fish tutorial001.py)"105 install_script = (106 "eval (env _TUTORIAL001.PY_COMPLETE=source_fish tutorial001.py 2>/dev/null)"107 )108 assert install_script not in text109 assert install_script in new_text110 assert "completion installed in" in result.stdout111 assert "Completion will take effect once you restart the terminal." in result.stdout
21 unmodified lines
133 ["pwsh"], returncode=0, stdout=completion_path_bytes134 ),135 ):136 result = runner.invoke(app, ["--install-completion"])131 install_script = "Register-ArgumentCompleter -Native -CommandName typer -ScriptBlock $scriptblock"137 install_script = "Register-ArgumentCompleter -Native -CommandName mocked-typer-testing-app -ScriptBlock $scriptblock"138 parent: Path = completion_path.parent139 parent.mkdir(parents=True, exist_ok=True)140 completion_path.write_text(install_script)141 new_text = completion_path.read_text()
5 unmodified lines
modified:tests/test_completion/test_completion.py+4 added-1 removed
37 unmodified lines
38 env={**os.environ, "SHELL": "/bin/bash", "_TYPER_COMPLETE_TESTING": "True"},39 )40 new_text = bash_completion_path.read_text()41 bash_completion_path.write_text(text)42 assert 'eval "$(_TUTORIAL001.PY_COMPLETE=source_bash tutorial001.py)' in new_text42 assert (43 'eval "$(_TUTORIAL001.PY_COMPLETE=source_bash tutorial001.py 2>/dev/null)'44 in new_text45 )46 assert "completion installed in" in result.stdout47 assert "Completion will take effect once you restart the terminal." in result.stdout4849
128 unmodified lines
modified:typer/completion.py+3 added-3 removed
219 unmodified lines
220221222def get_installable_script(prog_name: str, complete_var: str, shell: str) -> str:223 if shell == "bash":224 return f'eval "$({complete_var}=source_bash {prog_name})"'224 return f'eval "$({complete_var}=source_bash {prog_name} 2>/dev/null)"'225 elif shell == "zsh":226 return f'eval "$({complete_var}=source_zsh {prog_name})"'226 return f'eval "$({complete_var}=source_zsh {prog_name} 2>/dev/null)"'227 elif shell == "fish":228 return f"eval (env {complete_var}=source_fish {prog_name})"228 return f"eval (env {complete_var}=source_fish {prog_name} 2>/dev/null)"229 elif shell in {"powershell", "pwsh"}:230 return get_completion_script(prog_name, complete_var, shell)231 return ""232
165 unmodified lines