MyST-NB icon indicating copy to clipboard operation
MyST-NB copied to clipboard

UnboundLocalError in convert.py

Open funkyfuture opened this issue 2 years ago • 1 comments

Describe the bug

context I added myst-nb to an existing documentation that includes a .ipynb file and invoke make html.

expectation A neat result.

bug But instead 🐛UnboundLocalError🐛 happens Here's an error message I ran into...

# Sphinx version: 5.3.0
# Python version: 3.11.2 (CPython)
# Docutils version: 0.19 
# Jinja2 version: 3.1.2
# Last messages:
#   updating environment:
#   [new config]
#   11 added, 0 changed, 0 removed
#   reading sources... [  9%] api
#   reading sources... [ 18%] api-note
#   reading sources... [ 27%] changes
#   reading sources... [ 36%] design
#   reading sources... [ 45%] extending
#   reading sources... [ 54%] genindex
#   reading sources... [ 63%] getting_started
# Loaded extensions:
#   sphinx.ext.mathjax (5.3.0) from /home/user/.local/share/hatch/env/virtual/project/pFhfpXCQ/docs/lib/python3.11/site-packages/sphinx/ext/mathjax.py
#   sphinxcontrib.applehelp (1.0.4) from /home/user/.local/share/hatch/env/virtual/project/pFhfpXCQ/docs/lib/python3.11/site-packages/sphinxcontrib/applehelp/__init__.py
#   sphinxcontrib.devhelp (1.0.2) from /home/user/.local/share/hatch/env/virtual/project/pFhfpXCQ/docs/lib/python3.11/site-packages/sphinxcontrib/devhelp/__init__.py
#   sphinxcontrib.htmlhelp (2.0.1) from /home/user/.local/share/hatch/env/virtual/project/pFhfpXCQ/docs/lib/python3.11/site-packages/sphinxcontrib/htmlhelp/__init__.py
#   sphinxcontrib.serializinghtml (1.1.5) from /home/user/.local/share/hatch/env/virtual/project/pFhfpXCQ/docs/lib/python3.11/site-packages/sphinxcontrib/serializinghtml/__init__.py
#   sphinxcontrib.qthelp (1.0.3) from /home/user/.local/share/hatch/env/virtual/project/pFhfpXCQ/docs/lib/python3.11/site-packages/sphinxcontrib/qthelp/__init__.py
#   alabaster (0.7.13) from /home/user/.local/share/hatch/env/virtual/project/pFhfpXCQ/docs/lib/python3.11/site-packages/alabaster/__init__.py
#   autoclasstoc (1.6.0) from /home/user/.local/share/hatch/env/virtual/project/pFhfpXCQ/docs/lib/python3.11/site-packages/autoclasstoc/__init__.py
#   myst_nb (0.17.1) from /home/user/.local/share/hatch/env/virtual/project/pFhfpXCQ/docs/lib/python3.11/site-packages/myst_nb/__init__.py
#   sphinx.ext.autodoc.preserve_defaults (5.3.0) from /home/user/.local/share/hatch/env/virtual/project/pFhfpXCQ/docs/lib/python3.11/site-packages/sphinx/ext/autodoc/preserve_defaults.py
#   sphinx.ext.autodoc.type_comment (5.3.0) from /home/user/.local/share/hatch/env/virtual/project/pFhfpXCQ/docs/lib/python3.11/site-packages/sphinx/ext/autodoc/type_comment.py
#   sphinx.ext.autodoc.typehints (5.3.0) from /home/user/.local/share/hatch/env/virtual/project/pFhfpXCQ/docs/lib/python3.11/site-packages/sphinx/ext/autodoc/typehints.py
#   sphinx.ext.autodoc (5.3.0) from /home/user/.local/share/hatch/env/virtual/project/pFhfpXCQ/docs/lib/python3.11/site-packages/sphinx/ext/autodoc/__init__.py
#   sphinx.ext.autosummary (5.3.0) from /home/user/.local/share/hatch/env/virtual/project/pFhfpXCQ/docs/lib/python3.11/site-packages/sphinx/ext/autosummary/__init__.py
#   sphinx.ext.doctest (5.3.0) from /home/user/.local/share/hatch/env/virtual/project/pFhfpXCQ/docs/lib/python3.11/site-packages/sphinx/ext/doctest.py
#   sphinx.ext.intersphinx (5.3.0) from /home/user/.local/share/hatch/env/virtual/project/pFhfpXCQ/docs/lib/python3.11/site-packages/sphinx/ext/intersphinx.py
#   sphinx.ext.viewcode (5.3.0) from /home/user/.local/share/hatch/env/virtual/project/pFhfpXCQ/docs/lib/python3.11/site-packages/sphinx/ext/viewcode.py
#   sphinxcontrib.fulltoc (unknown version) from /home/user/.local/share/hatch/env/virtual/project/pFhfpXCQ/docs/lib/python3.11/site-packages/sphinxcontrib/fulltoc.py
Traceback (most recent call last):
  File "/home/user/.local/share/hatch/env/virtual/project/pFhfpXCQ/docs/lib/python3.11/site-packages/sphinx/cmd/build.py", line 281, in build_main
    app.build(args.force_all, args.filenames)
  File "/home/user/.local/share/hatch/env/virtual/project/pFhfpXCQ/docs/lib/python3.11/site-packages/sphinx/application.py", line 347, in build
    self.builder.build_update()
  File "/home/user/.local/share/hatch/env/virtual/project/pFhfpXCQ/docs/lib/python3.11/site-packages/sphinx/builders/__init__.py", line 310, in build_update
    self.build(to_build,
  File "/home/user/.local/share/hatch/env/virtual/project/pFhfpXCQ/docs/lib/python3.11/site-packages/sphinx/builders/__init__.py", line 326, in build
    updated_docnames = set(self.read())
                           ^^^^^^^^^^^
  File "/home/user/.local/share/hatch/env/virtual/project/pFhfpXCQ/docs/lib/python3.11/site-packages/sphinx/builders/__init__.py", line 433, in read
    self._read_serial(docnames)
  File "/home/user/.local/share/hatch/env/virtual/project/pFhfpXCQ/docs/lib/python3.11/site-packages/sphinx/builders/__init__.py", line 454, in _read_serial
    self.read_doc(docname)
  File "/home/user/.local/share/hatch/env/virtual/project/pFhfpXCQ/docs/lib/python3.11/site-packages/sphinx/builders/__init__.py", line 510, in read_doc
    publisher.publish()
  File "/home/user/.local/share/hatch/env/virtual/project/pFhfpXCQ/docs/lib/python3.11/site-packages/docutils/core.py", line 224, in publish
    self.document = self.reader.read(self.source, self.parser,
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.local/share/hatch/env/virtual/project/pFhfpXCQ/docs/lib/python3.11/site-packages/sphinx/io.py", line 104, in read
    self.parse()
  File "/home/user/.local/share/hatch/env/virtual/project/pFhfpXCQ/docs/lib/python3.11/site-packages/docutils/readers/__init__.py", line 76, in parse
    self.parser.parse(self.input, document)
  File "/home/user/.local/share/hatch/env/virtual/project/pFhfpXCQ/docs/lib/python3.11/site-packages/myst_nb/sphinx_.py", line 87, in parse
    notebook = nb_reader.read(inputstring)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.local/share/hatch/env/virtual/project/pFhfpXCQ/docs/lib/python3.11/site-packages/myst_nb/core/read.py", line 38, in standard_nb_read
    return nbf.reads(text, as_version=NOTEBOOK_VERSION)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.local/share/hatch/env/virtual/project/pFhfpXCQ/docs/lib/python3.11/site-packages/nbformat/__init__.py", line 91, in reads
    nb = convert(nb, as_version)
         ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.local/share/hatch/env/virtual/project/pFhfpXCQ/docs/lib/python3.11/site-packages/nbformat/converter.py", line 56, in convert
    converted = convert_function(nb)
                ^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.local/share/hatch/env/virtual/project/pFhfpXCQ/docs/lib/python3.11/site-packages/nbformat/v2/convert.py", line 47, in upgrade
    ws.cells.append(newcell)
                    ^^^^^^^
UnboundLocalError: cannot access local variable 'newcell' where it is not associated with a value

Reproduce the bug

see above.

List your environment

No response

funkyfuture avatar Apr 06 '23 22:04 funkyfuture

Thanks for opening your first issue here! Engagement like this is essential for open source projects! :hugs:
If you haven't done so already, check out EBP's Code of Conduct. Also, please try to follow the issue template as it helps other community members to contribute more effectively.
If your issue is a feature request, others may react to it, to raise its prominence (see Feature Voting).
Welcome to the EBP community! :tada:

welcome[bot] avatar Apr 06 '23 22:04 welcome[bot]