Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

autoupdate mypy #4943

Merged
merged 8 commits into from
Feb 23, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/workflows/ci-pre-commit-autoupdate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ jobs:
uses: actions/setup-python@v2
- name: upgrade pip
run: python -m pip install --upgrade pip
- name: install pre-commit
run: python -m pip install --upgrade pre-commit
- name: install dependencies
run: python -m pip install --upgrade pre-commit pyyaml packaging
- name: version info
run: python -m pip list
- name: autoupdate
Expand All @@ -35,7 +35,10 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
EXECUTE_COMMANDS: |
python -m pre_commit autoupdate
python .github/workflows/sync_linter_versions.py .pre-commit-config.yaml ci/requirements/mypy_only
COMMIT_MESSAGE: 'pre-commit: autoupdate hook versions'
COMMIT_NAME: 'github-actions[bot]'
COMMIT_EMAIL: 'github-actions[bot]@users.noreply.github.com'
PR_TITLE: 'pre-commit: autoupdate hook versions'
PR_BRANCH_PREFIX: 'pre-commit/'
PR_BRANCH_NAME: 'autoupdate-${PR_ID}'
54 changes: 54 additions & 0 deletions .github/workflows/sync_linter_versions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env python
import argparse
import pathlib

import yaml
from packaging import version


def extract_version(config, name):
repos = config.get("repos")
if repos is None:
raise ValueError("invalid pre-commit configuration")

for repo in repos:
hooks = repo["hooks"]
hook_names = [hook["id"] for hook in hooks]
if name in hook_names:
return version.parse(repo["rev"])

raise KeyError(f"cannot find hook {name!r} in the pre-commit configuration")


if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--dry", action="store_true")
parser.add_argument(
metavar="pre-commit-config", dest="pre_commit_config", type=pathlib.Path
)
parser.add_argument("requirements", type=pathlib.Path)
args = parser.parse_args()

with args.pre_commit_config.open() as f:
config = yaml.safe_load(f)

mypy_version = extract_version(config, "mypy")

requirements = args.requirements.read_text()
new_requirements = "\n".join(
[
line if not line.startswith("mypy=") else f"mypy={mypy_version}"
keewis marked this conversation as resolved.
Show resolved Hide resolved
for line in requirements.split("\n")
]
)

if args.dry:
separator = "\n" + "—" * 80 + "\n"
print(
"contents of the new requirements file:",
new_requirements,
sep=separator,
end=separator,
)
else:
args.requirements.write_text(new_requirements)