Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,13 @@ repos:
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: local
hooks:
- id: check_deps_changes
name: Check for dependency changes
entry: python -m scripts.githook_deps_check
language: system
always_run: true

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider setting always_run: false to improve performance, as the script likely doesn't need to run on every commit.

stages: [post-checkout, post-merge]
verbose: true
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,12 @@ format: ## Run black and isort code formatter
format-modified: ## Run black and isort code formatter on modified files
($(VENV_RUN); python -m isort `git ls-files -m | grep '\.py$$' | xargs`; python -m black `git ls-files -m | grep '\.py$$' | xargs` )

init-precommit: ## install te pre-commit hook into your local git repository
init-precommit: ## install the pre-commit hook into your local git repository
($(VENV_RUN); pre-commit install)
Comment on lines +277 to 278

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

syntax: typo in comment: 'te' should be 'the'


init-githooks: ## install all githooks into your local git repository
($(VENV_RUN); pre-commit install -t pre-commit -t post-checkout -t post-merge)

clean: ## Clean up (npm dependencies, downloaded infrastructure code, compiled Java classes)
rm -rf .filesystem
rm -rf localstack/dashboard/web/node_modules
Expand Down
49 changes: 49 additions & 0 deletions scripts/githook_deps_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""
Git hook that checks if there's been any updates to a set of predefined files

This is for example useful to be alerted if there might be a need to reinstall the project
"""

import os
import subprocess

from rich.console import Console

c = Console()

DISABLE_CHECKS_ENV_VAR = "GITHOOK_DISABLE_DEPS_CHECK"

# basically anything that might lead to issues with an existing local setup
files_to_watch = ["setup.py", "setup.cfg", "requirements.txt", "Makefile", "pyproject.toml"]

# TODO: alert on rebase
# TODO: alert on pull
# TODO: compare providers
# TODO: compare plugins


if __name__ == "__main__":
if os.environ.get(DISABLE_CHECKS_ENV_VAR, "0") == "1":
exit(0)
Comment on lines +26 to +27

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Add a log message when checks are disabled to inform the user.


envs = {k: v for k, v in os.environ.items() if k.startswith("PRE_COMMIT")}

# checkout
from_commit = envs.get("PRE_COMMIT_FROM_REF")
to_commit = envs.get("PRE_COMMIT_TO_REF")

if from_commit and to_commit:
r = subprocess.run(
["git", "diff", "--name-only", from_commit, to_commit], capture_output=True
)
Comment on lines +35 to +38

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Use 'git diff --name-only' with '--no-renames' flag to avoid issues with renamed files.


files = r.stdout.decode().splitlines()

for file in files_to_watch:
if file in files:
c.print(
f"[red]ATTENTION![/red] Found a change in file [red]{file}[/red] during the checkout."
)
c.print(
f"\t>> show changes: [bold]git diff {from_commit[:8]}:{file} {to_commit[:8]}:{file}[/bold]\n"
)
Comment on lines +42 to +49

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider using a set for faster lookup of changed files.