Skip to content

infra: add griffe to public-symbols check CI #4633

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
31 changes: 31 additions & 0 deletions scripts/eachdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,21 @@ def setup_instparser(instparser):
),
)

listparser = subparsers.add_parser(
"list",
help="List all packages with their relative paths",
)
listparser.set_defaults(func=list_args)
listparser.add_argument(
"--mode",
"-m",
default="DEFAULT",
help=cleandoc(
"""Section of config file to use for target selection configuration.
See description of exec for available options."""
),
)

return parser.parse_args(args)


Expand Down Expand Up @@ -741,6 +756,22 @@ def version_args(args):
print(cfg[args.mode]["version"])


def list_args(args):
rootpath = find_projectroot()
targets = find_targets(args.mode, rootpath)

if not targets:
sys.exit(f"Error: No targets selected (root: {rootpath})")

excluded_dirs = ["docs", "scripts"]

for target in targets:
rel_path = target.relative_to(rootpath)
if any(excluded in str(rel_path) for excluded in excluded_dirs):
continue
print(str(rel_path))


def main():
args = parse_args()
args.func(args)
Expand Down
28 changes: 28 additions & 0 deletions scripts/griffe_check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

OVERALL_EXIT_CODE=0
BRANCH_TO_COMPARE="main"
GRIFFE_CMD="griffe check -v -a $BRANCH_TO_COMPARE "

run_griffe_check() {
local package_spec="$1"
local package_name
local search_path=""

if [[ "$package_spec" == *"/"* ]]; then
Copy link
Member

Choose a reason for hiding this comment

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

sorry my bash isn't that great. when tox calls with no arguments, will it check all directories? This might get annoying for test directories.

Copy link
Member Author

@emdneto emdneto Jun 12, 2025

Choose a reason for hiding this comment

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

Yes, tests will also be checked 😓. I agree it will be annoying. Let me see if we can exclude them.

Copy link
Member Author

@emdneto emdneto Jun 12, 2025

Choose a reason for hiding this comment

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

thanks for the approval, but I'll put it in draft to write the check using griffe Python API. It will be easier to maintain.

search_path=$(echo "$package_spec" | cut -d'/' -f1)
package_name=$(echo "$package_spec" | cut -d'/' -f2)
$GRIFFE_CMD -s "$search_path" "$package_name"
else
package_name="$package_spec"
$GRIFFE_CMD "$package_name"
fi
}

while read -r package; do
if ! run_griffe_check "$package"; then
OVERALL_EXIT_CODE=1
fi
done < <(python "$(dirname "$0")/eachdist.py" list)

exit $OVERALL_EXIT_CODE
7 changes: 6 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -309,11 +309,16 @@ commands_post =
docker-compose down -v

[testenv:public-symbols-check]
basepython: python3
recreate = True
allowlist_externals =
{toxinidir}/scripts/griffe_check.sh
deps =
GitPython==3.1.40
griffe==1.7.3
toml
commands =
; griffe check before to fail fast if there are any issues
{toxinidir}/scripts/griffe_check.sh
python {toxinidir}/scripts/public_symbols_checker.py
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this catch anything than griffe won't?

Copy link
Member Author

@emdneto emdneto Jun 12, 2025

Choose a reason for hiding this comment

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

I don't know, to be honest. I left it here to keep what we have now 😅

Copy link
Contributor

@xrmx xrmx Jun 12, 2025

Choose a reason for hiding this comment

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

Yeah, we can run both for a release and then drop the custom one if it doesn't raise anything.

Copy link
Member Author

Choose a reason for hiding this comment

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

@xrmx I think the main difference is that the public_symbols_checker.py script will check for additions. Griffe will be checking for removed/moved symbols

Copy link
Member

Choose a reason for hiding this comment

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

I think griffe check misses a few other important cases we have related to modifying base classes


[testenv:generate-workflows]
Expand Down
Loading