From 61040c473896542d3656893550d47560cba7a000 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Thu, 3 Sep 2026 17:59:16 +0800 Subject: [PATCH] CI: Improve the Style Checks workflow to enforce underscores for both files and directories --- .github/workflows/style_checks.yaml | 16 ++++++++++++---- doc/contributing.md | 7 ++++--- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/.github/workflows/style_checks.yaml b/.github/workflows/style_checks.yaml index 8679c979e53..391a0baf3fd 100644 --- a/.github/workflows/style_checks.yaml +++ b/.github/workflows/style_checks.yaml @@ -56,13 +56,21 @@ jobs: exit $nfiles fi - - name: Ensure hyphens are not used in names of directories and Python files + - name: Ensure hyphens are not used in names of directories and files run: | - git ls-files '*.py' | grep '-' > output.txt || true - git ls-tree -rd --name-only HEAD | grep '-' >> output.txt || true + # Paths that allows hyphens in their names. + allowed=( + '^\.pre-commit-config\.yaml$' + '^\.github/release-drafter\.yml$' + '^\.github/ISSUE_TEMPLATE/[0-9]+-' + '^doc/_static/' + '^pygmt/tests/baseline/' + '^\.github/workflows/' + ) + git ls-files | grep '-' | grep -v -E "$(IFS='|'; echo "${allowed[*]}")" > output.txt || true nfiles=$(wc --lines output.txt | awk '{print $1}') if [[ $nfiles > 0 ]]; then - echo "Following directories/files use hyphens in file names:" + echo "Following directories/files use hyphens in their names:" cat output.txt rm output.txt exit $nfiles diff --git a/doc/contributing.md b/doc/contributing.md index c2db26fe7d0..d3e91d1f29d 100644 --- a/doc/contributing.md +++ b/doc/contributing.md @@ -130,9 +130,10 @@ our tests. This way, the *main* branch is always stable. integrated separately. - Bug fixes should be submitted in separate PRs. * How to write and submit a PR - - Use underscores for all Python (\*.py) files as per - [PEP8](https://www.python.org/dev/peps/pep-0008/), not hyphens. Directory names - should also use underscores instead of hyphens. + - Use underscores, not hyphens, in the names of all files and directories, as per + [PEP8](https://www.python.org/dev/peps/pep-0008/) for Python (\*.py) files. A few + exceptions are allowed (e.g., `.pre-commit-config.yaml`) and are listed + in the [style checks](.github/workflows/style_checks.yaml) workflow. - Describe what your PR changes and *why* this is a good thing. Be as specific as you can. The PR description is how we keep track of the changes made to the project over time.