8000 Use env var to control if notebooks are executed and add docs, slim, slimfast, and slimgallery variants to Makefile by psobolewskiPhD · Pull Request #646 · napari/docs · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Use env var to control if notebooks are executed and add docs, slim, slimfast, and slimgallery variants to Makefile #646

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

Merged
merged 18 commits into from
Apr 1, 2025

Conversation

psobolewskiPhD
Copy link
Member
@psobolewskiPhD psobolewskiPhD commented Mar 28, 2025

References and relevant issues

closes: #625

Description

In #625 (comment) Juan noted that there is a flag in Myst NB to control whether notebooks are executed.
This is a proof of concept using that.
Basically, the flag is set via ENV var. If it's not set, the flag is set to auto, which is the default. See:
https://myst-nb.readthedocs.io/en/latest/configuration.html#execution

The effect is that now you can do something like:
NB_EXECUTION_MODE="off" make html-noplot and notebooks will not be executed.

Additional slowness is from prep_docs which builds files for events, preferences, and the UI arch diagrams. All of the source material is from outside napari/docs.
As a result, I've added --stubs flag to all of the scripts, which will generate a stub file if the .md file is missing. This ensures that there are no warnings when trying to build the docs.

In order to give more control over building docs, I've added to the Makefile:

  • prep-stubs -- this runs prep_docs.py --stubs, to generate stubs instead of the real files. Will not overwrite, so you can manually run prep-docs if you want.
  • docs -- this will do just napari/docs, but run notebooks (pops up napari GUIs). Meaning: no gallery, prep_docs --stubs, nothing from napari/napari basically
  • docs-live -- same as above, but autobuild
  • slim -- same as docs, but without notebook execution
  • slimfast which is slim but with parallelization (-j auto). For me this one runs in ~35 s.
  • slimfast-live -- live version of slimfast. With slimfast being fast, it runs an initial build. Great way to get started with editing non-codecell content.
  • tweaked html-live to be called html-noplot-live, reflecting its actual role for consistency and to use prep-stubs, because those files get ignored anyways. It will still execute notebooks during autobuild.

We have so many examples, that it's slow to build them all.
As a result, I modified clean to not remove them -- you can use clean-gallery to do that.
Then I added:

  • slimgallery -- will clean and then build the docs with the examples gallery, but not run all the notebook cells in the rest of the docs. So only the examples will pop the viewer.
  • slimgallery-live will do the above, but as an autobuild. Will build all examples that arn't built--the whole gallery. Then, only the example you edit will be re-built when you edit it. Other pages will also rebuild, but notebook cells will not run.
  • slimgallery-% -- % is a capture, to a variable. This is a target for build-single-example Here this will clean and build just a single example, so you would do: slimgallery-vortex for the vortex.py example.
  • slimgallery-live-% -- this is the same as above, but will autobuild the single example. Editing other examples will be ignored. Editing other pages will work and trigger rebuild.

Finally, I updated the documentation and README for the new make options.

@psobolewskiPhD psobolewskiPhD added the maintenance CI, dependencies, and other maintenance label Mar 28, 2025
@github-actions github-actions bot added the documentation Improvements or additions to documentation label Mar 28, 2025
@psobolewskiPhD
Copy link
Member Author
psobolewskiPhD commented Mar 28, 2025

I tested this locally and it worked!
prep_docs is still slow
and I still got one napari window during it or maybe from npe2.
But then, once the sphinx-build step was hit, it was smooth sailing.
The resultant HTML looks as expected: code cells are there, but no output.

We could set the env var in a new make option: make static ?
Feedback very welcome.

@psobolewskiPhD
Copy link
Member Author

Looking at prep_docs, I bet it's the mermaid diagrams that are slow!
But if you've ever run prep_docs, the files are just there in your docs folder. They arn't removed by make clean.
I think I can make a super fast build...

@psobolewskiPhD psobolewskiPhD changed the title Use env var to control if notebooks are executed Use env var to control if notebooks are executed and add slim, slimfast to Makefile Mar 28, 2025
@psobolewskiPhD
Copy link
Member Author

Ok so it works!
prep_docs is slow mostly because of the UI mermaids I think, but the it also generates other materials, etc. But if we're ok with skipping that, then it's all gucci.

Also, clean doesn't remove the generated material from prep_docs scripts, so it's actually built, as long as you've run the scripts once.

Now if you run this on CI (aka fresh clone) it might not complete--I haven't tested. but locally it seems good!

