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

CI: Require at least one code block separator for example files in the Style Checks workflow #2810

Merged
merged 7 commits into from
Nov 18, 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
11 changes: 11 additions & 0 deletions .github/workflows/style_checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,14 @@ jobs:
find . -type f -not -path '*/\.git/*' -exec grep -Iq . {} \; -exec dos2unix --quiet {} \;
find . -type f -not -path '*/\.git/*' -exec grep -Iq . {} \; -exec chmod 644 {} \;
if [[ $(git ls-files -m) ]]; then git --no-pager diff HEAD; exit 1; fi

- name: Ensure example scripts have at least one code block separator
run: |
grep --files-without-match '# %%' $(find 'examples' -name '*.py') > output.txt
nfiles=$(wc --lines output.txt | awk '{print $1}')
if [[ $nfiles > 0 ]]; then
echo "Code block separator '# %%' is required in following example files:"
cat output.txt
rm output.txt
exit $nfiles
fi
7 changes: 7 additions & 0 deletions doc/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,13 @@ words bridged only by consonants, such as `distcalc`, and `crossprofile`. This
convention is not applied by the code checking tools, but the PyGMT maintainers
will comment on any pull requests as needed.

When working on a tutorial or a gallery plot, it is good practice to use code
block separators to split a long script into multiple blocks. The separators also
make it possible to run the script like a Jupyter notebook in some modern text
editors or IDEs. We consistently use `# %%` as code block separators (please
refer to [issue #2660](https://github.com/GenericMappingTools/pygmt/issues/2660)
for the discussions) and require at least one separator in all example files.

We also use [ruff](https://docs.astral.sh/ruff) and
[pylint](https://pylint.pycqa.org/) to check the quality of the code and quickly catch
common errors.
Expand Down
Loading