Skip to content

Commit

Permalink
ENH: Use yaml anchors for pre-commit hooks additional dependencies (#…
Browse files Browse the repository at this point in the history
…44177)

* ENH: Use yaml anchors for pre-commit hooks additional dependencies

* ENH: add flake8 to env additonal deps
  • Loading branch information
trallard authored Oct 25, 2021
1 parent 82f5395 commit d8440f1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 34 deletions.
15 changes: 6 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ repos:
rev: 3.9.2
hooks:
- id: flake8
additional_dependencies:
- flake8-comprehensions==3.1.0
- flake8-bugbear==21.3.2
- pandas-dev-flaker==0.2.0
additional_dependencies: &flake8_dependencies
- flake8==3.9.2
- flake8-comprehensions==3.1.0
- flake8-bugbear==21.3.2
- pandas-dev-flaker==0.2.0
- id: flake8
alias: flake8-cython
name: flake8 (cython)
Expand Down Expand Up @@ -76,11 +77,7 @@ repos:
rev: v1.2.3
hooks:
- id: yesqa
additional_dependencies:
- flake8==3.9.2
- flake8-comprehensions==3.1.0
- flake8-bugbear==21.3.2
- pandas-dev-flaker==0.2.0
additional_dependencies: *flake8_dependencies
- repo: local
hooks:
- id: pyright
Expand Down
26 changes: 1 addition & 25 deletions scripts/sync_flake8_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,9 @@ def _conda_to_pip_compat(dep):

def _validate_additional_dependencies(
flake8_additional_dependencies,
yesqa_additional_dependencies,
environment_additional_dependencies,
) -> None:
for dep in flake8_additional_dependencies:
if dep not in yesqa_additional_dependencies:
sys.stdout.write(
f"Mismatch of '{dep.name}' version between 'flake8' "
"and 'yesqa' in '.pre-commit-config.yaml'\n"
)
sys.exit(1)
if dep not in environment_additional_dependencies:
sys.stdout.write(
f"Mismatch of '{dep.name}' version between 'enviroment.yml' "
Expand All @@ -94,13 +87,6 @@ def _validate_revisions(revisions):
)
sys.exit(1)

if revisions.yesqa != revisions.pre_commit:
sys.stdout.write(
f"{revisions.name} in 'yesqa' does not match "
"in 'flake8' from 'pre-commit'\n"
)
sys.exit(1)


def _process_dependencies(deps):
for dep in deps:
Expand Down Expand Up @@ -130,29 +116,19 @@ def get_revisions(
else:
flake8_additional_dependencies.append(dep)

_, yesqa_hook = _get_repo_hook(repos, "yesqa")
yesqa_additional_dependencies = []
for dep in _process_dependencies(yesqa_hook.get("additional_dependencies", [])):
if dep.name == "flake8":
flake8_revisions.yesqa = dep
elif dep.name == "pandas-dev-flaker":
pandas_dev_flaker_revisions.yesqa = dep
else:
yesqa_additional_dependencies.append(dep)

environment_dependencies = environment["dependencies"]
environment_additional_dependencies = []
for dep in _process_dependencies(environment_dependencies):
if dep.name == "flake8":
flake8_revisions.environment = dep
environment_additional_dependencies.append(dep)
elif dep.name == "pandas-dev-flaker":
pandas_dev_flaker_revisions.environment = dep
else:
environment_additional_dependencies.append(dep)

_validate_additional_dependencies(
flake8_additional_dependencies,
yesqa_additional_dependencies,
environment_additional_dependencies,
)

Expand Down

0 comments on commit d8440f1

Please sign in to comment.