@jni
Copy link
Member
jni commented Mar 28, 2025

Absolutely awesome @psobolewskiPhD! I'm a bit confused about the mermaid diagrams — if we skip prep_docs altogether and they're not cached, would it crash the build or would it just be rendered as text?

@jni
Copy link
Member
jni commented Mar 28, 2025

Overall this is super super exciting — after we merge this we can add a separate circleci config for slimfast (😂) which would allow really fast feedback from CI builds — gamechanger!

Copy link
Member
@jni jni left a comment

Choose a reason for hiding this comment

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

😍🤩

@jni jni added this to the 0.6.0 milestone Mar 28, 2025
@psobolewskiPhD
Copy link
Member Author

Absolutely awesome @psobolewskiPhD! I'm a bit confused about the mermaid diagrams — if we skip prep_docs altogether and they're not cached, would it crash the build or would it just be rendered as text?

Dunno. it's on the todo to test with a fresh clone where prep_docs hasn't been run.
I'm 50-50 on it will work vs it will crash, but I've not had time to test it. I should have time to try tomorrow night.

Copy link
Contributor
@willingc willingc left a comment

Choose a reason for hiding this comment

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

@psobolewskiPhD You are my hero! Let's merge fast too. 😄

@psobolewskiPhD
Copy link
Member Author

Question:
Would it be worth it to add a make keyword for a build that runs the notebook cells but skips prep_docs?
Someone writting/editing a tutorial or whatnot will never care about the stuff prep_docs builds and it alone is a big time saver. (>5 min)
Basically a no gallery, no api, no arch diagrams, no outside stuff basically. Just the docs/docs notebooks and stuffs.

@TimMonko
Copy link
Contributor
TimMonko commented Mar 28, 2025

Would it be worth it to add a make keyword for a build that runs the notebook cells but skips prep_docs?

For sure! and I assume also skips gallery?
Edit: wait yeah I guess it would if it's included in prep_docs. I assumed the was only API. I guess a key thing to document lol.

@psobolewskiPhD psobolewskiPhD changed the title Use env var to control if notebooks are executed and add slim, slimfast to Makefile Use env var to control if notebooks are executed and add docs, slim, slimfast to Makefile Mar 28, 2025
@psobolewskiPhD
Copy link
Member Author

Latest update:
In order to give more control over building docs, I've added to the Makefile:

  • docs -- this will do just napari/docs, but run notebooks (pops up napari GUIs). Meaning: no gallery, no prep_docs (events, pref, ui), nothing from napari/napari basically
  • slim -- same as docs, but without notebook execution
  • slimfast which is slim but with parallelization (-j auto). For me this one runs in ~35 s.

@psobolewskiPhD
Copy link
Member Author
psobolewskiPhD commented Mar 28, 2025

Oh, I tested locally with a fresh clone.
If you don't run prep_docs, then the docs do build, but you get a warning for all the things that are missing. So it's a bit of spam, but it completes and the html is fine, with just some stuff missing.
The warnings do make it harder to id a real warning should you get one. I'm not sure if there is a way to filter specific warnings for a specific sphinx-build run.

edit: making stub files is probably the easiest. Have the files generated by prep_docs there, but just placeholders.
edit2: no, that seems like it will result in the real versions being committed and not gitignored. >.<
edit3: ok we'd need a prep_sham which generates the stubs via a script

@willingc
Copy link
Contributor

@psobolewskiPhD I will take a look at this tomorrow. We should be able to get the API build running smoother. Let me take a looks at the scripts and think about optimization.

@psobolewskiPhD
Copy link
Member Author

I'm almost ready to merge a commit that adds --stubs to prep_docs which will generate stubs instead of doing the real stuff.
It's a couple seconds. Silences the warnings but doesn't overwrite, so if you do run the real prep_docs, then you have the fancies.

@psobolewskiPhD
Copy link
Member Author

Boom. Works nicely.
slimfast still runs in 40s, so just a few seconds cost for not having the warnings.

@psobolewskiPhD
Copy link
Member Author

If this goes through, I have a prototype of:

  • a slimfast run on circleCI (no qt! simple!) on PRs (replacing current job)
  • a full build (current job) triggered by a comment on the PR. Can have the full build include both a circle job and the GitHub build too.

@TimMonko
Copy link
Contributor

