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

Move check_inits.py into Pants #19919

Merged
merged 5 commits into from
Sep 22, 2023
Merged
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
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(
Copy link
Contributor

Choose a reason for hiding this comment

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

I know nothing about this. How do you invoke it?

Copy link
Member Author

Choose a reason for hiding this comment

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

It gets executed as part of the test goal! 🎉

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