From d166fe3a6647d99b07216ba7ff6bff3e88db6c38 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Sun, 25 May 2025 15:56:55 +0100 Subject: [PATCH] Lint via pre-commit --- .github/workflows/ci.yml | 21 ------------ .pre-commit-config.yaml | 35 ++++++++++++++++++++ .readthedocs.yaml | 1 - CONTRIBUTING.md | 25 ++++++++++++++ doc/make.bat | 70 ++++++++++++++++++++-------------------- test-requirements.txt | 1 - 6 files changed, 95 insertions(+), 58 deletions(-) create mode 100644 .pre-commit-config.yaml delete mode 100644 test-requirements.txt diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3df842da..b90bf0d8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -80,27 +80,6 @@ jobs: # because we monkeypatch typing under some circumstances. python -c 'import typing_extensions; import test.__main__' test_typing -v - linting: - name: Lint - - # no reason to run this as a cron job - if: github.event_name != 'schedule' - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: "3" - cache: "pip" - cache-dependency-path: "test-requirements.txt" - - name: Install dependencies - run: pip install -r test-requirements.txt - - name: Lint implementation - run: ruff check - create-issue-on-failure: name: Create an issue if daily tests failed runs-on: ubuntu-latest diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..96e97c70 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,35 @@ +repos: + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.9.6 + hooks: + - id: ruff + args: [--fix, --exit-non-zero-on-fix] + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-docstring-first + - id: check-yaml + - id: check-toml + - id: check-merge-conflict + - id: check-case-conflict + - id: forbid-submodules + - id: mixed-line-ending + args: [--fix=lf] + - repo: https://github.com/python-jsonschema/check-jsonschema + rev: 0.33.0 + hooks: + - id: check-dependabot + - repo: https://github.com/abravalheri/validate-pyproject + rev: v0.24.1 + hooks: + - id: validate-pyproject + additional_dependencies: ["validate-pyproject-schema-store[all]"] + - repo: https://github.com/rhysd/actionlint + rev: v1.7.7 + hooks: + - id: actionlint + - repo: meta + hooks: + - id: check-hooks-apply diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 60419be8..5de3b9a3 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -10,4 +10,3 @@ build: sphinx: configuration: doc/conf.py - diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1b030d56..086ba3f7 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -51,6 +51,31 @@ Running these commands in the `src/` directory ensures that the local file `typing_extensions.py` is used, instead of any other version of the library you may have installed. +# Linting + +Linting is done via pre-commit. We recommend running pre-commit via a tool such +as [uv](https://docs.astral.sh/uv/) or [pipx](https://pipx.pypa.io/stable/) so +that pre-commit and its dependencies are installed into an isolated environment +located outside your `typing_extensions` clone. Running pre-commit this way +ensures that you don't accidentally install a version of `typing_extensions` +from PyPI into a virtual environment inside your `typing_extensions` clone, +which could easily happen if pre-commit depended (directly or indirectly) on +`typing_extensions`. If a version of `typing_extensions` from PyPI *was* +installed into a project-local virtual environment, it could lead to +unpredictable results when running `typing_extensions` tests locally. + +To run the linters using uv: + +``` +uvx pre-commit run -a +``` + +Or using pipx: + +``` +pipx run pre-commit run -a +``` + # Workflow for PyPI releases - Make sure you follow the versioning policy in the documentation diff --git a/doc/make.bat b/doc/make.bat index 32bb2452..954237b9 100644 --- a/doc/make.bat +++ b/doc/make.bat @@ -1,35 +1,35 @@ -@ECHO OFF - -pushd %~dp0 - -REM Command file for Sphinx documentation - -if "%SPHINXBUILD%" == "" ( - set SPHINXBUILD=sphinx-build -) -set SOURCEDIR=. -set BUILDDIR=_build - -%SPHINXBUILD% >NUL 2>NUL -if errorlevel 9009 ( - echo. - echo.The 'sphinx-build' command was not found. Make sure you have Sphinx - echo.installed, then set the SPHINXBUILD environment variable to point - echo.to the full path of the 'sphinx-build' executable. Alternatively you - echo.may add the Sphinx directory to PATH. - echo. - echo.If you don't have Sphinx installed, grab it from - echo.https://www.sphinx-doc.org/ - exit /b 1 -) - -if "%1" == "" goto help - -%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% -goto end - -:help -%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% - -:end -popd +@ECHO OFF + +pushd %~dp0 + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set SOURCEDIR=. +set BUILDDIR=_build + +%SPHINXBUILD% >NUL 2>NUL +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.https://www.sphinx-doc.org/ + exit /b 1 +) + +if "%1" == "" goto help + +%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% +goto end + +:help +%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% + +:end +popd diff --git a/test-requirements.txt b/test-requirements.txt deleted file mode 100644 index 4b0fc81e..00000000 --- a/test-requirements.txt +++ /dev/null @@ -1 +0,0 @@ -ruff==0.9.6