Skip to content

Commit c29b2c1

Browse files
authored
Merge branch 'master' into dependabot/github_actions/actions/upload-artifact-6
2 parents 2463e04 + 65133a2 commit c29b2c1

642 files changed

Lines changed: 4418 additions & 4301 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/pre-commit.yml

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

.github/workflows/test.yml

Lines changed: 2 additions & 4 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:

.pre-commit-config.yaml

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
11
# See https://pre-commit.com for more information
22
# See https://pre-commit.com/hooks.html for more hooks
3-
default_language_version:
4-
python: python3.10
53
repos:
64
- repo: https://github.com/pre-commit/pre-commit-hooks
75
rev: v6.0.0
86
hooks:
9-
- id: check-added-large-files
10-
- id: check-toml
11-
- id: check-yaml
7+
- id: check-added-large-files
8+
- id: check-toml
9+
- id: check-yaml
1210
args:
1311
- --unsafe
14-
- id: end-of-file-fixer
15-
- id: trailing-whitespace
16-
- repo: https://github.com/astral-sh/ruff-pre-commit
17-
rev: v0.14.8
12+
- id: end-of-file-fixer
13+
- id: trailing-whitespace
14+
15+
- repo: local
1816
hooks:
19-
- id: ruff
20-
args:
21-
- --fix
22-
- id: ruff-format
23-
ci:
24-
autofix_commit_msg: 🎨 [pre-commit.ci] Auto format from pre-commit.com hooks
25-
autoupdate_commit_msg: ⬆ [pre-commit.ci] pre-commit autoupdate
17+
- id: local-ruff-check
18+
name: ruff check
19+
entry: uv run ruff check --force-exclude --fix --exit-non-zero-on-fix
20+
require_serial: true
21+
language: unsupported
22+
types: [python]
23+
24+
- id: local-ruff-format
25+
name: ruff format
26+
entry: uv run ruff format --force-exclude --exit-non-zero-on-format
27+
require_serial: true
28+
language: unsupported
29+
types: [python]

docs/management-tasks.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ A PR should have a specific use case that it is solving.
9090
* If the PR is for a feature, it should have docs.
9191
* Unless it's a feature we want to discourage, like support for a corner case that we don't want users to use.
9292
* The docs should include a source example file, not write Python directly in Markdown.
93-
* If the source example(s) file can have different syntax for Python 3.8, 3.9, 3.10, there should be different versions of the file, and they should be shown in tabs in the docs.
93+
* If the source example(s) file can have different syntax for Python different Python versions, there should be different versions of the file, and they should be shown in tabs in the docs.
9494
* There should be tests testing the source example.
9595
* Before the PR is applied, the new tests should fail.
9696
* After applying the PR, the new tests should pass.

docs/release-notes.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,27 @@
44

55
### Internal
66

