GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add sphinx extension myst-nb to enable writing executable Markdown notebooks by seisman · Pull Request #3379 · GenericMappingTools/pygmt

Conversation

@seisman

@seisman seisman commented Aug 6, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Description of proposed changes

This PR adds the Sphinx extension myst-nb to enable executing code cells in a file and insert the output directly into the file. The file format can be (1) ReST; (2) Plain Markdown; (3) Jupyter Notebooks; (4) MyST text-based notebooks. See https://myst-nb.readthedocs.io/en/latest/authoring/basics.html for more details.

The text-based MyST notebook is the most appealing format. To convert a plain Markdown file into a MyST notebook, we just need to do two things:

  1. Add metadata at the top of a markdown file. The simplest example is:
---
file_format: mystnb
---
  1. Write codes using the following syntax
```{code-cell}
a = "This is some"
b = "Python code!"
print(f"{a} {b}")
```

This PR also updates the install.md file as an example showing how the extension works. In the installation guides, we provide a test script and include an external image (added in #3249) to show how the output looks like. It's not ideal since the image may be outdated when we update the test script. The myst-nb extension can execute the codes and directly insert the output image below the codes, so the codes and the image are always consistent.

Preview: https://pygmt-dev--3379.org.readthedocs.build/en/3379/install.html#testing-your-install

Notes:

  1. The myst-parser extension is removed because it's required by myst-nb and is automatically enabled by myst-nb.
  2. The myst-nb extension is necessary for writing documentation that needs images. For example, an image is needed to explain justification codes well.
  3. This extension can't replace sphinx-gallery now, but maybe it can in the future (xref Enable thumbnail galleries of notebooks executablebooks/MyST-NB#396)
  4. myst-nb is one of the subprojects of The Executable Books Project. We're also using their sphinx-copybutton and sphinx-design extensions. Maybe one day we should consider migrating to their Jupyter Book project, which is built on top of Sphinx and a collection of Sphinx extensions.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
seisman added 2 commits August 6, 2024 13:43
@seisman
Add sphinx extension myst-nb and remove myst-parser
d0059c9
myst-nb depends on myst-parser.
@seisman
Exclude .ipynb and .py files generated by sphinx-gallery
fba97ba
@seisman seisman changed the title Add sphinx extension myst-nb to enable executing code cells in Markdown and insert the output directly Add sphinx extension myst-nb to enable writing executable Markdown notebooks Aug 6, 2024
seisman
seisman commented Aug 6, 2024
View reviewed changes
Comment thread doc/install.md
@@ -1,3 +1,7 @@
---

@seisman seisman Aug 6, 2024

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Add metadata at the top so that myst-nb can recognize it as a MyST notebook.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread doc/install.md
Comment on lines +241 to +243
---
tags: [remove-stdout]
mystnb:
image: center
---

@seisman seisman Aug 6, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

---
tags: [remove-stdout]
---

These lines are cell-level metadata for controlling the format of the output. Usually it's not necessary. Here remove-stdout is necessary to hide the long output from pygmt.show_versions().

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread doc/install.md
fig.text(position="MC", text="PyGMT", font="80p,Helvetica-Bold,red@75")
fig.show()
```
![pygmt-get-started](https://github.com/GenericMappingTools/pygmt/assets/3974108/f7f51484-8640-4b58-ae5b-6c71e7150f7a){.align-center width="70%"}

@seisman seisman Aug 6, 2024

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

No need to include the external image.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

weiji14 reacted with hooray emoji
All reactions
  • 🎉 1 reaction
@seisman seisman added the documentation Improvements or additions to documentation label Aug 6, 2024
@seisman seisman added this to the 0.13.0 milestone Aug 6, 2024
@seisman seisman added the needs review This PR has higher priority and needs review. label Aug 6, 2024
@seisman
Change install.md to be a notebook format and insert the output image…
48951ba
… into the document
@seisman
seisman force-pushed the doc/mystnb branch from a532ca9 to 48951ba Compare August 6, 2024 10:12
seisman added 2 commits August 7, 2024 19:50
@seisman
Merge branch 'main' into doc/mystnb
c7324b1
@seisman
Merge branch 'main' into doc/mystnb
a30f2ce
@seisman
seisman requested a review from a team August 11, 2024 04:43
weiji14
weiji14 reviewed Aug 11, 2024
View reviewed changes
Comment thread doc/conf.py Outdated
Comment on lines +159 to +162
# Workaround from https://github.com/executablebooks/MyST-NB/issues/363 to prevent
# myst-nb from parsing the .ipynb and .py files generated by sphinx-gallery.
"**/*.ipynb",
"**/*.py",

@weiji14 weiji14 Aug 11, 2024

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Can these be more specific to point to a specific folder instead of using **?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@seisman seisman Aug 12, 2024

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Done in 90bb110.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

weiji14 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread doc/install.md
Comment on lines +240 to 247
```{code-cell} ipython
---
tags: [remove-stdout]
---

import pygmt
pygmt.show_versions()

@weiji14 weiji14 Aug 11, 2024

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

These lines are cell-level metadata for controlling the format of the output. Usually it's not necessary. Here remove-stdout is necessary to hide the long output from pygmt.show_versions().

Would it be nicer to actually show the output of pygmt.show_versions() actually? Suggestion to:

  1. Split into two code blocks, one for pygmt.show_versions() and one for fig = pygmt.Figure() below
  2. Collapse the output of pygmt.show_versions() in a dropdown using the hide-output tag (see https://myst-nb.readthedocs.io/en/v0.13.2/use/hiding.html#hide-code-cells).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@seisman seisman Aug 12, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Done in 609d759 and 7a38068 and looks better.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@weiji14 weiji14 Aug 12, 2024

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Readthedocs is showing the PyGMT version as v0.1.dev64+g7a38068.d20240812, but I guess that's ok 😆

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
seisman added 4 commits August 12, 2024 11:37
@seisman
Merge branch 'main' into doc/mystnb
c9a8e90
@seisman
Be more specific about which directories to ignore
90bb110
@seisman
Split the test script into two separate cells
609d759
@seisman
Fix the exclude_patterns parameter to avoid warnings
7a38068
weiji14
weiji14 approved these changes Aug 12, 2024
View reviewed changes
@seisman seisman removed the needs review This PR has higher priority and needs review. label Aug 12, 2024
@seisman
seisman merged commit 7906307 into main Aug 12, 2024
@seisman
seisman deleted the doc/mystnb branch August 12, 2024 08:38
This was referenced Aug 22, 2024
DOC: Generate the charset tables dynamically from codes #3409
Merged
The dynamically generated images are not shown in the documentation #3416
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@weiji14 weiji14 weiji14 approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

documentation Improvements or additions to documentation

Projects

None yet

Milestone

0.13.0

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@seisman @weiji14
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.