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

Error accessing notebook.metadata.language_info.file_extension #63

Closed
chrisjsewell opened this issue Mar 12, 2020 · 3 comments
Closed
Labels
bug Something isn't working

Comments

@chrisjsewell
Copy link
Member

chrisjsewell commented Mar 12, 2020

Trying to add a notebook to documentation in executablebooks/jupyter-cache#35, I'm getting this error

(expand for traceback)

  File "//anaconda/envs/mistune/lib/python3.7/site-packages/jupyter_sphinx/execute.py", line 259, in write_notebook_output
    ext = notebook.metadata.language_info.file_extension
  File "//anaconda/envs/mistune/lib/python3.7/site-packages/ipython_genutils/ipstruct.py", line 134, in __getattr__
    raise AttributeError(key)
AttributeError: file_extension

# Sphinx version: 2.4.0
# Python version: 3.7.6 (CPython)
# Docutils version: 0.16 release
# Jinja2 version: 2.11.1
# Last messages:
#   done
#   loading intersphinx inventory from https://docs.python.org/3.7/objects.inv...
#   building [mo]: targets for 0 po files that are out of date
#   building [html]: targets for 4 source files that are out of date
#   updating environment:
#   [new config]
#   4 added, 0 changed, 0 removed
#   reading sources... [ 25%] develop/contributing
#   reading sources... [ 50%] index
#   reading sources... [ 75%] using/api
# Loaded extensions:
#   sphinx.ext.mathjax (2.4.0) from //anaconda/envs/mistune/lib/python3.7/site-packages/sphinx/ext/mathjax.py
#   sphinxcontrib.applehelp (1.0.1) from //anaconda/envs/mistune/lib/python3.7/site-packages/sphinxcontrib/applehelp/__init__.py
#   sphinxcontrib.devhelp (1.0.1) from //anaconda/envs/mistune/lib/python3.7/site-packages/sphinxcontrib/devhelp/__init__.py
#   sphinxcontrib.htmlhelp (1.0.2) from //anaconda/envs/mistune/lib/python3.7/site-packages/sphinxcontrib/htmlhelp/__init__.py
#   sphinxcontrib.serializinghtml (1.1.3) from //anaconda/envs/mistune/lib/python3.7/site-packages/sphinxcontrib/serializinghtml/__init__.py
#   sphinxcontrib.qthelp (1.0.2) from //anaconda/envs/mistune/lib/python3.7/site-packages/sphinxcontrib/qthelp/__init__.py
#   alabaster (0.7.12) from //anaconda/envs/mistune/lib/python3.7/site-packages/alabaster/__init__.py
#   myst_parser (0.6.0) from //anaconda/envs/mistune/lib/python3.7/site-packages/myst_parser/__init__.py
#   sphinx_togglebutton (0.0.2) from //anaconda/envs/mistune/lib/python3.7/site-packages/sphinx_togglebutton/__init__.py
#   jupyter_sphinx (0.2.4a1) from //anaconda/envs/mistune/lib/python3.7/site-packages/jupyter_sphinx/__init__.py
#   myst_nb (0.2.1) from //anaconda/envs/mistune/lib/python3.7/site-packages/myst_nb/__init__.py
#   sphinx.ext.intersphinx (2.4.0) from //anaconda/envs/mistune/lib/python3.7/site-packages/sphinx/ext/intersphinx.py
#   pandas_sphinx_theme (unknown version) from //anaconda/envs/mistune/lib/python3.7/site-packages/pandas_sphinx_theme/__init__.py
Traceback (most recent call last):
  File "//anaconda/envs/mistune/lib/python3.7/site-packages/ipython_genutils/ipstruct.py", line 132, in __getattr__
    result = self[key]