This is marvelous! 🤩 Truly incredible. And it looks way less janky than I expected. Code blocks are still there, just nothing obviously ran (maybe this is obvious but I sort of expected a blank spot). Also, anywhere there is a stub it nicely informs "This is a stub. The real file is autogenerated in a full build." Which I really like!

Might be worth adding -live to one of these?

Now all that's left is me not having to rethink Git Bash every time because I'm on Windows. I'm sure this will help me finally learn the like 2 extra steps I have to do that I always forget...

@psobolewskiPhD
Copy link
Member Author
psobolewskiPhD commented Mar 30, 2025

(I did just test again, and slimfast-live was quicker this time and closed out correctly. Maybe it was just wonky the first time on a fresh env)

prep-stubs will check if the files exist and not overwrite, so that could explain it. in a fresh env it would be creating the stubs, so some file i/o.

I think there are 2 main workflows for a fresh clone/new contributor:

  • quick and easy, want to fix something, add admonition: just use slimfast (or -live for more changes)
  • Working on notebook content? slimfast followed by html-live

Transitioning to a longer term contributor? may as well run prep-docs, even manually. It only does a couple flashes, but does take upwards of 10 min. Then you can run whatever you need for the specific contribution, probably slimfast and/or html-live, with the occasional full build.

@TimMonko did you want me to revert the --quiet on slimfast-live?

@psobolewskiPhD
Copy link
Member Author

Would be cool to come up with a way to do a quick gallery build, of only the examples you edit -- so like the -live builds. I will poke around.

@TimMonko
Copy link
Contributor

@TimMonko did you want me to revert the --quiet on slimfast-live?

Quiet is ok as long as it tells users a useful error (like a myst formatting issue or whatever). I honestly I have no idea what this sphinx doc --quiet is supposed to mean.

Your overall synopsis of the usage is 💯 Pretty much can be dropping in to the contributing documentation page as is

@TimMonko
Copy link
Contributor

Also to be most forward. I trust your judgement, wisdom, and experience much more than mine, so do whatever you think is best

@psobolewskiPhD
Copy link
Member Author

I honestly I have no idea what this sphinx doc --quiet is supposed to mean.

So on unix systems at least (macos/linux for sure) the normal console display for interactive shells prints both standard error and standard output. So --quiet will silence all the normal progress etc output, when everything runs normally, but it will print errors and warnings when things are whack, because the typical display will also show standard error. The distinction is useful when piping commands or running things headless. Then you may want to monitor errors in particular, hence a different output channel (standard error) for them.

@psobolewskiPhD
Copy link
Member Author

