Skip to content

Commit 64fa088

Browse files
authored
Merge branch 'master' into update-code-examples-to-python-3.9
2 parents eb7a6aa + b7f39ea commit 64fa088

11 files changed

Lines changed: 288 additions & 52 deletions

.github/workflows/pre-commit.yml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: pre-commit
2+
3+
on:
4+
pull_request:
5+
types:
6+
- opened
7+
- synchronize
8+
9+
env:
10+
IS_FORK: ${{ github.event.pull_request.head.repo.full_name != github.repository }}
11+
12+
jobs:
13+
pre-commit:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Dump GitHub context
17+
env:
18+
GITHUB_CONTEXT: ${{ toJson(github) }}
19+
run: echo "$GITHUB_CONTEXT"
20+
- uses: actions/checkout@v5
21+
name: Checkout PR for own repo
22+
if: env.IS_FORK == 'false'
23+
with:
24+
# To be able to commit it needs to fetch the head of the branch, not the
25+
# merge commit
26+
ref: ${{ github.head_ref }}
27+
# And it needs the full history to be able to compute diffs
28+
fetch-depth: 0
29+
# A token other than the default GITHUB_TOKEN is needed to be able to trigger CI
30+
token: ${{ secrets.PRE_COMMIT }}
31+
# pre-commit lite ci needs the default checkout configs to work
32+
- uses: actions/checkout@v5
33+
name: Checkout PR for fork
34+
if: env.IS_FORK == 'true'
35+
with:
36+
# To be able to commit it needs the head branch of the PR, the remote one
37+
ref: ${{ github.event.pull_request.head.sha }}
38+
fetch-depth: 0
39+
- name: Set up Python
40+
uses: actions/setup-python@v6
41+
with:
42+
python-version: "3.14"
43+
- name: Setup uv
44+
uses: astral-sh/setup-uv@v7
45+
with:
46+
cache-dependency-glob: |
47+
requirements**.txt
48+
pyproject.toml
49+
uv.lock
50+
- name: Install Dependencies
51+
run: |
52+
uv venv
53+
uv pip install -r requirements.txt
54+
- name: Run prek - pre-commit
55+
id: precommit
56+
run: uvx prek run --from-ref origin/${GITHUB_BASE_REF} --to-ref HEAD --show-diff-on-failure
57+
continue-on-error: true
58+
- name: Commit and push changes
59+
if: env.IS_FORK == 'false'
60+
run: |
61+
git config user.name "github-actions[bot]"
62+
git config user.email "github-actions[bot]@users.noreply.github.com"
63+
git add -A
64+
if git diff --staged --quiet; then
65+
echo "No changes to commit"
66+
else
67+
git commit -m "🎨 Auto format"
68+
git push
69+
fi
70+
- uses: pre-commit-ci/[email protected]
71+
if: env.IS_FORK == 'true'
72+
with:
73+
msg: 🎨 Auto format
74+
- name: Error out on pre-commit errors
75+
if: steps.precommit.outcome == 'failure'
76+
run: exit 1
77+
78+
# https://github.com/marketplace/actions/alls-green#why
79+
pre-commit-alls-green: # This job does nothing and is only used for the branch protection
80+
if: always()
81+
needs:
82+
- pre-commit
83+
runs-on: ubuntu-latest
84+
steps:
85+
- name: Dump GitHub context
86+
env:
87+
GITHUB_CONTEXT: ${{ toJson(github) }}
88+
run: echo "$GITHUB_CONTEXT"
89+
- name: Decide whether the needed jobs succeeded or failed
90+
uses: re-actors/alls-green@release/v1
91+
with:
92+
jobs: ${{ toJSON(needs) }}

.github/workflows/smokeshow.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ env:
1515