KeyError: 'file_extension'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "//anaconda/envs/mistune/lib/python3.7/site-packages/sphinx/cmd/build.py", line 276, in build_main
app.build(args.force_all, filenames)
File "//anaconda/envs/mistune/lib/python3.7/site-packages/sphinx/application.py", line 349, in build
self.builder.build_update()
File "//anaconda/envs/mistune/lib/python3.7/site-packages/sphinx/builders/init.py", line 300, in build_update
len(to_build))
File "//anaconda/envs/mistune/lib/python3.7/site-packages/sphinx/builders/init.py", line 312, in build
updated_docnames = set(self.read())
File "//anaconda/envs/mistune/lib/python3.7/site-packages/sphinx/builders/init.py", line 419, in read
self._read_serial(docnames)
File "//anaconda/envs/mistune/lib/python3.7/site-packages/sphinx/builders/init.py", line 440, in _read_serial
self.read_doc(docname)
File "//anaconda/envs/mistune/lib/python3.7/site-packages/sphinx/builders/init.py", line 480, in read_doc
doctree = read_doc(self.app, self.env, self.env.doc2path(docname))
File "//anaconda/envs/mistune/lib/python3.7/site-packages/sphinx/io.py", line 316, in read_doc
pub.publish()
File "//anaconda/envs/mistune/lib/python3.7/site-packages/docutils/core.py", line 218, in publish
self.settings)
File "//anaconda/envs/mistune/lib/python3.7/site-packages/sphinx/io.py", line 130, in read
self.parse()
File "//anaconda/envs/mistune/lib/python3.7/site-packages/docutils/readers/init.py", line 77, in parse
self.parser.parse(self.input, document)
File "//anaconda/envs/mistune/lib/python3.7/site-packages/myst_nb/parser.py", line 133, in parse
write_notebook_output(ntbk, str(output_dir), doc_filename)
File "//anaconda/envs/mistune/lib/python3.7/site-packages/jupyter_sphinx/execute.py", line 259, in write_notebook_output
ext = notebook.metadata.language_info.file_extension
File "//anaconda/envs/mistune/lib/python3.7/site-packages/ipython_genutils/ipstruct.py", line 134, in getattr
raise AttributeError(key)
AttributeError: file_extension

@AakashGfude notes something similar in
#55 (comment)

Aakash can you add here the full traceback from the log file

Not sure where the actual fault here lies yet?
@akhmerov it also maybe is related to jupyter-sphinx, any ideas?

@chrisjsewell chrisjsewell added the bug Something isn't working label Mar 12, 2020
@chrisjsewell chrisjsewell changed the title Error accessing attribute of notebook language info Error accessing attribute of notebook language_info Mar 12, 2020
@chrisjsewell
Copy link
Member Author

I think the issue may lie with jupyter-sphinx expecting the presence of notebook.metadata.language_info.file_extension here:
https://github.com/jupyter/jupyter-sphinx/blob/970097e01c1b7af04372be202aed572de68d2d20/jupyter_sphinx/execute.py#L259

Below is the notebook is being read and, as you can see, it doesn't actually have this attribute.

{
 "nbformat": 4,
 "nbformat_minor": 2,
 "metadata": {
  "language_info": {
   "name": "python",
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   }
  },
  "orig_nbformat": 2,
  "file_extension": ".py",
  "mimetype": "text/x-python",
  "name": "python",
  "npconvert_exporter": "python",
  "pygments_lexer": "ipython3",
  "version": 3
 },
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "(use/api)=\n",
    "\n",
    "# Python API"
   ]
  }
 ]
}

Note, the notebook was initially created by VS Code:

Name: Python
Id: ms-python.python
Description: Linting, Debugging (multi-threaded, remote), Intellisense, Jupyter Notebooks, code formatting, refactoring, unit tests, snippets, and more.
Version: 2020.2.64397
Publisher: Microsoft
VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=ms-python.python 

@chrisjsewell chrisjsewell changed the title Error accessing attribute of notebook language_info Error accessing notebook.metadata.language_info.file_extension Mar 12, 2020
@chrisjsewell
Copy link
Member Author

Yep fixed if I add notebook.metadata.language_info.file_extension = ".ipynb"

@chrisjsewell
Copy link
Member Author

raised at microsoft/vscode-python#10544

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant