Skip to content

Commit

Permalink
Move check_inits.py into Pants (pantsbuild#19919)
Browse files Browse the repository at this point in the history
This change moves the pre-commit-hook (which ummm is that run in
CI?!?!?!) into an `experimental_test_shell_command`.
  • Loading branch information
thejcannon authored Sep 22, 2023
1 parent 990dc1b commit 2b91b8a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 39 deletions.
28 changes: 28 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,31 @@ remote_environment(
name="buildgrid_remote",
python_bootstrap_search_path=["<PATH>"],
)

files(
name="all-__init__.py-files",
sources=[
"**/__init__.py",
"!testprojects/**",
# These are explicit namespace packages
"!src/python/pants/__init__.py",
"!src/python/pants/testutil/__init__.py",
],
)

# NB: This should be in `lint` when we implement `lint` in https://github.com/pantsbuild/pants/issues/17729
experimental_test_shell_command(
name="checks-empty-init-files",
command="""
NONEMPTY_INITS=$(find . -type f -name "*.py" -size +0);
if [ -n "$NONEMPTY_INITS" ]; then
echo "All \\`__init__.py\\` file should be empty, but the following had content:";
echo "$NONEMPTY_INITS";
exit 1;
fi
exit 0;
""",
tools=["echo", "find"],
execution_dependencies=[":all-__init__.py-files"],
)
36 changes: 0 additions & 36 deletions build-support/bin/check_inits.py

This file was deleted.

3 changes: 0 additions & 3 deletions build-support/githooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,3 @@ if git diff "${MERGE_BASE}" --name-only | grep src/python/pants_release/generate
echo "* Checking GitHub workflows generation"
$_PANTS_PRE_COMMIT_BINARY run src/python/pants_release/generate_github_workflows.py -- --check
fi

echo "* Checking __init__.py files"
$_PANTS_PRE_COMMIT_BINARY run build-support/bin/check_inits.py

0 comments on commit 2b91b8a

Please sign in to comment.