Skip to content

Use "# %%" as code block separators in gallery examples #2660

@seisman

Description

@seisman

For gallery examples, it usually makes sense to split a long script into multiple blocks using block separators. The Sphinx-Gallery package supports three different "block separators/splitters"

  1. more than 20 # characters, i.e., ###################################################
  2. # %%
  3. #%%

Reference: https://sphinx-gallery.github.io/stable/syntax.html#embed-rest-in-your-example-python-files

The separator #%% will always be formatted to # %% by black, following PEP-8 convention, so this kind of separator can be ignored.

Currently, we use the # separator in our gallery examples (e.g., https://github.com/GenericMappingTools/pygmt/blob/main/examples/gallery/maps/tilemaps.py). I propose to use # %% instead.

The main reason is that # %% is also supported by Visual Studio Code and other editors/IDEs (see https://code.visualstudio.com/docs/python/jupyter-support-py#_jupyter-code-cells), making Python scripts working like Jupyter Notebooks. The # %% also can save us a lot of keystrokes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    maintenanceBoring but important stuff for the core devs

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions