mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-07 12:44:28 +08:00
Improve pre-commit config (#9563)
- Add a few more hooks. These are all very fast, and I've found them useful in other projects:
- Autofixes:
- `trailing-whitespace`: fixes trailing whitespace
- `requirements-txt-fixer`: alphabetises items in `requirements.txt` files
- `end-of-file-fixer`: makes sure every file ends with a single newline character
- `mixed-line-ending`: Makes sure Windows users don't accidentally introduce CRLF line endings into a file that uses LF line endings
- None-autofixes:
- `check-yaml`: loads YAML files to validate syntax
- `check-toml`: loads TOML files to validate syntax
- `check-merge-conflict`: detects merge-conflict strings in files and blocks them from accidentally being committed
- `check-case-conflict`: checks for files with names that would conflict on a case-insensitive filesystem like MacOS HFS+ or Windows FAT; blocks them from being committed.
- Change the bot schedule to quarterly, to reduce noisy PRs
- Change the `black` language target-version to Python 3.10, synching the setting here with the changes that were made to our `pyproject.toml` file in #7538
This commit is contained in:
@@ -8,6 +8,7 @@ from __future__ import annotations
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import urllib.parse
|
||||
from pathlib import Path
|
||||
|
||||
import tomli
|
||||
@@ -220,8 +221,9 @@ def get_precommit_requirements() -> dict[str, SpecifierSet]:
|
||||
if not repo.get("python_requirement", True):
|
||||
continue
|
||||
hook = repo["hooks"][0]
|
||||
package_name, package_rev = hook["id"], repo["rev"]
|
||||
package_specifier = SpecifierSet(f"=={package_rev.removeprefix('v')}")
|
||||
package_name = Path(urllib.parse.urlparse(repo["repo"]).path).name
|
||||
package_rev = repo["rev"].removeprefix("v")
|
||||
package_specifier = SpecifierSet(f"=={package_rev}")
|
||||
precommit_requirements[package_name] = package_specifier
|
||||
for additional_req in hook.get("additional_dependencies", []):
|
||||
req = Requirement(additional_req)
|
||||
|
||||
Reference in New Issue
Block a user