I think I can get a gallery autobuild. You will need to run a gallery build once (but don't need prep-docs or notebook execution) and then it should update edited examples. I'll test it and then push if it works.

@psobolewskiPhD
Copy link
Member Author
psobolewskiPhD commented Mar 31, 2025

Ok! I think I got examples to work.

  • slimgallery will clean and build the gallery, but not run all the notebook cells in the rest of the docs.
  • slimgallery-live will do an autobuild. Will build all examples that arn't built--the whole gallery. Then, only the example you edit will be re-built when you edit it. Other pages will also rebuild, but notebook cells will not run.

and to make it even easier to contribute a single example:

  • slimgallery-% -- this will clean and build just a single example, so you would do: slimgallery-vortex for the vortex.py example
  • slimgallery-live-% -- this is the same as above, but autobuild

neither of these require the full examples to be built in advance

(I wanted to build stubs and md5s for the gallery, but it was too annoying)

@psobolewskiPhD psobolewskiPhD changed the title Use env var to control if notebooks are executed and add docs, slim, slimfast to Makefile Use env var to control if notebooks are executed and add docs, slim, slimfast, and slimgallery variants to Makefile Mar 31, 2025
@psobolewskiPhD
Copy link
Member Author

Using slimgallery-vortex to build the docs with the vortex.py example takes 42 seconds on my machine.

(oh btw i reverted the --quiet mode so everything looks the same when running)

# no generation from prep_docs scripts, no gallery
# will not remove existing gallery files
docs: clean prep-stubs
NAPARI_APPLICATION_IPY_INTERACTIVE=0 sphinx-build -M html docs/ docs/_build -D plot_gallery=0 -D sphinx_gallery_conf.examples_dirs=$(GALLERY_PATH) $(SPHINXOPTS)
Copy link
Member

Choose a reason for hiding this comment

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

(1) is sphinx_gallery_conf.examples_dirs needed with plot_gallery=0?
(2) I don't understand now how to build both docs and gallery? ie what is the incantation for a "full build" now?
(3) it might be worth mentioning that in the comment. "For gallery, look at XYZ. For a single gallery example, look at ABC. For a full build, look at ZYX."

Copy link
Member

Choose a reason for hiding this comment

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

@psobolewskiPhD I'll merge this in the morning my time because my questions above are minor, but if you have a chance to look at them I appreciate it. 😊 🙏

Copy link
Member Author
@psobolewskiPhD psobolewskiPhD Mar 31, 2025

Choose a reason for hiding this comment

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

@jni

  1. my understanding from the docs is that examples_dir is a needed config, while plot_gallery is an execution option:
    https://sphinx-gallery.github.io/stable/configuration.html
    The settings are the same as existing make commands that didn't build gallery, so I didn't want to mess with it.

  2. this hasn't changed. it's still make html.

  3. Do you mean add comments to the existing make options? I can do that. I will definitely update the contribution guide before this is merged, just wanted some feedback on the options.

Copy link
Member Author

Choose a reason for hiding this comment

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

@jni I update the contribution guide for the new make variants. I tried to make it clear which you'd want to run depending on what you were trying to contribute.

@jni
Copy link
Member
jni commented Mar 31, 2025

@psobolewskiPhD this is amazing work. 😍 I had a minor question when looking over the full makefile, but improvements are optional at this point and can come in followup PRs.

@psobolewskiPhD
Copy link
Member Author

I update the contribution guide for the new make variants. I tried to make it clear which you'd want to run depending on what you were trying to contribute.
It was nice to use slimfast-live for this!! 🚀

@jni jni merged commit 0dc1c55 into napari:main Apr 1, 2025
9 checks passed
jni pushed a commit that referenced this pull request Apr 13, 2025
…targets (#649)

# References and relevant issues
Followup to #646 

# Description
In a clean repo, `prep_stubs` was generating warnings due to missing
targets. The stub files were written, but lacked targets.
I fix this in this PR and add `clean-prep` and `clean-full` to be able
to ensure all autogenerated content can be cleaned if needed.
jni pushed a commit that referenced this pull request Apr 23, 2025
…#669)

# References and relevant issues
Depends on #671

# Description
In #646 new make targets were added
for faster builds that skip certain parts of the process.
In this PR I make them available on CI using a comment:
`napari-bot make <target>`
(add the `@` in front of napari-bot)

Here's the breakdown:
1. circleci/config.yml : Here I add a parameter `make_target` to make
the make target configurable on-run. Default is `slimfast` (no gallery,
no outside stuff, no notebook execution)
2. build_docs.yml : I added this back, as a reusable workflow, so that
there is a build-only workflow that can be run on PR push and triggered
with different make_target. (The build-deploy job needs to use the full
build for obvious reasons). I made it so that this build-only job also
be manually triggered by dispatch. Whether triggered or by manual
dispatch, this workflow accepts a make target, one of: html html-noplot
docs slimfast slimgallery. The default is `slimfast`, so on (every)
push/open of PR it will use `slimfast`, but can be triggered with the
other options. Note: at present the triggered state is not saved, so
push always used the default.
3. build_trigger.yml : This is the workflow that detects PR comment,
checks make target vs a list, and triggers the CircleCI and build_docs
builds with the make target from the comment. It also has a step to
report back that the triggered build_docs workflow finished and provide
a link to the run.
4. build_and_deploy.yml : I modified this to not run on PR push anymore,
because it's a full build -- we do need full build for deployment and
it's triggered by napari/napari as well.

I also modified the PR template to give info on the CI builds, as well
as the contributor guide where we talk about docs building on CI.

Note: I don't think the new features will trigger in this PR, because
it's from a branch.
You should be able to see this in action and test it here in my fork,
where this PR branch is the default branch:
psobolewskiPhD#74
You can see builds triggered by comments from Juan and Carol:
https://github.com/psobolewskiPhD/napari-docs/actions/workflows/build_trigger.yml

Followups: 
- have the trigger add a reaction to the comment, so the user knows it
triggered
- have the trigger add a label to the PR and then use the label as
default for subsequent runs (e.g. push ones)

---------

Co-authored-by: Tim Monko <timmonko@gmail.com>
Co-authored-by: Carol Willing <carolcode@willingconsulting.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation maintenance CI, dependencies, and other maintenance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create a proof of concept for html-slim in the makefile
4 participants
0