Skip to content

Commit 813dd35

Browse files
authored
Use pre-commit for linting (#607)
1 parent f66c1fb commit 813dd35

File tree

6 files changed

+95
-58
lines changed

6 files changed

+95
-58
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -81,27 +81,6 @@ jobs:
8181
# because we monkeypatch typing under some circumstances.
8282
python -c 'import typing_extensions; import test.__main__' test_typing -v
8383
84-
linting:
85-
name: Lint
86-
87-
# no reason to run this as a cron job
88-
if: github.event_name != 'schedule'
89-
90-
runs-on: ubuntu-latest
91-
92-
steps:
93-
- uses: actions/checkout@v4
94-
- name: Set up Python
95-
uses: actions/setup-python@v5
96-
with:
97-
python-version: "3"
98-
cache: "pip"
99-
cache-dependency-path: "test-requirements.txt"
100-
- name: Install dependencies
101-
run: pip install -r test-requirements.txt
102-
- name: Lint implementation
103-
run: ruff check
104-
10584
create-issue-on-failure:
10685
name: Create an issue if daily tests failed
10786
runs-on: ubuntu-latest

.pre-commit-config.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
repos:
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
rev: v0.9.6
4+
hooks:
5+
- id: ruff
6+
args: [--fix, --exit-non-zero-on-fix]
7+
- repo: https://github.com/pre-commit/pre-commit-hooks
8+
rev: v4.5.0
9+
hooks:
10+
- id: trailing-whitespace
11+
- id: end-of-file-fixer
12+
- id: check-docstring-first
13+
- id: check-yaml
14+
- id: check-toml
15+
- id: check-merge-conflict
16+
- id: check-case-conflict
17+
- id: forbid-submodules
18+
- id: mixed-line-ending
19+
args: [--fix=lf]
20+
- repo: https://github.com/python-jsonschema/check-jsonschema
21+
rev: 0.33.0
22+
hooks:
23+
- id: check-dependabot
24+
- repo: https://github.com/abravalheri/validate-pyproject
25+
rev: v0.24.1
26+
hooks:
27+
- id: validate-pyproject
28+
additional_dependencies: ["validate-pyproject-schema-store[all]"]
29+
- repo: https://github.com/rhysd/actionlint
30+
rev: v1.7.7
31+
hooks:
32+
- id: actionlint
33+
- repo: meta
34+
hooks:
35+
- id: check-hooks-apply

.readthedocs.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,3 @@ build:
1010

1111
sphinx:
1212
configuration: doc/conf.py
13-

CONTRIBUTING.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,31 @@ Running these commands in the `src/` directory ensures that the local file
5151
`typing_extensions.py` is used, instead of any other version of the library you
5252
may have installed.
5353

54+
# Linting
55+
56+
Linting is done via pre-commit. We recommend running pre-commit via a tool such
57+
as [uv](https://docs.astral.sh/uv/) or [pipx](https://pipx.pypa.io/stable/) so
58+
that pre-commit and its dependencies are installed into an isolated environment
59+
located outside your `typing_extensions` clone. Running pre-commit this way
60+
ensures that you don't accidentally install a version of `typing_extensions`
61+
from PyPI into a virtual environment inside your `typing_extensions` clone,
62+
which could easily happen if pre-commit depended (directly or indirectly) on
63+
`typing_extensions`. If a version of `typing_extensions` from PyPI *was*
64+
installed into a project-local virtual environment, it could lead to
65+
unpredictable results when running `typing_extensions` tests locally.
66+
67+
To run the linters using uv:
68+
69+
```
70+
uvx pre-commit run -a
71+
```
72+
73+
Or using pipx:
74+
75+
```
76+
pipx run pre-commit run -a
77+
```
78+
5479
# Workflow for PyPI releases
5580

5681
- Make sure you follow the versioning policy in the documentation

doc/make.bat

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
1-
@ECHO OFF
2-
3-
pushd %~dp0
4-
5-
REM Command file for Sphinx documentation
6-
7-
if "%SPHINXBUILD%" == "" (
8-
set SPHINXBUILD=sphinx-build
9-
)
10-
set SOURCEDIR=.
11-
set BUILDDIR=_build
12-
13-
%SPHINXBUILD% >NUL 2>NUL
14-
if errorlevel 9009 (
15-
echo.
16-
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
17-
echo.installed, then set the SPHINXBUILD environment variable to point
18-
echo.to the full path of the 'sphinx-build' executable. Alternatively you
19-
echo.may add the Sphinx directory to PATH.
20-
echo.
21-
echo.If you don't have Sphinx installed, grab it from
22-
echo.https://www.sphinx-doc.org/
23-
exit /b 1
24-
)
25-
26-
if "%1" == "" goto help
27-
28-
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
29-
goto end
30-
31-
:help
32-
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
33-
34-
:end
35-
popd
1+
@ECHO OFF
2+
3+
pushd %~dp0
4+
5+
REM Command file for Sphinx documentation
6+
7+
if "%SPHINXBUILD%" == "" (
8+
set SPHINXBUILD=sphinx-build
9+
)
10+
set SOURCEDIR=.
11+
set BUILDDIR=_build
12+
13+
%SPHINXBUILD% >NUL 2>NUL
14+
if errorlevel 9009 (
15+
echo.
16+
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
17+
echo.installed, then set the SPHINXBUILD environment variable to point
18+
echo.to the full path of the 'sphinx-build' executable. Alternatively you
19+
echo.may add the Sphinx directory to PATH.
20+
echo.
21+
echo.If you don't have Sphinx installed, grab it from
22+
echo.https://www.sphinx-doc.org/
23+
exit /b 1
24+
)
25+
26+
if "%1" == "" goto help
27+
28+
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
29+
goto end
30+
31+
:help
32+
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
33+
34+
:end
35+
popd

test-requirements.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)