Skip to content

Commit aad20d3

Browse files
authored
Merge branch 'master' into fix/optional-param-no-default
2 parents 5e06c17 + 50b1018 commit aad20d3

11 files changed

Lines changed: 74 additions & 22 deletions

.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.12.9
17+
rev: v0.12.10
1818
hooks:
1919
- id: ruff
2020
args:

docs/release-notes.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,22 @@
22

33
## Latest Changes
44

5+
## 0.17.1
6+
7+
### Fixes
8+
9+
* 🐛 Fix markdown formatting in `--help` output. PR [#815](https://github.com/fastapi/typer/pull/815) by [@gar1t](https://github.com/gar1t).
10+
11+
## 0.17.0
12+
13+
### Features
14+
15+
* ⚡️ Lazy-load `rich_utils` to reduce startup time. PR [#1128](https://github.com/fastapi/typer/pull/1128) by [@oefe](https://github.com/oefe).
16+
517
### Internal
618

19+
* ⬆ Bump ruff from 0.12.9 to 0.12.10. PR [#1280](https://github.com/fastapi/typer/pull/1280) by [@dependabot[bot]](https://github.com/apps/dependabot).
20+
*[pre-commit.ci] pre-commit autoupdate. PR [#1281](https://github.com/fastapi/typer/pull/1281) by [@pre-commit-ci[bot]](https://github.com/apps/pre-commit-ci).
721
* ⬆ Update pytest-sugar requirement from <1.1.0,>=0.9.4 to >=0.9.4,<1.2.0. PR [#1279](https://github.com/fastapi/typer/pull/1279) by [@dependabot[bot]](https://github.com/apps/dependabot).
822

923
## 0.16.1

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.2.0
88
mypy ==1.4.1
9-
ruff ==0.12.9
9+
ruff ==0.12.10
1010
# Needed explicitly by typer-slim
1111
rich >=10.11.0
1212
shellingham >=1.3.0

tests/assets/print_modules.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import sys
2+
3+
import typer
4+
5+
app = typer.Typer()
6+
7+
8+
@app.command()
9+
def main():
10+
for m in sys.modules:
11+
print(m)
12+
13+
14+
if __name__ == "__main__":
15+
app()

tests/test_rich_import.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import subprocess
2+
import sys
3+
from pathlib import Path
4+
5+
ACCEPTED_MODULES = {"rich._extension", "rich"}
6+
7+
8+
def test_rich_not_imported_unnecessary():
9+
file_path = Path(__file__).parent / "assets/print_modules.py"
10+
result = subprocess.run(
11+
[sys.executable, "-m", "coverage", "run", str(file_path)],
12+
capture_output=True,
13+
encoding="utf-8",
14+
)
15+
modules = result.stdout.splitlines()
16+
modules = [
17+
module
18+
for module in modules
19+
if module not in ACCEPTED_MODULES and module.startswith("rich")
20+
]
21+
assert not modules

tests/test_rich_markup_mode.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ def main(arg: str):
4949
pytest.param(
5050
"markdown",
5151
["First line", "", "Line 1", "", "Line 2", "", "Line 3", ""],
52-
marks=pytest.mark.xfail,
5352
),
5453
pytest.param(
5554
"rich", ["First line", "", "Line 1", "", "Line 2", "", "Line 3", ""]
@@ -140,7 +139,6 @@ def main(arg: str):
140139
"Line 3",
141140
"",
142141
],
143-
marks=pytest.mark.xfail,
144142
),
145143
pytest.param(
146144
"rich",

typer/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Typer, build great CLIs. Easy to code. Based on Python type hints."""
22

3-
__version__ = "0.16.1"
3+
__version__ = "0.17.1"
44

55
from shutil import get_terminal_size as get_terminal_size
66

typer/cli.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import rich
1616

1717
has_rich = True
18-
from . import rich_utils
1918

2019
except ImportError: # pragma: no cover
2120
has_rich = False
@@ -275,6 +274,8 @@ def get_docs_for_click(
275274
def _parse_html(input_text: str) -> str:
276275
if not has_rich: # pragma: no cover
277276
return input_text
277+
from . import rich_utils
278+
278279
return rich_utils.rich_to_html(input_text)
279280

280281

typer/core.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
try:
3434
import rich
3535

36-
from . import rich_utils
37-
3836
DEFAULT_MARKUP_MODE: MarkupMode = "rich"
3937

4038
except ImportError: # pragma: no cover
@@ -213,6 +211,8 @@ def _main(
213211
raise
214212
# Typer override
215213
if rich and rich_markup_mode is not None:
214+
from . import rich_utils
215+
216216
rich_utils.rich_format_error(e)
217217
else:
218218
e.show()
@@ -243,6 +243,8 @@ def _main(
243243
raise
244244
# Typer override
245245
if rich and rich_markup_mode is not None:
246+
from . import rich_utils
247+
246248
rich_utils.rich_abort_error()
247249
else:
248250
click.echo(_("Aborted!"), file=sys.stderr)
@@ -705,6 +707,8 @@ def main(
705707
def format_help(self, ctx: click.Context, formatter: click.HelpFormatter) -> None:
706708
if not rich or self.rich_markup_mode is None:
707709
return super().format_help(ctx, formatter)
710+
from . import rich_utils
711+
708712
return rich_utils.rich_format_help(
709713
obj=self,
710714
ctx=ctx,
@@ -768,6 +772,8 @@ def main(
768772
def format_help(self, ctx: click.Context, formatter: click.HelpFormatter) -> None:
769773
if not rich or self.rich_markup_mode is None:
770774
return super().format_help(ctx, formatter)
775+
from . import rich_utils
776+
771777
return rich_utils.rich_format_help(
772778
obj=self,
773779
ctx=ctx,

typer/main.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,6 @@
5151

5252
try:
5353
import rich
54-
from rich.traceback import Traceback
55-
56-
from . import rich_utils
57-
58-
console_stderr = rich_utils._get_rich_console(stderr=True)
5954

6055
except ImportError: # pragma: no cover
6156
rich = None # type: ignore
@@ -83,16 +78,19 @@ def except_hook(
8378
supress_internal_dir_names = [typer_path, click_path]
8479
exc = exc_value
8580
if rich:
86-
from .rich_utils import MAX_WIDTH
81+
from rich.traceback import Traceback
82+
83+
from . import rich_utils
8784

8885
rich_tb = Traceback.from_exception(
8986
type(exc),
9087
exc,
9188
exc.__traceback__,
9289
show_locals=exception_config.pretty_exceptions_show_locals,
9390
suppress=supress_internal_dir_names,
94-
width=MAX_WIDTH,
91+
width=rich_utils.MAX_WIDTH,
9592
)
93+
console_stderr = rich_utils._get_rich_console(stderr=True)
9694
console_stderr.print(rich_tb)
9795
return
9896
tb_exc = traceback.TracebackException.from_exception(exc)

0 commit comments

Comments
 (0)