1616
jobs:
1717
smokeshow:
18-
if: ${{ github.event.workflow_run.conclusion == 'success' }}
1918
runs-on: ubuntu-latest
2019
steps:
2120
- name: Dump GitHub context
@@ -25,12 +24,10 @@ jobs:
2524
- uses: actions/checkout@v6
2625
- uses: actions/setup-python@v6
2726
with:
28-
python-version: '3.9'
27+
python-version: '3.13'
2928
- name: Setup uv
3029
uses: astral-sh/setup-uv@v7
3130
with:
32-
version: "0.4.15"
33-
enable-cache: true
3431
cache-dependency-glob: |
3532
requirements**.txt
3633
pyproject.toml

.github/workflows/test.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ jobs:
2222
os: [ ubuntu-latest, windows-latest, macos-latest ]
2323
python-version: [ "3.14" ]
2424
include:
25-
- os: macos-latest
26-
python-version: "3.8"
2725
- os: windows-latest
2826
python-version: "3.9"
2927
- os: ubuntu-latest
@@ -57,7 +55,7 @@ jobs:
5755
- name: Install Dependencies
5856
run: uv pip install -r requirements-tests.txt
5957
- name: Lint
60-
if: matrix.python-version != '3.7' && matrix.python-version != '3.8' && matrix.python-version != '3.9'
58+
if: matrix.python-version != '3.9'
6159
run: bash scripts/lint.sh
6260
- run: mkdir coverage
6361
- run: bash ./scripts/test-files.sh
@@ -84,7 +82,7 @@ jobs:
8482
- uses: actions/checkout@v6
8583
- uses: actions/setup-python@v6
8684
with:
87-
python-version: '3.8'
85+
python-version: '3.13'
8886
- name: Setup uv
8987
uses: astral-sh/setup-uv@v7
9088
with:
@@ -103,14 +101,14 @@ jobs:
103101
run: uv pip install -r requirements-tests.txt
104102
- run: ls -la coverage
105103
- run: coverage combine coverage
106-
- run: coverage report
107104
- run: coverage html --show-contexts --title "Coverage for ${{ github.sha }}"
108105
- name: Store coverage HTML
109106
uses: actions/upload-artifact@v5
110107
with:
111108
name: coverage-html
112109
path: htmlcov
113110
include-hidden-files: true
111+
- run: coverage report --fail-under=100
114112

115113
# https://github.com/marketplace/actions/alls-green#why
116114
check: # This job does nothing and is only used for the branch protection

docs/release-notes.md

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

33
## Latest Changes
44

