Skip to content

Commit 03860a5

Browse files
authored
Merge branch 'master' into feature/rich_expand
2 parents b97e79e + 46f4a0f commit 03860a5

File tree

7 files changed

+62
-3
lines changed

7 files changed

+62
-3
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ repos:
1414
- id: end-of-file-fixer
1515
- id: trailing-whitespace
1616
- repo: https://github.com/astral-sh/ruff-pre-commit
17-
rev: v0.11.0
17+
rev: v0.11.2
1818
hooks:
1919
- id: ruff
2020
args:

docs/release-notes.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44

55
### Fixes
66

7+
* 🐛 Ensure that autocompletion works for `Path` arguments/options. PR [#1138](https://github.com/fastapi/typer/pull/1138) by [@svlandeg](https://github.com/svlandeg).
78
* 🐛 Fix newline after header in help text, and add more tests for the behaviour of `rich_markup_mode` . PR [#964](https://github.com/fastapi/typer/pull/964) by [@svlandeg](https://github.com/svlandeg).
89

910
### Internal
1011

12+
* ⬆ Bump ruff from 0.11.1 to 0.11.2. PR [#1186](https://github.com/fastapi/typer/pull/1186) by [@dependabot[bot]](https://github.com/apps/dependabot).
13+
*[pre-commit.ci] pre-commit autoupdate. PR [#1187](https://github.com/fastapi/typer/pull/1187) by [@pre-commit-ci[bot]](https://github.com/apps/pre-commit-ci).
1114
* ⬆ Bump ruff from 0.11.0 to 0.11.1. PR [#1185](https://github.com/fastapi/typer/pull/1185) by [@dependabot[bot]](https://github.com/apps/dependabot).
1215
* ⬆ Bump ruff from 0.9.10 to 0.11.0. PR [#1180](https://github.com/fastapi/typer/pull/1180) by [@dependabot[bot]](https://github.com/apps/dependabot).
1316
*[pre-commit.ci] pre-commit autoupdate. PR [#1181](https://github.com/fastapi/typer/pull/1181) by [@pre-commit-ci[bot]](https://github.com/apps/pre-commit-ci).

requirements-tests.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ coverage[toml] >=6.2,<8.0
66
pytest-xdist >=1.32.0,<4.0.0
77
pytest-sugar >=0.9.4,<1.1.0
88
mypy ==1.4.1
9-
ruff ==0.11.1
9+
ruff ==0.11.2
1010
# Needed explicitly by typer-slim
1111
rich >=10.11.0
1212
shellingham >=1.3.0
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from pathlib import Path
2+
3+
import typer
4+
5+
app = typer.Typer()
6+
7+
8+
@app.command()
9+
def f(p: Path):
10+
print(p)
11+
12+
13+
if __name__ == "__main__":
14+
app()
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import os
2+
import subprocess
3+
import sys
4+
5+
from . import path_example as mod
6+
7+
8+
def test_script():
9+
result = subprocess.run(
10+
[sys.executable, "-m", "coverage", "run", mod.__file__, "path/to/deadpool"],
11+
capture_output=True,
12+
encoding="utf-8",
13+
)
14+
assert result.returncode == 0
15+
assert "deadpool" in result.stdout
16+
17+
18+
def test_completion_path_bash():
19+
result = subprocess.run(
20+
[sys.executable, "-m", "coverage", "run", mod.__file__, " "],
21+
capture_output=True,
22+
encoding="utf-8",
23+
env={
24+
**os.environ,
25+
"_PATH_EXAMPLE.PY_COMPLETE": "complete_bash",
26+
"COMP_WORDS": "path_example.py ",
27+
"COMP_CWORD": "2",
28+
},
29+
)
30+
assert result.returncode == 0

typer/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
ParamMeta,
4545
Required,
4646
TyperInfo,
47+
TyperPath,
4748
)
4849
from .utils import get_params_from_function
4950

@@ -753,7 +754,7 @@ def get_click_type(
753754
or parameter_info.path_type
754755
or parameter_info.resolve_path
755756
):
756-
return click.Path(
757+
return TyperPath(
757758
exists=parameter_info.exists,
758759
file_okay=parameter_info.file_okay,
759760
dir_okay=parameter_info.dir_okay,

typer/models.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,3 +531,14 @@ def __init__(
531531
self.pretty_exceptions_enable = pretty_exceptions_enable
532532
self.pretty_exceptions_show_locals = pretty_exceptions_show_locals
533533
self.pretty_exceptions_short = pretty_exceptions_short
534+
535+
536+
class TyperPath(click.Path):
537+
# Overwrite Click's behaviour to be compatible with Typer's autocompletion system
538+
def shell_complete(
539+
self, ctx: click.Context, param: click.Parameter, incomplete: str
540+
) -> List[click.shell_completion.CompletionItem]:
541+
"""Return an empty list so that the autocompletion functionality
542+
will work properly from the commandline.
543+
"""
544+
return []

0 commit comments

Comments
 (0)