7+
* 👷 Update secrets check. PR [#1471](https://github.com/fastapi/typer/pull/1471) by [@YuriiMotov](https://github.com/YuriiMotov).
8+
* ✅ Add missing tests for code examples. PR [#1465](https://github.com/fastapi/typer/pull/1465) by [@YuriiMotov](https://github.com/YuriiMotov).
9+
* 🔧 Update pre-commit to use local Ruff instead of hook, unpin `prek`. PR [#1466](https://github.com/fastapi/typer/pull/1466) by [@YuriiMotov](https://github.com/YuriiMotov).
10+
* ⬆ Bump mypy from 1.14.1 to 1.18.2. PR [#1382](https://github.com/fastapi/typer/pull/1382) by [@dependabot[bot]](https://github.com/apps/dependabot).
11+
12+
## 0.21.0
13+
14+
### Breaking Changes
15+
16+
* ➖ Drop support for Python 3.8. PR [#1464](https://github.com/fastapi/typer/pull/1464) by [@tiangolo](https://github.com/tiangolo).
17+
* ➖ Drop support for Python 3.8 in CI. PR [#1463](https://github.com/fastapi/typer/pull/1463) by [@YuriiMotov](https://github.com/YuriiMotov) and [@tiangolo](https://github.com/tiangolo).
18+
19+
### Docs
20+
21+
* 📝 Update code examples to Python 3.9. PR [#1459](https://github.com/fastapi/typer/pull/1459) by [@YuriiMotov](https://github.com/YuriiMotov).
22+
23+
### Internal
24+
25+
* 💚 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).
26+
* ⬆ 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).
27+
* 👷 Add pre-commit workflow. PR [#1453](https://github.com/fastapi/typer/pull/1453) by [@tiangolo](https://github.com/tiangolo).
728
* 👷 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).
829
* 👷 Run Smokeshow always, even on test failures. PR [#1447](https://github.com/fastapi/typer/pull/1447) by [@YuriiMotov](https://github.com/YuriiMotov).
930
* 🔨 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).

docs/tutorial/app-dir.md

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

33
You can get the application directory where you can, for example, save configuration files with `typer.get_app_dir()`:
44

5-
{* docs_src/app_dir/tutorial001.py hl[12] *}
5+
{* docs_src/app_dir/tutorial001_py39.py hl[12] *}
66

77
It will give you a directory for storing configurations appropriate for your CLI program for the current user in each operating system.
88

docs/tutorial/arguments/default.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ That way the *CLI argument* will be optional *and also* have a default value.
88

99
We can also use `typer.Argument()` to make a *CLI argument* have a default value other than `None`:
1010

11-
{* docs_src/arguments/default/tutorial001_an.py hl[8] *}
11+
{* docs_src/arguments/default/tutorial001_an_py39.py hl[9] *}
1212

1313
/// tip
1414

@@ -52,7 +52,7 @@ Hello Camila
5252

5353
And we can even make the default value be dynamically generated by passing a function as the `default_factory` argument:
5454

55-
{* docs_src/arguments/default/tutorial002_an.py hl[9:10,14] *}
55+
{* docs_src/arguments/default/tutorial002_an_py39.py hl[9:10,14] *}
5656

5757
In this case, we created the function `get_name` that will just return a random `str` each time.
5858

docs/tutorial/arguments/envvar.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ You can learn more about environment variables in the [Environment Variables](..
1010

1111
To do that, use the `envvar` parameter for `typer.Argument()`:
1212

13-
{* docs_src/arguments/envvar/tutorial001_an.py hl[8] *}
13+
{* docs_src/arguments/envvar/tutorial001_an_py39.py hl[9] *}
1414

1515
In this case, the *CLI argument* `name` will have a default value of `"World"`, but will also read any value passed to the environment variable `AWESOME_NAME` if no value is provided in the command line:
1616

@@ -55,7 +55,7 @@ Hello Mr. Czernobog
5555

5656
You are not restricted to a single environment variable, you can declare a list of environment variables that could be used to get a value if it was not passed in the command line:
5757

58-
{* docs_src/arguments/envvar/tutorial002_an.py hl[9] *}
58+
{* docs_src/arguments/envvar/tutorial002_an_py39.py hl[10] *}
5959

6060
Check it:
6161

@@ -90,7 +90,7 @@ Hello Mr. Anubis
9090

9191
By default, environment variables used will be shown in the help text, but you can disable them with `show_envvar=False`:
9292

93-
{* docs_src/arguments/envvar/tutorial003_an.py hl[10] *}
93+
{* docs_src/arguments/envvar/tutorial003_an_py39.py hl[11] *}
9494

9595
Check it:
9696

docs/tutorial/arguments/help.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ In the *First Steps* section you saw how to add help for a CLI app/command by ad
44

55
Here's how that last example looked like:
66

7-
{* docs_src/first_steps/tutorial006.py *}
7+
{* docs_src/first_steps/tutorial006_py39.py *}
88

99
Now that you also know how to use `typer.Argument()`, let's use it to add documentation specific for a *CLI argument*.
1010

1111
## Add a `help` text for a *CLI argument*
1212

1313
You can use the `help` parameter to add a help text for a *CLI argument*:
1414

15-
{* docs_src/arguments/help/tutorial001_an.py hl[8] *}
15+
{* docs_src/arguments/help/tutorial001_an_py39.py hl[9] *}
1616

1717
And it will be used in the automatic `--help` option:
1818

@@ -37,7 +37,7 @@ Options:
3737

3838
And of course, you can also combine that `help` with the <abbr title="a multi-line string as the first expression inside a function (not assigned to any variable) used for documentation">docstring</abbr>:
3939

40-
{* docs_src/arguments/help/tutorial002_an.py hl[8:11] *}
40+
{* docs_src/arguments/help/tutorial002_an_py39.py hl[9:12] *}
4141

4242
And the `--help` option will combine all the information:
4343

@@ -64,7 +64,7 @@ Options:
6464

6565
If you have a *CLI argument* with a default value, like `"World"`:
6666

67-
{* docs_src/arguments/help/tutorial003_an.py hl[8] *}
67+
{* docs_src/arguments/help/tutorial003_an_py39.py hl[9] *}
6868

6969
It will show that default value in the help text:
7070

@@ -89,7 +89,7 @@ Options:
8989

9090
But you can disable that if you want to, with `show_default=False`:
9191

92-
{* docs_src/arguments/help/tutorial004_an.py hl[10] *}
92+
{* docs_src/arguments/help/tutorial004_an_py39.py hl[11] *}
9393

9494
And then it won't show the default value:
9595

@@ -124,7 +124,7 @@ In **Typer** these default values are shown by default. 👀
124124

125125
You can use the same `show_default` to pass a custom string (instead of a `bool`) to customize the default value to be shown in the help text:
126126

127-
{* docs_src/arguments/help/tutorial005_an.py hl[12] *}
127+
{* docs_src/arguments/help/tutorial005_an_py39.py hl[13] *}
128128

129129
And it will be used in the help text:
130130

@@ -169,7 +169,7 @@ But you can customize it with the `metavar` parameter for `typer.Argument()`.
169169

170170
For example, let's say you don't want to have the default of `NAME`, you want to have `username`, in lowercase, and you really want ✨ emojis ✨ everywhere:
171171

172-
{* docs_src/arguments/help/tutorial006_an.py hl[8] *}
172+
{* docs_src/arguments/help/tutorial006_an_py39.py hl[9] *}
173173

174174
Now the generated help text will have `✨username✨` instead of `NAME`:
175175

@@ -195,7 +195,7 @@ You might want to show the help information for *CLI arguments* in different pan
195195

196196
If you have installed Rich as described in the docs for [Printing and Colors](../printing.md){.internal-link target=_blank}, you can set the `rich_help_panel` parameter to the name of the panel where you want this *CLI argument* to be shown:
197197

198-
{* docs_src/arguments/help/tutorial007_an.py hl[11,15] *}
198+
{* docs_src/arguments/help/tutorial007_an_py39.py hl[12,16] *}
199199

200200
Then, if you check the `--help` option, you will see a default panel named "`Arguments`" for the *CLI arguments* that don't have a custom `rich_help_panel`.
201201

@@ -238,7 +238,7 @@ If you want, you can make a *CLI argument* **not** show up in the `Arguments` se
238238

239239
You will probably not want to do this normally, but it's possible:
240240

241-
{* docs_src/arguments/help/tutorial008_an.py hl[8] *}
241+
{* docs_src/arguments/help/tutorial008_an_py39.py hl[9] *}
242242

243243
Check it:
244244

docs/tutorial/arguments/optional.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ __init__.py test_tutorial
3535

3636
In the [First Steps](../first-steps.md#add-a-cli-argument){.internal-link target=_blank} you saw how to add a *CLI argument*:
3737

38-
{* docs_src/first_steps/tutorial002.py hl[4] *}
38+
{* docs_src/first_steps/tutorial002_py39.py hl[4] *}
3939

4040
Now let's see an alternative way to create the same *CLI argument*:
4141

42-
{* docs_src/arguments/optional/tutorial000.py hl[4] *}
42+
{* docs_src/arguments/optional/tutorial000_an_py39.py hl[6] *}
4343

4444
Or, using an explicit `Typer()` instance creation:
4545

46-
{* docs_src/arguments/optional/tutorial001_an.py hl[8] *}
46+
{* docs_src/arguments/optional/tutorial001_an_py39.py hl[9] *}
4747

4848
/// info
4949

@@ -114,7 +114,7 @@ Now, finally what we came for, an optional *CLI argument*.
114114

115115
To make a *CLI argument* optional, use `typer.Argument()` and make sure to provide a "default" value, for example `"World"`:
116116

117-
{* docs_src/arguments/optional/tutorial002_an.py hl[8] *}
117+
{* docs_src/arguments/optional/tutorial002_an_py39.py hl[9] *}
118118

119119
Now we have:
120120

@@ -181,7 +181,7 @@ Notice that "`Camila`" here is an optional *CLI argument*, not a *CLI option*, b
181181

182182
Instead of using `Annotated`, you can use `typer.Argument()` as the default value:
183183

184-
{* docs_src/arguments/optional/tutorial001.py hl[7] *}
184+
{* docs_src/arguments/optional/tutorial001_py39.py hl[7] *}
185185

186186
/// tip
187187

@@ -215,11 +215,11 @@ If you hadn't seen that `...` before: it is a special single value, it is <a hre
215215

216216
///
217217

218-
{* docs_src/arguments/optional/tutorial003.py hl[7] *}
218+
{* docs_src/arguments/optional/tutorial003_py39.py hl[7] *}
219219

220220
And the same way, you can make it optional by passing a different `default` value, for example `"World"`:
221221

222-
{* docs_src/arguments/optional/tutorial002.py hl[7] *}
222+
{* docs_src/arguments/optional/tutorial002_py39.py hl[7] *}
223223

224224
Because the first parameter passed to `typer.Argument(default="World")` (the new "default" value) is `"World"`, **Typer** knows that this is an **optional** *CLI argument*, if no value is provided when calling it in the command line, it will have that default value of `"World"`.
225225

0 commit comments

Comments
 (0)