diff --git a/.flake8 b/.flake8 new file mode 100644 index 000000000..f4546adb4 --- /dev/null +++ b/.flake8 @@ -0,0 +1,2 @@ +[flake8] +max_line_length = 88 diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 839471ed0..b1d63fbf3 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -8,4 +8,4 @@ It should describe the change to be made. Most PRs will require an issue number. Trivial changes, like fixing a typo, do not need an issue. ---> \ No newline at end of file +--> diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3267db717..f2b16054d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,8 +19,6 @@ jobs: cache: pip - name: Build docs run: make html - - name: Check markup - run: make check - name: Link check run: make linkcheck continue-on-error: true diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 000000000..c78a4053a --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,14 @@ +name: Lint + +on: [push, pull_request, workflow_dispatch] + +jobs: + lint: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: "3.x" + - uses: pre-commit/action@v3.0.0 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..e6b335c32 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,47 @@ +repos: + - repo: https://github.com/asottile/pyupgrade + rev: v3.10.1 + hooks: + - id: pyupgrade + args: [--py38-plus] + + - repo: https://github.com/psf/black + rev: 23.7.0 + hooks: + - id: black + args: [--skip-string-normalization] + + - repo: https://github.com/PyCQA/isort + rev: 5.12.0 + hooks: + - id: isort + args: [--profile=black] + + - repo: https://github.com/PyCQA/flake8 + rev: 6.1.0 + hooks: + - id: flake8 + additional_dependencies: [flake8-2020] + + - repo: https://github.com/sphinx-contrib/sphinx-lint + rev: v0.6.7 + hooks: + - id: sphinx-lint + args: ["--enable=default-role"] + + - repo: https://github.com/pre-commit/pygrep-hooks + rev: v1.10.0 + hooks: + - id: python-check-blanket-noqa + + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 + hooks: + - id: check-json + - id: check-merge-conflict + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace + +ci: + autoupdate_schedule: quarterly diff --git a/LICENSE b/LICENSE index 28289e879..4594fb738 100644 --- a/LICENSE +++ b/LICENSE @@ -113,4 +113,4 @@ Affirmer's express Statement of Purpose. CC0 or use of the Work. For more information, please see - \ No newline at end of file + diff --git a/Makefile b/Makefile index d86ebf533..17141ac2d 100644 --- a/Makefile +++ b/Makefile @@ -38,6 +38,7 @@ help: @echo " linkcheck to check all external links for integrity" @echo " doctest to run all doctests embedded in the documentation (if enabled)" @echo " check to run a check for frequent markup errors" + @echo " lint to lint all the files" @echo " versions to update release cycle after changing release-cycle.json" .PHONY: clean @@ -183,6 +184,11 @@ check: ensure-venv # Ignore the tools and venv dirs and check that the default role is not used. $(SPHINXLINT) -i tools -i $(VENVDIR) --enable default-role +.PHONY: lint +lint: venv + $(VENVDIR)/bin/python3 -m pre_commit --version > /dev/null || $(VENVDIR)/bin/python3 -m pip install pre-commit + $(VENVDIR)/bin/python3 -m pre_commit run --all-files + .PHONY: serve serve: @echo "The 'serve' target was removed, use 'htmlview' instead" \ diff --git a/_extensions/custom_roles.py b/_extensions/custom_roles.py index 2c4e9d9d0..f8c9bb895 100644 --- a/_extensions/custom_roles.py +++ b/_extensions/custom_roles.py @@ -35,8 +35,9 @@ def role(name, rawtext, text, lineno, inliner, _options=None, _content=None): if text.startswith('!'): node = nodes.literal(rawtext, text[1:]) else: - node = nodes.reference(rawtext, '', nodes.literal(rawtext, text), - refuri=url, internal=False) + node = nodes.reference( + rawtext, '', nodes.literal(rawtext, text), refuri=url, internal=False + ) return [node], [] return role diff --git a/conf.py b/conf.py index 15823481b..36be6625c 100644 --- a/conf.py +++ b/conf.py @@ -34,6 +34,7 @@ '.github', ] + def _asset_hash(path: os.PathLike[str]) -> str: """Append a `?digest=` to an url based on the file content.""" full_path = (Path(html_static_path[0]) / path).resolve() @@ -59,19 +60,19 @@ def _asset_hash(path: os.PathLike[str]) -> str: linkcheck_allowed_redirects = { # Edit page - r"https://docs.google.com/document/d/.*/": r"https://docs.google.com/document/d/.*/edit", + r"https://docs.google.com/document/d/.*/": r"https://docs.google.com/document/d/.*/edit", # noqa: E501 # Canonical r"https://docs.python.org/": r"https://docs.python.org/3/", # Translations with country codes r"https://docs.python.org/[a-z-]+/": r"https://docs.python.org/[a-z-]+/3/", # Personal /my/ links redirect to login page - r"https://discuss.python.org/my/.*": r"https://discuss.python.org/login-preferences", + r"https://discuss.python.org/my/.*": r"https://discuss.python.org/login-preferences", # noqa: E501 # Login page - r"https://github.com/python/core-workflow/issues/new.*": r"https://github.com/login.*", + r"https://github.com/python/core-workflow/issues/new.*": r"https://github.com/login.*", # noqa: E501 # Archive redirect - r"https://github.com/python/cpython/archive/main.zip": r"https://codeload.github.com/python/cpython/zip/refs/heads/main", + r"https://github.com/python/cpython/archive/main.zip": r"https://codeload.github.com/python/cpython/zip/refs/heads/main", # noqa: E501 # Blob to tree - r"https://github.com/python/cpython/blob/.*": r"https://github.com/python/cpython/tree/.*", + r"https://github.com/python/cpython/blob/.*": r"https://github.com/python/cpython/tree/.*", # noqa: E501 # HackMD shortcuts r"https://hackmd.io/s/.*": r"https://hackmd.io/@.*", # Read the Docs diff --git a/developer-workflow/lang-changes.rst b/developer-workflow/lang-changes.rst index 7d663530c..19cc42dd1 100644 --- a/developer-workflow/lang-changes.rst +++ b/developer-workflow/lang-changes.rst @@ -86,4 +86,3 @@ to inform others who may propose a similar language change in the future. .. _Ideas Discourse category: https://discuss.python.org/c/ideas/6 .. _Status Quo Wins a Stalemate: https://www.curiousefficiency.org/posts/2011/02/status-quo-wins-stalemate.html .. _Justifying Python Language Changes: https://www.curiousefficiency.org/posts/2011/02/justifying-python-language-changes.html -