Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,20 @@ select = [
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"UP", # pyupgrade
"TID", # flake8-tidy-imports
]
ignore = [
"E501", # line too long, handled by black
"B008", # do not perform function calls in argument defaults
"C901", # too complex
"W191", # indentation contains tabs
"TID252", # relative imports okay
]

[tool.ruff.lint.per-file-ignores]
# "__init__.py" = ["F401"]
# rich_utils is allowed to use rich imports
"typer/rich_utils.py" = ["TID251"]
# This file is more readable without yield from
"docs_src/progressbar/tutorial004.py" = ["UP028", "B007"]
# Default mutable data structure
Expand All @@ -192,6 +196,8 @@ ignore = [
"docs_src/prompt/tutorial003.py" = ["F841"]
# Loop control variable `x` not used within loop body
"docs_src/using_click/tutorial001.py" = ["B007"]
# No need to worry about rich imports in docs
"docs_src/*" = ["TID"]

[tool.ruff.lint.isort]
known-third-party = ["typer", "click"]
Expand All @@ -201,3 +207,10 @@ known-first-party = ["reigns", "towns", "lands", "items", "users"]
[tool.ruff.lint.pyupgrade]
# Preserve types, even if a file imports `from __future__ import annotations`.
keep-runtime-typing = true

[tool.ruff.lint.flake8-tidy-imports]
# Import rich_utils from within functions (lazy), not at the module level (TID253)
banned-module-level-imports = ["typer.rich_utils"]

[tool.ruff.lint.flake8-tidy-imports.banned-api]
"rich".msg = "Use 'typer.rich_utils' instead of importing from 'rich' directly."
2 changes: 1 addition & 1 deletion tests/assets/type_error_no_rich.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import typer
import typer.main

typer.main.rich = None
typer.main.HAS_RICH = False


def main(name: str = "morty"):
Expand Down
2 changes: 1 addition & 1 deletion tests/assets/type_error_no_rich_short_disable.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import typer
import typer.main

typer.main.rich = None
typer.main.HAS_RICH = False


app = typer.Typer(pretty_exceptions_short=False)
Expand Down
8 changes: 4 additions & 4 deletions tests/test_corner_cases.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pytest
import typer.core
from typer.testing import CliRunner

Expand All @@ -16,17 +17,16 @@ def test_hidden_option():
assert "(dynamic)" in result.output


def test_hidden_option_no_rich():
rich = typer.core.rich
typer.core.rich = None
def test_hidden_option_no_rich(monkeypatch: pytest.MonkeyPatch):
monkeypatch.setattr(typer.core, "HAS_RICH", False)

result = runner.invoke(mod.app, ["--help"])
assert result.exit_code == 0
assert "Say hello" in result.output
assert "--name" not in result.output
assert "/lastname" in result.output
assert "TEST_LASTNAME" in result.output
assert "(dynamic)" in result.output
typer.core.rich = rich


def test_coverage_call():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import subprocess
import sys

import pytest
import typer
import typer.core
from typer.testing import CliRunner
Expand All @@ -22,16 +23,14 @@ def test_help():
assert "default: World" in result.output


def test_help_no_rich():
rich = typer.core.rich
typer.core.rich = None
def test_help_no_rich(monkeypatch: pytest.MonkeyPatch):
monkeypatch.setattr(typer.core, "HAS_RICH", False)
result = runner.invoke(app, ["--help"])
assert result.exit_code == 0
assert "[OPTIONS] [NAME]" in result.output
assert "Arguments" in result.output
assert "env var: AWESOME_NAME" in result.output
assert "default: World" in result.output
typer.core.rich = rich


def test_call_arg():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import subprocess
import sys

import pytest
import typer
import typer.core
from typer.testing import CliRunner
Expand All @@ -22,16 +23,15 @@ def test_help():
assert "default: World" in result.output


def test_help_no_rich():
rich = typer.core.rich
typer.core.rich = None
def test_help_no_rich(monkeypatch: pytest.MonkeyPatch):
monkeypatch.setattr(typer.core, "HAS_RICH", False)

result = runner.invoke(app, ["--help"])
assert result.exit_code == 0
assert "[OPTIONS] [NAME]" in result.output
assert "Arguments" in result.output
assert "env var: AWESOME_NAME" in result.output
assert "default: World" in result.output
typer.core.rich = rich


def test_call_arg():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import subprocess
import sys

import pytest
import typer
import typer.core
from typer.testing import CliRunner
Expand All @@ -23,17 +24,15 @@ def test_help():
assert "[required]" in result.output


def test_help_no_rich():
rich = typer.core.rich
typer.core.rich = None
def test_help_no_rich(monkeypatch: pytest.MonkeyPatch):
monkeypatch.setattr(typer.core, "HAS_RICH", False)
result = runner.invoke(app, ["--help"])
assert result.exit_code == 0
assert "[OPTIONS] NAME" in result.output
assert "Arguments" in result.output
assert "NAME" in result.output
assert "The name of the user to greet" in result.output
assert "[required]" in result.output
typer.core.rich = rich


def test_call_arg():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import subprocess
import sys

import pytest
import typer
import typer.core
from typer.testing import CliRunner
Expand All @@ -23,17 +24,15 @@ def test_help():
assert "[required]" in result.output


def test_help_no_rich():
rich = typer.core.rich
typer.core.rich = None
def test_help_no_rich(monkeypatch: pytest.MonkeyPatch):
monkeypatch.setattr(typer.core, "HAS_RICH", False)
result = runner.invoke(app, ["--help"])
assert result.exit_code == 0
assert "[OPTIONS] NAME" in result.output
assert "Arguments" in result.output
assert "NAME" in result.output
assert "The name of the user to greet" in result.output
assert "[required]" in result.output
typer.core.rich = rich


def test_call_arg():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import subprocess
import sys

import pytest
import typer
import typer.core
from typer.testing import CliRunner
Expand All @@ -22,16 +23,14 @@ def test_help():
assert "[default: World]" not in result.output


def test_help_no_rich():
rich = typer.core.rich
typer.core.rich = None
def test_help_no_rich(monkeypatch: pytest.MonkeyPatch):
monkeypatch.setattr(typer.core, "HAS_RICH", False)
result = runner.invoke(app, ["--help"])
assert result.exit_code == 0
assert "[OPTIONS] [NAME]" in result.output
assert "Say hi to NAME very gently, like Dirk." in result.output
assert "Arguments" not in result.output
assert "[default: World]" not in result.output
typer.core.rich = rich


def test_call_arg():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import subprocess
import sys

import pytest
import typer
import typer.core
from typer.testing import CliRunner
Expand All @@ -22,16 +23,14 @@ def test_help():
assert "[default: World]" not in result.output


def test_help_no_rich():
rich = typer.core.rich
typer.core.rich = None
def test_help_no_rich(monkeypatch: pytest.MonkeyPatch):
monkeypatch.setattr(typer.core, "HAS_RICH", False)
result = runner.invoke(app, ["--help"])
assert result.exit_code == 0
assert "[OPTIONS] [NAME]" in result.output
assert "Say hi to NAME very gently, like Dirk." in result.output
assert "Arguments" not in result.output
assert "[default: World]" not in result.output
typer.core.rich = rich


def test_call_arg():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import subprocess
import sys

import pytest
import typer
import typer.core
from typer.testing import CliRunner
Expand All @@ -25,14 +26,12 @@ def test_call_no_arg_standalone():
assert result.exit_code != 0


def test_call_no_arg_no_rich():
def test_call_no_arg_no_rich(monkeypatch: pytest.MonkeyPatch):
# Mainly for coverage
rich = typer.core.rich
typer.core.rich = None
monkeypatch.setattr(typer.core, "HAS_RICH", False)
result = runner.invoke(app)
assert result.exit_code != 0
assert "Error: Missing argument 'NAME'" in result.output
typer.core.rich = rich


def test_call_arg():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import subprocess
import sys

import pytest
import typer
import typer.core
from typer.testing import CliRunner
Expand All @@ -25,14 +26,12 @@ def test_call_no_arg_standalone():
assert result.exit_code != 0


def test_call_no_arg_no_rich():
def test_call_no_arg_no_rich(monkeypatch: pytest.MonkeyPatch):
# Mainly for coverage
rich = typer.core.rich
typer.core.rich = None
monkeypatch.setattr(typer.core, "HAS_RICH", False)
result = runner.invoke(app)
assert result.exit_code != 0
assert "Error: Missing argument 'NAME'" in result.output
typer.core.rich = rich


def test_call_arg():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import subprocess
import sys

import pytest
import typer
import typer.core
from typer.testing import CliRunner
Expand All @@ -25,14 +26,12 @@ def test_call_no_arg_standalone():
assert result.exit_code != 0


def test_call_no_arg_no_rich():
def test_call_no_arg_no_rich(monkeypatch: pytest.MonkeyPatch):
# Mainly for coverage
rich = typer.core.rich
typer.core.rich = None
monkeypatch.setattr(typer.core, "HAS_RICH", False)
result = runner.invoke(app)
assert result.exit_code != 0
assert "Error: Missing argument 'NAME'" in result.output
typer.core.rich = rich


def test_call_arg():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import subprocess
import sys

import pytest
import typer.core
from typer.testing import CliRunner

Expand All @@ -19,15 +20,13 @@ def test_help():
assert "--no-verbose" in result.output


def test_help_no_rich():
rich = typer.core.rich
typer.core.rich = None
def test_help_no_rich(monkeypatch: pytest.MonkeyPatch):
monkeypatch.setattr(typer.core, "HAS_RICH", False)
result = runner.invoke(app, ["--help"])
assert result.exit_code == 0
assert "Manage users in the awesome CLI app." in result.output
assert "--verbose" in result.output
assert "--no-verbose" in result.output
typer.core.rich = rich


def test_create():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import subprocess
import sys

import pytest
import typer
import typer.core
from typer.testing import CliRunner
Expand Down Expand Up @@ -33,15 +34,13 @@ def test_help():
assert "[required]" in result.output


def test_help_no_rich():
rich = typer.core.rich
typer.core.rich = None
def test_help_no_rich(monkeypatch: pytest.MonkeyPatch):
monkeypatch.setattr(typer.core, "HAS_RICH", False)
result = runner.invoke(app, ["--help"])
assert result.exit_code == 0
assert "--lastname" in result.output
assert "TEXT" in result.output
assert "[required]" in result.output
typer.core.rich = rich


def test_script():
Expand Down
Loading
Loading