5+
### Breaking Changes
6+
7+
* ➖ Drop support for Python 3.8. PR [#1463](https://github.com/fastapi/typer/pull/1463) by [@tiangolo](https://github.com/tiangolo).
8+
59
### Internal
610

11+
* 💚 Move `ruff` dependency to shared `requirements-docs-tests.txt` to fix "Build docs" workflow in CI. PR [#1458](https://github.com/fastapi/typer/pull/1458) by [@YuriiMotov](https://github.com/YuriiMotov).
12+
* ⬆ Bump markdown-include-variants from 0.0.5 to 0.0.8. PR [#1442](https://github.com/fastapi/typer/pull/1442) by [@dependabot[bot]](https://github.com/apps/dependabot).
13+
* 👷 Add pre-commit workflow. PR [#1453](https://github.com/fastapi/typer/pull/1453) by [@tiangolo](https://github.com/tiangolo).
14+
* 👷 Configure coverage, error on main tests, don't wait for Smokeshow. PR [#1448](https://github.com/fastapi/typer/pull/1448) by [@YuriiMotov](https://github.com/YuriiMotov).
15+
* 👷 Run Smokeshow always, even on test failures. PR [#1447](https://github.com/fastapi/typer/pull/1447) by [@YuriiMotov](https://github.com/YuriiMotov).
716
* 🔨 Add Typer script to generate example variants for Python files. PR [#1452](https://github.com/fastapi/typer/pull/1452) by [@tiangolo](https://github.com/tiangolo).
817

918
## 0.20.1

requirements-docs-tests.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# For linting and generating docs versions
2+
ruff ==0.14.8

requirements-docs.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
-e .
2-
2+
-r requirements-docs-tests.txt
33
mkdocs-material==9.7.0
44
mdx-include >=1.4.1,<2.0.0
55
mkdocs-redirects>=1.2.1,<1.3.0
@@ -16,4 +16,4 @@ griffe-warnings-deprecated==1.1.0
1616
# For griffe, it formats with black
1717
# black==24.3.0
1818
mkdocs-macros-plugin==1.5.0
19-
markdown-include-variants==0.0.5
19+
markdown-include-variants==0.0.8

requirements-tests.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
-e .
2-
2+
-r requirements-docs-tests.txt
33
pytest >=4.4.0,<9.0.0
44
pytest-cov >=2.10.0,<8.0.0
55
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.14.1
9-
ruff ==0.14.8
109
# Needed explicitly by typer-slim
1110
rich >=10.11.0
1211
shellingham >=1.3.0

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
-r requirements-tests.txt
44
-r requirements-docs.txt
55

6-
pre-commit >=2.17.0,<5.0.0
6+
prek==0.2.22

typer/_typing.py

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,23 @@
11
# Copied from pydantic 1.9.2 (the latest version to support python 3.6.)
22
# https://github.com/pydantic/pydantic/blob/v1.9.2/pydantic/typing.py
3-
# Reduced drastically to only include Typer-specific 3.8+ functionality
3+
# Reduced drastically to only include Typer-specific 3.9+ functionality
44
# mypy: ignore-errors
55

66
import sys
77
from typing import (
8+
Annotated,
89
Any,
910
Callable,
11+
Literal,
1012
Optional,
1113
Tuple,
1214
Type,
1315
Union,
16+
get_args,
17+
get_origin,
18+
get_type_hints,
1419
)
1520

16-
if sys.version_info >= (3, 9):
17-
from typing import Annotated, Literal, get_args, get_origin, get_type_hints
18-
else:
19-
from typing_extensions import (
20-
Annotated,
21-
Literal,
22-
get_args,
23-
get_origin,
24-
get_type_hints,
25-
)
26-
2721
if sys.version_info < (3, 10):
2822

2923
def is_union(tp: Optional[Type[Any]]) -> bool:
@@ -57,25 +51,11 @@ def is_union(tp: Optional[Type[Any]]) -> bool:
5751
NONE_TYPES: Tuple[Any, Any, Any] = (None, NoneType, Literal[None])
5852

5953

60-
if sys.version_info[:2] == (3, 8):
61-
# We can use the fast implementation for 3.8 but there is a very weird bug
62-
# where it can fail for `Literal[None]`.
63-
# We just need to redefine a useless `Literal[None]` inside the function body to fix this
64-
65-
def is_none_type(type_: Any) -> bool:
66-
Literal[None] # fix edge case
67-
for none_type in NONE_TYPES:
68-
if type_ is none_type:
69-
return True
70-
return False
71-
72-
else:
73-
74-
def is_none_type(type_: Any) -> bool:
75-
for none_type in NONE_TYPES:
76-
if type_ is none_type:
77-
return True
78-
return False
54+
def is_none_type(type_: Any) -> bool:
55+
for none_type in NONE_TYPES:
56+
if type_ is none_type:
57+
return True
58+
return False
7959

8060

8161
def is_callable_type(type_: Type[Any]) -> bool:

typer/rich_utils.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22

33
import inspect
44
import io
5-
import sys
65
from collections import defaultdict
76
from gettext import gettext as _
87
from os import getenv
9-
from typing import Any, DefaultDict, Dict, Iterable, List, Optional, Union
8+
from typing import Any, DefaultDict, Dict, Iterable, List, Literal, Optional, Union
109

1110
import click
1211
from rich import box
@@ -25,11 +24,6 @@
2524
from rich.traceback import Traceback
2625
from typer.models import DeveloperExceptionConfig
2726

28-
if sys.version_info >= (3, 9):
29-
from typing import Literal
30-
else:
31-
from typing_extensions import Literal
32-
3327
# Default styles
3428
STYLE_OPTION = "bold cyan"
3529
STYLE_SWITCH = "bold green"

0 commit comments

Comments
 (0)