Skip to content

Commit 4054948

Browse files
authored
Setup renovate for updating dependencies (#11565)
1 parent ea6dac4 commit 4054948

File tree

3 files changed

+46
-56
lines changed

3 files changed

+46
-56
lines changed

.github/renovate.json

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
3+
"dependencyDashboard": true,
4+
"suppressNotifications": ["prEditedNotification"],
5+
"extends": ["config:base"],
6+
"labels": ["dependencies"],
7+
"pre-commit": {
8+
"enabled": true
9+
},
10+
"customManagers": [
11+
{
12+
"customType": "regex",
13+
"fileMatch": ["^pyproject.toml$"],
14+
"matchStrings": [
15+
"\\n\\[tool\\.typeshed\\]\\npyright_version\\s*=\\s*(\"|')(?<currentValue>[\\d.]*?)(\"|')\\s*?\\n"
16+
],
17+
"depNameTemplate": "pyright",
18+
"datasourceTemplate": "npm"
19+
}
20+
],
21+
"packageRules": [
22+
{
23+
"groupName": "GitHub Actions update",
24+
"matchManagers": ["github-actions"],
25+
"description": "Quarterly update of GitHub Action dependencies",
26+
"separateMajorMinor": "false",
27+
"schedule": ["every 3 months on the first day of the month"]
28+
},
29+
{
30+
"groupName": "Quarterly dependency update",
31+
"matchManagers": ["pip_requirements", "pre-commit"],
32+
"excludePackageNames": ["pytype", "pyright"],
33+
"description": "Quarterly update of most test dependencies",
34+
"separateMajorMinor": "false",
35+
"schedule": ["every 3 months on the first day of the month"]
36+
},
37+
{
38+
"groupName": "Daily dependency update",
39+
"matchManagers": ["pip_requirements", "regex"],
40+
"matchPackageNames": ["pytype", "pyright"],
41+
"description": "Daily update of pyright and pytype",
42+
"separateMajorMinor": "false",
43+
"schedule": ["daily"]
44+
}
45+
]
46+
}

requirements-tests.txt

-4
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,9 @@ aiohttp==3.9.3
1515
packaging==23.2
1616
pathspec>=0.11.1
1717
pre-commit
18-
pyyaml==6.0.1
1918
stubdefaulter==0.1.0
2019
termcolor>=2.3
2120
tomli==2.0.1
2221
tomlkit==0.12.3
2322
typing_extensions>=4.9.0rc1
2423
uv
25-
26-
# Type stubs used to type check our scripts.
27-
types-pyyaml>=6.0.12.7

tests/check_consistent.py

-52
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,7 @@
88
import os
99
import re
1010
import sys
11-
import urllib.parse
1211
from pathlib import Path
13-
from typing import TypedDict
14-
15-
import yaml
16-
from packaging.requirements import Requirement
17-
from packaging.specifiers import SpecifierSet
1812

1913
from parse_metadata import read_metadata
2014
from utils import (
@@ -143,34 +137,6 @@ def check_metadata() -> None:
143137
read_metadata(distribution)
144138

145139

146-
class PreCommitConfigRepos(TypedDict):
147-
hooks: list[dict[str, str]]
148-
repo: str
149-
150-
151-
class PreCommitConfig(TypedDict):
152-
repos: list[PreCommitConfigRepos]
153-
154-
155-
def get_precommit_requirements() -> dict[str, SpecifierSet]:
156-
with open(".pre-commit-config.yaml", encoding="UTF-8") as precommit_file:
157-
precommit = precommit_file.read()
158-
yam: PreCommitConfig = yaml.load(precommit, Loader=yaml.Loader)
159-
precommit_requirements: dict[str, SpecifierSet] = {}
160-
for repo in yam["repos"]:
161-
package_rev = repo.get("rev")
162-
if not isinstance(package_rev, str):
163-
continue
164-
package_name = Path(urllib.parse.urlparse(repo["repo"]).path).name
165-
package_specifier = SpecifierSet(f"=={package_rev.removeprefix('v')}")
166-
precommit_requirements[package_name] = package_specifier
167-
for hook in repo["hooks"]:
168-
for additional_req in hook.get("additional_dependencies", ()):
169-
req = Requirement(additional_req)
170-
precommit_requirements[req.name] = req.specifier
171-
return precommit_requirements
172-
173-
174140
def check_requirement_pins() -> None:
175141
"""Check that type checkers and linters are pinned to an exact version."""
176142
requirements = parse_requirements()
@@ -182,23 +148,6 @@ def check_requirement_pins() -> None:
182148
assert str(spec).startswith("=="), msg
183149

184150

185-
def check_precommit_requirements() -> None:
186-
"""Check that the requirements in the requirements file and .pre-commit-config.yaml match."""
187-
requirements_txt_requirements = parse_requirements()
188-
precommit_requirements = get_precommit_requirements()
189-
no_txt_entry_msg = f"All pre-commit requirements must also be listed in `{REQS_FILE}` (missing {{requirement!r}})"
190-
for requirement, specifier in precommit_requirements.items():
191-
# annoying: the Ruff and Black repos for pre-commit are different to the names in the requirements file
192-
if requirement in {"ruff-pre-commit", "black-pre-commit-mirror"}:
193-
requirement = requirement.split("-")[0]
194-
assert requirement in requirements_txt_requirements, no_txt_entry_msg.format(requirement=requirement)
195-
specifier_mismatch = (
196-
f'Specifier "{specifier}" for {requirement!r} in `.pre-commit-config.yaml` '
197-
f'does not match specifier "{requirements_txt_requirements[requirement].specifier}" in `{REQS_FILE}`'
198-
)
199-
assert specifier == requirements_txt_requirements[requirement].specifier, specifier_mismatch
200-
201-
202151
if __name__ == "__main__":
203152
assert sys.version_info >= (3, 9), "Python 3.9+ is required to run this test"
204153
check_stdlib()
@@ -208,4 +157,3 @@ def check_precommit_requirements() -> None:
208157
check_no_symlinks()
209158
check_test_cases()
210159
check_requirement_pins()
211-
check_precommit_requirements()

0 commit comments

Comments
 (0)