Use "# %%" as code block separators in examples#2662
Conversation
|
/format |
|
Something doesn't work as expected (e.g., https://pygmt-dev--2662.org.readthedocs.build/en/2662/tutorials/basics/coastlines.html): |
This issue occurs in examples in which we use """
# sphinx_gallery_thumbnail_number = x
# %%
import pygmtto """
# %%
# sphinx_gallery_thumbnail_number = x
import pygmt |
|
Still WIP? |
Should be ready for review 🙂. |
| @@ -74,7 +73,8 @@ | |||
| ) | |||
| fig.show() | |||
|
|
|||
There was a problem hiding this comment.
The number of blank lines above the # %% separator is inconsistent. For example, there is only one blank line near line 56, but two blank lines near line 77. Maybe we should have only one blank line above # %%, although it really doesn't matter much.
There was a problem hiding this comment.
This is because there are two blank lines in case of a following subsection, otherwise only one blank is used. This is the concept in some of the tutorials. For me, this makes it easier to read the script, because it gives a bit more structure, especially for longer ones. Thus, I tried / decided to use this consistently across all examples. But as you mentioned, this doesn't matter much, I can change it to have only one blank line before subsections.
There was a problem hiding this comment.
This is because there are two blank lines in case of a following subsection, otherwise only one blank is used.
OK. That makes sense to me.
I had a quick look at the Sphinx-Gallery source code. It seems that anything between the docstring and the first Your fix in d375ec5 works as expected, but the biggest limitation is that there must be a blank line between I think it makes more sense to have |
Yes, you are completly right! I was / am also not happy with this blank line. But as I tried several sequences at the beginning of the code and only the one in commit d375ec5 worked without producing an empty code block, I accepted the blank line.
I am fine with this solution and can change it later the day. If we go with this solution, I should probably also submit a PR to update the Contributors Guide at https://www.pygmt.org/dev/contributing.html#contributing-tutorials. |
This is done in the commits 2a9c466, d3d5b3b, and d24a45c.
Please see PR #2675 for this update. |



Description of proposed changes
This PR aims to replace the code block separator
###############################################################################by# %%and also add this separator at thte beginning of the code:Fixes #2660
Preview: https://pygmt-dev--2662.org.readthedocs.build/en/2662/tutorials/basics/coastlines.html
Reminders
make formatandmake checkto make sure the code follows the style guide.doc/api/index.rst.Slash Commands
You can write slash commands (
/command) in the first line of a comment to performspecific operations. Supported slash commands are:
/format: automatically format and lint the code/test-gmt-dev: run full tests on the latest GMT development version