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

DOC: Add notebook infrastructure for the docs #17322

Merged
merged 12 commits into from Apr 7, 2023

Conversation

melissawm
Copy link
Contributor

@melissawm melissawm commented Nov 2, 2022

This is a first proposal for adding MyST-NB notebooks to the SciPy docs.

This PR is still in draft as there are a few things still to be decided:

  • If we need to run tests, we might need to look into testbook instead of nbval (see Feature Request: doctest for code-cell executablebooks/MyST-NB#290 for details)
  • I did some editing on the front page of the user guide. A lot of the contents are redundant now that the documentation has grown, and I felt like we could simplify them to read more like technical documentation and less like a book. I'm open to feedback or to breaking this into a separate PR if that's easier to review.
  • We could also add a guide on opening the tutorial as a Jupyter notebook.
  • Still pending is adding examples of cross-referencing the rst documentation and the md file.
  • The notebook itself can still use some editing, but I just wanted to try a first build so that we can trace a plan.

Reference issue

See #5233

What does this implement/fix?

Adds myst_nb as a Sphinx extension, adds a new MyST notebook tutorial (as a markdown file) and also reorganizes the user guide landing page.

Copy link
Member

@ev-br ev-br left a comment

Choose a reason for hiding this comment

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

This looks great!

We could also add a guide on opening the tutorial as a Jupyter notebook.

Yes please! For a novice user, I've no idea how to start a tutorial. Do I type the markdown in a text editor (and then what), do I write in a jupyter notebook (and then what), how to pair the NB and md etc.

Also, would be great to have a guidance on how to make intersphinx links both from a new-style md document into existing rst pages and vice versa.

doc/source/tutorial/index.rst Outdated Show resolved Hide resolved
doc/source/tutorial/index.rst Outdated Show resolved Hide resolved
@j-bowhay j-bowhay added enhancement A new feature or improvement Documentation Issues related to the SciPy documentation. Also check https://github.com/scipy/scipy.org labels Nov 2, 2022
Copy link
Member

@tupui tupui left a comment

Choose a reason for hiding this comment

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

That's great! +1 for this and the editing you've done to existing content. Just some suggestions.

I would not spend too much time on the review of the tutorial itself and leave this for later. We can even say nobody looks at this, it's just to see how it renders and we remove it before merging (my preference). Then we can do a proper PR to add content and take our time.

doc/source/tutorial/index.rst Outdated Show resolved Hide resolved
environment.yml Show resolved Hide resolved
@melissawm melissawm marked this pull request as ready for review November 30, 2022 18:07
@melissawm
Copy link
Contributor Author

I have created an issue in MyST-NB about the JUPYTER_PLATFORM_DIRS warning. This is fixable if we set the environment variable as the warning describes, but I'd like to understand what's happening anyway.

Copy link
Member

@tupui tupui left a comment

Choose a reason for hiding this comment

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

Thanks for the update @melissawm! I have some minor suggestions but otherwise LGTM

.gitignore Outdated Show resolved Hide resolved
doc/source/tutorial/index.rst Outdated Show resolved Hide resolved
environment.yml Outdated
Comment on lines 41 to 43
- docutils<0.18.1
#- jupytext
- myst-nb
Copy link
Member

Choose a reason for hiding this comment

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

Leftover?

Suggested change
- docutils<0.18.1
#- jupytext
- myst-nb
- docutils<0.18.1
- myst-nb

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added this back - not sure here though. On the one hand makes it easier for folks adding their own notebooks, and folks with this setup can easily open md files as notebooks (that is what Jupytext does). On the other hand, it is an extra dependency. What do you think?

environment.yml Outdated Show resolved Hide resolved
melissawm and others added 2 commits January 22, 2023 17:38
Co-authored-by: Pamphile Roy <roy.pamphile@gmail.com>
@tupui
Copy link
Member

tupui commented Jan 24, 2023

I think failure in CI is related. Seems to be due to a deprecation warning in SQLAlchemy and raised by myst

@melissawm
Copy link
Contributor Author

It is 🥲 I also observed that locally. I will investigate

@melissawm
Copy link
Contributor Author

After some testing, it looks like this is currently blocked on Python 3.9. Using Python 3.10 brings all sorts of unexpected deprecation warnings from sqlalchemy, nbclient and myst_nb. I am not sure how to solve it at this point unfortunately.

@tupui
Copy link
Member

tupui commented Jan 26, 2023

If it's just warnings, we can selectively disable them in the config file for the doc (around L150).

@melissawm
Copy link
Contributor Author

Ok! Here's the update:

  • I've merged main to make sure all was up to date and fix conflicts.
  • I've updated the requirements and made sure the notebook runs smoothly. Here's the reason for the changes to conf.py and dev.py:
  1. Several sqlalchemy errors appear, related to myst_nb and a few deprecations marked to happen in sqlalchemy 2.0. Pinning sqlalchemy makes no difference, so I've added the SQLALCHEMY_SILENCE_UBER_WARNING=1 to the env variables for the doc task in dev.py

    python dev.py doc
    💻  ninja -C /home/melissa/projects/scipy/build
    ninja: Entering directory `/home/melissa/projects/scipy/build'
    [2/2] Generating scipy/generate-config with a custom command
    Build OK
    💻  meson install -C build --only-changed
    Installing, see meson-install.log...
    Installation OK
    # for testing
    # @echo installed scipy 591765c matches git version 591765c; exit 1
    mkdir -p build/html build/doctrees
    LANG=C /opt/miniconda/envs/scipy-dev/bin/python -msphinx -WT --keep-going  -b html -d build/doctrees -j1 source build/html 
    Running Sphinx v5.3.0
    SciPy (VERSION 1.10.0.dev0+2284.591765c)
    
    Traceback (most recent call last):
      File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/sphinx/cmd/build.py", line 276, in build_main
        app = Sphinx(args.sourcedir, args.confdir, args.outputdir,
      File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/sphinx/application.py", line 223, in __init__
        self.setup_extension(extension)
      File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/sphinx/application.py", line 398, in setup_extension
        self.registry.load_extension(self, extname)
      File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/sphinx/registry.py", line 472, in load_extension
        metadata = setup(app)
      File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/myst_nb/__init__.py", line 8, in setup
        from .sphinx_ext import sphinx_setup
      File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/myst_nb/sphinx_ext.py", line 20, in <module>
        from myst_nb.ext.eval import load_eval_sphinx
      File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/myst_nb/ext/eval/__init__.py", line 10, in <module>
        from myst_nb.core.execute.base import EvalNameError
      File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/myst_nb/core/execute/__init__.py", line 7, in <module>
        from .cache import NotebookClientCache
      File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/myst_nb/core/execute/cache.py", line 11, in <module>
        from jupyter_cache.base import CacheBundleIn
      File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/jupyter_cache/base.py", line 16, in <module>
        from jupyter_cache.cache.db import NbCacheRecord, NbProjectRecord
      File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/jupyter_cache/cache/db.py", line 17, in <module>
        OrmBase = declarative_base()
      File "<string>", line 2, in declarative_base
      File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/sqlalchemy/util/deprecations.py", line 467, in warned
        _warn_with_version(message, version, wtype, stacklevel=3)
      File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/sqlalchemy/util/deprecations.py", line 47, in _warn_with_version
        _emit_uber_warning(type_, stacklevel)
      File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/sqlalchemy/util/deprecations.py", line 105, in _emit_uber_warning
        _warnings_warn(warn, stacklevel=stacklevel + 1)
      File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py", line 1679, in _warnings_warn
        warnings.warn(message, stacklevel=stacklevel + 1)
    sqlalchemy.exc.MovedIn20Warning: Deprecated API features detected! These feature(s) are not compatible with SQLAlchemy 2.0. To prevent incompatible upgrades prior to updating applications, ensure requirements files are pinned to "sqlalchemy<2.0". Set environment variable SQLALCHEMY_WARN_20=1 to show all deprecation warnings.  Set environment variable SQLALCHEMY_SILENCE_UBER_WARNING=1 to silence this message. (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
    
    Exception occurred:
      File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py", line 1679, in _warnings_warn
        warnings.warn(message, stacklevel=stacklevel + 1)
    sqlalchemy.exc.MovedIn20Warning: Deprecated API features detected! These feature(s) are not compatible with SQLAlchemy 2.0. To prevent incompatible upgrades prior to updating applications, ensure requirements files are pinned to "sqlalchemy<2.0". Set environment variable SQLALCHEMY_WARN_20=1 to show all deprecation warnings.  Set environment variable SQLALCHEMY_SILENCE_UBER_WARNING=1 to silence this message. (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
    The full traceback has been saved in /tmp/sphinx-err-rls3vz9x.log, if you want to report the issue to the developers.
    Please also report this if it was a user error, so that a better error message can be provided next time.
    A bug report can be filed in the tracker at <https://github.com/sphinx-doc/sphinx/issues>. Thanks!
    make: *** [Makefile:110: html-build] Error 2
    
  2. A Jupyter warning also needs the JUPYTER_PLATFORM_DIRS=1 env variable set in dev.py.

     python dev.py doc
    💻  ninja -C /home/melissa/projects/scipy/build
    ninja: Entering directory `/home/melissa/projects/scipy/build'
    [2/2] Generating scipy/generate-config with a custom command
    Build OK
    💻  meson install -C build --only-changed
    Installing, see meson-install.log...
    Installation OK
    # for testing
    # @echo installed scipy 591765c matches git version 591765c; exit 1
    mkdir -p build/html build/doctrees
    LANG=C /opt/miniconda/envs/scipy-dev/bin/python -msphinx -WT --keep-going  -b html -d build/doctrees -j1 source build/html 
    Running Sphinx v5.3.0
    SciPy (VERSION 1.10.0.dev0+2284.591765c)
    
    Traceback (most recent call last):
      File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/sphinx/cmd/build.py", line 276, in build_main
        app = Sphinx(args.sourcedir, args.confdir, args.outputdir,
      File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/sphinx/application.py", line 223, in __init__
        self.setup_extension(extension)
      File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/sphinx/application.py", line 398, in setup_extension
        self.registry.load_extension(self, extname)
      File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/sphinx/registry.py", line 472, in load_extension
        metadata = setup(app)
      File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/myst_nb/__init__.py", line 8, in setup
        from .sphinx_ext import sphinx_setup
      File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/myst_nb/sphinx_ext.py", line 20, in <module>
        from myst_nb.ext.eval import load_eval_sphinx
      File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/myst_nb/ext/eval/__init__.py", line 10, in <module>
        from myst_nb.core.execute.base import EvalNameError
      File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/myst_nb/core/execute/__init__.py", line 7, in <module>
        from .cache import NotebookClientCache
      File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/myst_nb/core/execute/cache.py", line 13, in <module>
        from jupyter_cache.executors.utils import single_nb_execution
      File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/jupyter_cache/executors/utils.py", line 7, in <module>
        from nbclient import execute as executenb
      File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/nbclient/__init__.py", line 6, in <module>
        from .client import NotebookClient, execute  # noqa: F401
      File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/nbclient/client.py", line 14, in <module>
        from jupyter_client import KernelManager
      File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/jupyter_client/__init__.py", line 8, in <module>
        from .asynchronous import AsyncKernelClient  # noqa
      File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/jupyter_client/asynchronous/__init__.py", line 1, in <module>
        from .client import AsyncKernelClient  # noqa
      File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/jupyter_client/asynchronous/client.py", line 9, in <module>
        from ..client import KernelClient, reqrep
      File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/jupyter_client/client.py", line 20, in <module>
        from .connect import ConnectionFileMixin
      File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/jupyter_client/connect.py", line 20, in <module>
        from jupyter_core.paths import jupyter_data_dir, jupyter_runtime_dir, secure_write
      File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/jupyter_core/paths.py", line 208, in <module>
        deprecation(
      File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/jupyter_core/utils/__init__.py", line 89, in deprecation
        warnings.warn(message, DeprecationWarning, stacklevel=stacklevel + 1)
    DeprecationWarning: Jupyter is migrating its paths to use standard platformdirs
    given by the platformdirs library.  To remove this warning and
    see the appropriate new directories, set the environment variable
    `JUPYTER_PLATFORM_DIRS=1` and then run `jupyter --paths`.
    The use of platformdirs will be the default in `jupyter_core` v6
    
    Exception occurred:
      File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/jupyter_core/utils/__init__.py", line 89, in deprecation
        warnings.warn(message, DeprecationWarning, stacklevel=stacklevel + 1)
    DeprecationWarning: Jupyter is migrating its paths to use standard platformdirs
    given by the platformdirs library.  To remove this warning and
    see the appropriate new directories, set the environment variable
    `JUPYTER_PLATFORM_DIRS=1` and then run `jupyter --paths`.
    The use of platformdirs will be the default in `jupyter_core` v6
    The full traceback has been saved in /tmp/sphinx-err-olo_4c9a.log, if you want to report the issue to the developers.
    Please also report this if it was a user error, so that a better error message can be provided next time.
    A bug report can be filed in the tracker at <https://github.com/sphinx-doc/sphinx/issues>. Thanks!
    make: *** [Makefile:110: html-build] Error 2
    
  3. Two docutils warnings are suppressed in conf.py

    python dev.py doc      
    💻  ninja -C /home/melissa/projects/scipy/build
    ninja: Entering directory `/home/melissa/projects/scipy/build'
    [4/4] Generating scipy/generate-version with a custom command
    Build OK
    💻  meson install -C build --only-changed
    Installing, see meson-install.log...
    Installation OK
    # for testing
    # @echo installed scipy b36aa9f matches git version b36aa9f; exit 1
    mkdir -p build/html build/doctrees
    LANG=C /opt/miniconda/envs/scipy-dev/bin/python -msphinx -WT --keep-going  -b html -d build/doctrees -j1 source build/html 
    Running Sphinx v5.3.0
    SciPy (VERSION 1.11.0.dev0+1766.b36aa9f)
    [autosummary] generating autosummary for: dev/api-dev/api-dev-toc.rst, dev/api-dev/nan_policy.rst, dev/api-dev/special_ufuncs.rst, dev/conduct/code_of_conduct.rst, dev/conduct/report_handling_manual.rst, dev/contributor/adding_new.rst, dev/contributor/benchmarking.rst, dev/contributor/building.rst, dev/contributor/building_faq.rst, dev/contributor/compiled_code.rst, ..., tutorial/stats/discrete_zipf.rst, tutorial/stats/discrete_zipfian.rst, tutorial/stats/resampling.rst, tutorial/stats/sampling.rst, tutorial/stats/sampling_dau.rst, tutorial/stats/sampling_dgt.rst, tutorial/stats/sampling_hinv.rst, tutorial/stats/sampling_pinv.rst, tutorial/stats/sampling_srou.rst, tutorial/stats/sampling_tdr.rst
    [autosummary] generating autosummary for: /home/melissa/projects/scipy/doc/source/reference/generated/czt-function.rst, /home/melissa/projects/scipy/doc/source/reference/generated/odr-function.rst, /home/melissa/projects/scipy/doc/source/reference/generated/scipy.LowLevelCallable.rst, /home/melissa/projects/scipy/doc/source/reference/generated/scipy.cluster.hierarchy.ClusterNode.rst, /home/melissa/projects/scipy/doc/source/reference/generated/scipy.cluster.hierarchy.DisjointSet.rst, /home/melissa/projects/scipy/doc/source/reference/generated/scipy.cluster.hierarchy.average.rst, /home/melissa/projects/scipy/doc/source/reference/generated/scipy.cluster.hierarchy.centroid.rst, /home/melissa/projects/scipy/doc/source/reference/generated/scipy.cluster.hierarchy.complete.rst, /home/melissa/projects/scipy/doc/source/reference/generated/scipy.cluster.hierarchy.cophenet.rst, /home/melissa/projects/scipy/doc/source/reference/generated/scipy.cluster.hierarchy.correspond.rst, ..., /home/melissa/projects/scipy/doc/source/reference/generated/scipy.stats.yeojohnson.rst, /home/melissa/projects/scipy/doc/source/reference/generated/scipy.stats.yeojohnson_llf.rst, /home/melissa/projects/scipy/doc/source/reference/generated/scipy.stats.yeojohnson_normmax.rst, /home/melissa/projects/scipy/doc/source/reference/generated/scipy.stats.yeojohnson_normplot.rst, /home/melissa/projects/scipy/doc/source/reference/generated/scipy.stats.yulesimon.rst, /home/melissa/projects/scipy/doc/source/reference/generated/scipy.stats.zipf.rst, /home/melissa/projects/scipy/doc/source/reference/generated/scipy.stats.zipfian.rst, /home/melissa/projects/scipy/doc/source/reference/generated/scipy.stats.zmap.rst, /home/melissa/projects/scipy/doc/source/reference/generated/scipy.stats.zscore.rst, /home/melissa/projects/scipy/doc/source/reference/generated/scipy.test.rst
    [autosummary] generating autosummary for: /home/melissa/projects/scipy/doc/source/reference/generated/scipy.LowLevelCallable.__getitem__.rst, /home/melissa/projects/scipy/doc/source/reference/generated/scipy.LowLevelCallable.__len__.rst, /home/melissa/projects/scipy/doc/source/reference/generated/scipy.LowLevelCallable.__mul__.rst, /home/melissa/projects/scipy/doc/source/reference/generated/scipy.LowLevelCallable.count.rst, /home/melissa/projects/scipy/doc/source/reference/generated/scipy.LowLevelCallable.from_cython.rst, /home/melissa/projects/scipy/doc/source/reference/generated/scipy.LowLevelCallable.function.rst, /home/melissa/projects/scipy/doc/source/reference/generated/scipy.LowLevelCallable.index.rst, /home/melissa/projects/scipy/doc/source/reference/generated/scipy.LowLevelCallable.signature.rst, /home/melissa/projects/scipy/doc/source/reference/generated/scipy.LowLevelCallable.user_data.rst, /home/melissa/projects/scipy/doc/source/reference/generated/scipy.cluster.hierarchy.ClusterNode.get_count.rst, ..., /home/melissa/projects/scipy/doc/source/reference/generated/scipy.stats.sampling.NumericalInversePolynomial.set_random_state.rst, /home/melissa/projects/scipy/doc/source/reference/generated/scipy.stats.sampling.NumericalInversePolynomial.u_error.rst, /home/melissa/projects/scipy/doc/source/reference/generated/scipy.stats.sampling.SimpleRatioUniforms.rvs.rst, /home/melissa/projects/scipy/doc/source/reference/generated/scipy.stats.sampling.SimpleRatioUniforms.set_random_state.rst, /home/melissa/projects/scipy/doc/source/reference/generated/scipy.stats.sampling.TransformedDensityRejection.hat_area.rst, /home/melissa/projects/scipy/doc/source/reference/generated/scipy.stats.sampling.TransformedDensityRejection.ppf_hat.rst, /home/melissa/projects/scipy/doc/source/reference/generated/scipy.stats.sampling.TransformedDensityRejection.rvs.rst, /home/melissa/projects/scipy/doc/source/reference/generated/scipy.stats.sampling.TransformedDensityRejection.set_random_state.rst, /home/melissa/projects/scipy/doc/source/reference/generated/scipy.stats.sampling.TransformedDensityRejection.squeeze_area.rst, /home/melissa/projects/scipy/doc/source/reference/generated/scipy.stats.sampling.TransformedDensityRejection.squeeze_hat_ratio.rst
    loading intersphinx inventory from https://docs.python.org/3/objects.inv...
    loading intersphinx inventory from https://numpy.org/devdocs/objects.inv...
    loading intersphinx inventory from https://numpy.org/neps/objects.inv...
    loading intersphinx inventory from https://matplotlib.org/stable/objects.inv...
    loading intersphinx inventory from https://asv.readthedocs.io/en/stable/objects.inv...
    loading intersphinx inventory from https://www.statsmodels.org/stable/objects.inv...
    myst v0.18.1: MdParserConfig(commonmark_only=False, gfm_only=False, enable_extensions=[], disable_syntax=[], all_links_external=False, url_schemes=('http', 'https', 'mailto', 'ftp'), ref_domains=None, highlight_code_blocks=True, number_code_blocks=[], title_to_header=False, heading_anchors=None, heading_slug_func=None, footnote_transition=True, words_per_minute=200, sub_delimiters=('{', '}'), linkify_fuzzy_links=True, dmath_allow_labels=True, dmath_allow_space=True, dmath_allow_digits=True, dmath_double_inline=False, update_mathjax=True, mathjax_classes='tex2jax_process|mathjax_process|math|output_area')
    myst-nb v0.17.1: NbParserConfig(custom_formats={}, metadata_key='mystnb', cell_metadata_key='mystnb', kernel_rgx_aliases={}, execution_mode='auto', execution_cache_path='', execution_excludepatterns=(), execution_timeout=30, execution_in_temp=False, execution_allow_errors=False, execution_raise_on_error=False, execution_show_tb=False, merge_streams=False, render_plugin='default', remove_code_source=False, remove_code_outputs=False, code_prompt_show='Show code cell {type}', code_prompt_hide='Hide code cell {type}', number_source_lines=False, output_stderr='show', render_text_lexer='myst-ansi', render_error_lexer='ipythontb', render_image_options={}, render_figure_options={}, render_markdown_format='commonmark', output_folder='build', append_css=True, metadata_to_fm=False)
    Using jupyter-cache at: /home/melissa/projects/scipy/doc/build/.jupyter_cache
    building [mo]: targets for 0 po files that are out of date
    building [html]: targets for 335 source files that are out of date
    updating environment: [new config] 4341 added, 0 changed, 0 removed
    reading sources... [  1%] notebooks/interp_transition_guide                                                                                  
    Traceback (most recent call last):
      File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/sphinx/cmd/build.py", line 281, in build_main
        app.build(args.force_all, args.filenames)
      File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/sphinx/application.py", line 347, in build
        self.builder.build_update()
      File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/sphinx/builders/__init__.py", line 310, in build_update
        self.build(to_build,
      File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/sphinx/builders/__init__.py", line 326, in build
        updated_docnames = set(self.read())
      File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/sphinx/builders/__init__.py", line 433, in read
        self._read_serial(docnames)
      File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/sphinx/builders/__init__.py", line 454, in _read_serial
        self.read_doc(docname)
      File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/sphinx/builders/__init__.py", line 510, in read_doc
        publisher.publish()
      File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/docutils/core.py", line 224, in publish
        self.document = self.reader.read(self.source, self.parser,
      File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/sphinx/io.py", line 104, in read
        self.parse()
      File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/docutils/readers/__init__.py", line 76, in parse
        self.parser.parse(self.input, document)
      File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/myst_nb/sphinx_.py", line 142, in parse
        mdit_renderer.setup_render(mdit_parser.options, mdit_env)
      File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/myst_parser/mdit_to_docutils/base.py", line 135, in setup_render
        self.document: nodes.document = options.get("document", make_document())
      File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/myst_parser/mdit_to_docutils/base.py", line 55, in make_document
        settings = OptionParser(components=(parser_cls,)).get_default_values()
      File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/docutils/frontend.py", line 662, in __init__
        warnings.warn('The frontend.OptionParser class will be replaced '
    DeprecationWarning: The frontend.OptionParser class will be replaced by a subclass of argparse.ArgumentParser in Docutils 0.21 or later.
    
    Exception occurred:
      File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/docutils/frontend.py", line 662, in __init__
        warnings.warn('The frontend.OptionParser class will be replaced '
    DeprecationWarning: The frontend.OptionParser class will be replaced by a subclass of argparse.ArgumentParser in Docutils 0.21 or later.
    The full traceback has been saved in /tmp/sphinx-err-k3368iou.log, if you want to report the issue to the developers.
    Please also report this if it was a user error, so that a better error message can be provided next time.
    A bug report can be filed in the tracker at <https://github.com/sphinx-doc/sphinx/issues>. Thanks!
    make: *** [Makefile:110: html-build] Error 2
    
  4. I have also set up the notebook to ignore the interp2d deprecation warnings.

Let me know if this is acceptable - if it's too much extra stuff we can reevaluate, but most of these can and should be removed in the near future.

Copy link
Member

@tupui tupui left a comment

Choose a reason for hiding this comment

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

Thanks for the update @melissawm!

I would be fine moving forward with this and silencing a few warnings seems ok to me.

There is still an issue with the CI. Did you see this locally as well?

Comment on lines +1038 to +1041
# Environment variables needed for notebooks
# See gh-17322
make_params.append('SQLALCHEMY_SILENCE_UBER_WARNING=1')
make_params.append('JUPYTER_PLATFORM_DIRS=1')
Copy link
Member

Choose a reason for hiding this comment

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

I would be fine with these.

(In the same spirit of the dep tracker issue, maybe we should have a place to note things we need to do when something updates. Be it a Python version or another library. Otherwise this might stay there longer than intended, not that it would be a big issue though.)

@melissawm
Copy link
Contributor Author

I think this is a docutils issue - I don't see it locally but have found similar in other CIs. Let me check

@melissawm
Copy link
Contributor Author

Well this is fun. It looks like the failure only happens for Python 3.9, and only if you enable -j2 as an option. Verified by running locally and also ssh'ing into CircleCI and running python dev.py --no-build docs (which works fine). Not sure if I can fix it?

@rgommers
Copy link
Member

@melissawm do you have a full traceback? If it's understood and it will be robust for Python >=3.10 we may consider just documenting the issue and moving on.

@tupui
Copy link
Member

tupui commented Mar 29, 2023

+1 for moving the whole job to 3.10 if this works.

@melissawm melissawm requested a review from larsoner as a code owner April 4, 2023 20:03
@melissawm
Copy link
Contributor Author

melissawm commented Apr 4, 2023

Ok I think I finally managed to pin this down.

  1. I've added filters to a few sphinx warnings coming from the docutils/myst_nb interaction and sphinx. Namely,
nodes.Node.traverse() is obsoleted by Node.findall().
Traceback (most recent call last):
  File "/opt/miniconda/envs/scipy-dev/lib/python3.9/site-packages/sphinx/cmd/build.py", line 281, in build_main
    app.build(args.force_all, args.filenames)
  File "/opt/miniconda/envs/scipy-dev/lib/python3.9/site-packages/sphinx/application.py", line 347, in build
    self.builder.build_update()
  File "/opt/miniconda/envs/scipy-dev/lib/python3.9/site-packages/sphinx/builders/__init__.py", line 310, in build_update
    self.build(to_build,
  File "/opt/miniconda/envs/scipy-dev/lib/python3.9/site-packages/sphinx/builders/__init__.py", line 376, in build
    self.write(docnames, list(updated_docnames), method)
  File "/opt/miniconda/envs/scipy-dev/lib/python3.9/site-packages/sphinx/builders/__init__.py", line 568, in write
    self._write_parallel(sorted(docnames),
  File "/opt/miniconda/envs/scipy-dev/lib/python3.9/site-packages/sphinx/builders/__init__.py", line 592, in _write_parallel
    doctree = self.env.get_and_resolve_doctree(firstname, self)
  File "/opt/miniconda/envs/scipy-dev/lib/python3.9/site-packages/sphinx/environment/__init__.py", line 591, in get_and_resolve_doctree
    self.apply_post_transforms(doctree, docname)
  File "/opt/miniconda/envs/scipy-dev/lib/python3.9/site-packages/sphinx/environment/__init__.py", line 637, in apply_post_transforms
    transformer.apply_transforms()
  File "/opt/miniconda/envs/scipy-dev/lib/python3.9/site-packages/sphinx/transforms/__init__.py", line 80, in apply_transforms
    super().apply_transforms()
  File "/opt/miniconda/envs/scipy-dev/lib/python3.9/site-packages/docutils/transforms/__init__.py", line 173, in apply_transforms
    transform.apply(**kwargs)
  File "/opt/miniconda/envs/scipy-dev/lib/python3.9/site-packages/sphinx/transforms/post_transforms/__init__.py", line 35, in apply
    self.run(**kwargs)
  File "/opt/miniconda/envs/scipy-dev/lib/python3.9/site-packages/myst_nb/ext/execution_tables.py", line 79, in run
    for node in self.document.traverse(ExecutionStatsNode):
  File "/opt/miniconda/envs/scipy-dev/lib/python3.9/site-packages/docutils/nodes.py", line 225, in traverse
    warnings.warn('nodes.Node.traverse() is obsoleted by Node.findall().',
PendingDeprecationWarning: nodes.Node.traverse() is obsoleted by Node.findall().

Exception occurred:
  File "/opt/miniconda/envs/scipy-dev/lib/python3.9/site-packages/docutils/nodes.py", line 225, in traverse
    warnings.warn('nodes.Node.traverse() is obsoleted by Node.findall().',
PendingDeprecationWarning: nodes.Node.traverse() is obsoleted by Node.findall().
The full traceback has been saved in /tmp/sphinx-err-ohqk40ub.log, if you want to report the issue to the developers.
Please also report this if it was a user error, so that a better error message can be provided next time.
A bug report can be filed in the tracker at <https://github.com/sphinx-doc/sphinx/issues>. Thanks!
make: *** [Makefile:110: html-build] Error 2
(scipy-dev) ~/projects/scipy (notebook-infra ✗) 
sphinx.errors.SphinxParallelError: DeprecationWarning: There is no current event loop
/home/melissa/projects/scipy/doc/source/notebooks/interp_transition_guide.md: Executing notebook using local CWD [mystnb]
/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/sphinx/util/parallel.py:84: RuntimeWarning: coroutine 'NotebookClient.async_execute' was never awaited
  ret = (errmsg, traceback.format_exc())
RuntimeWarning: Enable tracemalloc to get the object allocation traceback

Traceback (most recent call last):
  File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/sphinx/cmd/build.py", line 281, in build_main
    app.build(args.force_all, args.filenames)
  File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/sphinx/application.py", line 347, in build
    self.builder.build_update()
  File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/sphinx/builders/__init__.py", line 310, in build_update
    self.build(to_build,
  File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/sphinx/builders/__init__.py", line 326, in build
    updated_docnames = set(self.read())
  File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/sphinx/builders/__init__.py", line 431, in read
    self._read_parallel(docnames, nproc=self.app.parallel)
  File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/sphinx/builders/__init__.py", line 487, in _read_parallel
    tasks.join()
  File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/sphinx/util/parallel.py", line 105, in join
    if not self._join_one():
  File "/opt/miniconda/envs/scipy-dev/lib/python3.10/site-packages/sphinx/util/parallel.py", line 126, in _join_one
    raise SphinxParallelError(*result)
sphinx.errors.SphinxParallelError: DeprecationWarning: There is no current event loop

Sphinx parallel build error:
DeprecationWarning: There is no current event loop
make: *** [Makefile:110: html-build] Error 2
(scipy-dev) ~/projects/scipy (notebook-infra ✗)
  1. There are two other docutils Deprecation warnings that I am filtering on conf.py ("The frontend.OptionParser/frontend.Option class will be replaced/removed"). Locally, if I pin docutils<0.19 I don't see those errors, but they still showed up on CI so I added a filter.

From my tests this version I just pushed should work with all Python versions and parallel execution as well. (I didn't need to bump the CircleCI Python version)

Copy link
Member

@tupui tupui left a comment

Choose a reason for hiding this comment

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

Awesome 👏 thanks for tracking this down! Approving on my side. We can try to discuss this tomorrow to get this in. Unless someone wants to merge now which is fine with me too OC 😃

EDIT: folks and maintainers present at todays meeting were in favour of this change.

@mdhaber
Copy link
Contributor

mdhaber commented Apr 5, 2023

This is awesome. Regarding questions 1-3 of your email to the mailing list, I am not personally concerned with 1 (the new doc build dependencies), and I wouldn't want this PR to be held up by 2/3. Can those be addressed if we start to notice a problem?

How do you envision that new tutorials would be added? (e.g. would they all go in this executable notebook section at the bottom? How would that be organized, and what would the relationship be with the existing tutorials?)

Would it be worthwile to convert existing tutorials to this new format (maybe breaking them up into separate pages) so that new tutorials can be fit into the existing "User Guide"?

@ev-br
Copy link
Member

ev-br commented Apr 5, 2023

+1 from me. Would be great to do a test-drive while there's time until the next release.

Note to self to update the interp2d deprecation message to stop pointing to a random gist on somebody's GH account when this is merged.

@rgommers
Copy link
Member

rgommers commented Apr 6, 2023

This looks quite good to me - doc dependencies and build time don't seem to be problems I'd say. One question: there's mention of these as notebooks and being downloadable, but how? I don't see a link or button.

@melissawm
Copy link
Contributor Author

Hi all!

@mdhaber

I am not personally concerned with 1 (the new doc build dependencies), and I wouldn't want this PR to be held up by 2/3. Can those be addressed if we start to notice a problem?

Absolutely, I'd be happy to revisit any of these decisions if we feel like performance is an issue or we want to move these out. Nothing here is irreversible.

How do you envision that new tutorials would be added? (e.g. would they all go in this executable notebook section at the bottom? How would that be organized, and what would the relationship be with the existing tutorials?)

That is an initial proposal that I'm also happy to revisit later, I don't have strong opinions on this.

Would it be worthwile to convert existing tutorials to this new format (maybe breaking them up into separate pages) so that new tutorials can be fit into the existing "User Guide"?

I'd say this is up for discussion. This is an easier way to share executable tutorials with users, but this also relates to the next point.

@rgommers

One question: there's mention of these as notebooks and being downloadable, but how? I don't see a link or button.

This is true - the PyData Sphinx theme, as I understand it, does not readily support the download buttons you would see on other themes (see, for example, https://numpy.org/numpy-tutorials/). However, each individual .md file here, if downloaded, can be opened by jupyter classic or jupyterlab as long as the jupytext extension is installed - so downloading this file allows you to open it as a notebook and execute locally, edit it etc. This can absolutely be perfected here or in the future.

@rgommers
Copy link
Member

rgommers commented Apr 6, 2023

I'd just remove the mention on the front page of the tutorials then that these are downloadable notebooks - it's just going to lead to confusion. Once pydata-sphinx-theme gets support, the statement can be put back.

[skip azp] [skip cirrus] [skip actions]
@j-bowhay
Copy link
Member

j-bowhay commented Apr 7, 2023

Also +1, looks like a nice addition

@tupui
Copy link
Member

tupui commented Apr 7, 2023

Let's get this in 😃 thanks Melissa for the heavy lifting and everyone for the review and testing!

@tupui tupui merged commit 17db361 into scipy:main Apr 7, 2023
2 checks passed
@tupui tupui added this to the 1.11.0 milestone Apr 7, 2023
@melissawm
Copy link
Contributor Author

Thank you all!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Issues related to the SciPy documentation. Also check https://github.com/scipy/scipy.org enhancement A new feature or improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants