-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
CI, STYLE sync flake8 versions #40783
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c2560c7
sync flake8 versions
MarcoGorelli 5de5ac7
Merge remote-tracking branch 'upstream/master' into sync-flake8-version
MarcoGorelli f4c15ab
noop
MarcoGorelli 6652fe8
Merge remote-tracking branch 'upstream/master' into sync-flake8-version
MarcoGorelli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
""" | ||
Check that the flake8 pins are the same in: | ||
|
||
- environment.yml | ||
- .pre-commit-config.yaml, in the flake8 hook | ||
- .pre-commit-config.yaml, in the additional dependencies of the yesqa hook | ||
|
||
The flake8 hook revision in .pre-commit-config.yaml is taken as the reference revision. | ||
|
||
Usage: either | ||
|
||
- ``python scripts/sync_flake8_versions.py``, or | ||
- ``pre-commit run sync-flake8-versions --all-files``. | ||
""" | ||
import sys | ||
from typing import ( | ||
Any, | ||
Mapping, | ||
NamedTuple, | ||
Sequence, | ||
Tuple, | ||
TypeVar, | ||
) | ||
|
||
import yaml | ||
|
||
|
||
class Revisions(NamedTuple): | ||
precommit_rev: str | ||
precommit_yesqa_rev: str | ||
environment_rev: str | ||
|
||
|
||
YamlMapping = Mapping[str, Any] | ||
Repo = TypeVar("Repo", bound=YamlMapping) | ||
|
||
|
||
def _get_repo_hook(repos: Sequence[Repo], hook_name: str) -> Tuple[Repo, YamlMapping]: | ||
for repo in repos: | ||
for hook in repo["hooks"]: | ||
if hook["id"] == hook_name: | ||
return repo, hook | ||
else: | ||
raise RuntimeError(f"Repo with hook {hook_name} not found") | ||
|
||
|
||
def get_revisions(precommit_config: YamlMapping, environment: YamlMapping) -> Revisions: | ||
repos = precommit_config["repos"] | ||
flake8_repo, _ = _get_repo_hook(repos, "flake8") | ||
precommit_rev = flake8_repo["rev"] | ||
|
||
_, yesqa_hook = _get_repo_hook(repos, "yesqa") | ||
additional_dependencies = yesqa_hook.get("additional_dependencies", []) | ||
for dep in additional_dependencies: | ||
if "==" in dep: | ||
pkg, rev = dep.split("==", maxsplit=1) | ||
if pkg == "flake8": | ||
precommit_yesqa_rev = rev | ||
break | ||
else: | ||
raise RuntimeError( | ||
"flake8 not found, or not pinned, in additional dependencies of yesqa " | ||
"hook in .pre-commit-config.yaml" | ||
) | ||
|
||
deps = environment["dependencies"] | ||
for dep in deps: | ||
if isinstance(dep, str) and "=" in dep: | ||
pkg, rev = dep.split("=", maxsplit=1) | ||
if pkg == "flake8": | ||
environment_rev = rev | ||
break | ||
else: | ||
raise RuntimeError("flake8 not found, or not pinned, in environment.yml") | ||
|
||
return Revisions(precommit_rev, precommit_yesqa_rev, environment_rev) | ||
|
||
|
||
if __name__ == "__main__": | ||
with open(".pre-commit-config.yaml") as fd: | ||
precommit_config = yaml.safe_load(fd) | ||
with open("environment.yml") as fd: | ||
environment = yaml.safe_load(fd) | ||
|
||
revisions = get_revisions(precommit_config, environment) | ||
|
||
if revisions.environment_rev != revisions.precommit_rev: | ||
sys.stdout.write( | ||
f"flake8 pin in environment.yml is {revisions.environment_rev}, " | ||
f"should be {revisions.precommit_rev}\n" | ||
) | ||
sys.exit(1) | ||
|
||
if revisions.precommit_yesqa_rev != revisions.precommit_rev: | ||
sys.stdout.write( | ||
f"flake8 pin in yesqa is {revisions.precommit_yesqa_rev}, " | ||
f"should be {revisions.precommit_rev}\n" | ||
) | ||
sys.exit(1) | ||
|
||
sys.exit(0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from ..sync_flake8_versions import ( | ||
Revisions, | ||
get_revisions, | ||
) | ||
|
||
|
||
def test_get_revisions(): | ||
precommit_config = { | ||
"repos": [ | ||
{ | ||
"repo": "https://gitlab.com/pycqa/flake8", | ||
"rev": "foo", | ||
"hooks": [{"id": "flake8"}], | ||
}, | ||
{ | ||
"repo": "https://github.com/asottile/yesqa", | ||
"rev": "v1.2.2", | ||
"hooks": [{"id": "yesqa", "additional_dependencies": ["flake8==bar"]}], | ||
}, | ||
] | ||
} | ||
environment = {"dependencies": ["flake8=qux"]} | ||
result = get_revisions(precommit_config, environment) | ||
expected = Revisions("foo", "bar", "qux") | ||
assert result == expected |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we have 1 build where this is unpinned?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, but there's the risk that there's be another annoying CI failure like #40457
If there's a new flake8 release, this'll get bumped up anyway by the weekly autoupdate job
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah this is ok then.