Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Using nbformat instead of json #200

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

AntHoneyLam
Copy link

Issue #123

@ianhi
Copy link
Collaborator

ianhi commented Jun 12, 2021

Thanks for working on this @AntHoneyLam !

I'm away for the weekend so I can't look closely for a bit but will next week. But preliminarily I think you will need to add nbformat to the docs requirements in setup.cfg to get the docs to build.

Also I think it may be possible to do the output modification using nbformat? If that is possible it would be good to do as well.

@ianhi
Copy link
Collaborator

ianhi commented Jun 14, 2021

The docs failure:

looks real with this error:

Traceback (most recent call last):
  File "/home/docs/checkouts/readthedocs.org/user_builds/mpl-interactions/envs/200/lib/python3.7/site-packages/sphinx/config.py", line 323, in eval_config_file
    exec(code, namespace)
  File "/home/docs/checkouts/readthedocs.org/user_builds/mpl-interactions/checkouts/200/docs/conf.py", line 26, in <module>
    gogogo_all("../examples", "examples/")
  File "/home/docs/checkouts/readthedocs.org/user_builds/mpl-interactions/checkouts/200/docs/gifmaker.py", line 17, in gogogo_all
    gogogo_gif(nb, to)
  File "/home/docs/checkouts/readthedocs.org/user_builds/mpl-interactions/checkouts/200/docs/gifmaker.py", line 50, in gogogo_gif
    nbformat.write(nb, f)
  File "/home/docs/checkouts/readthedocs.org/user_builds/mpl-interactions/envs/200/lib/python3.7/site-packages/nbformat/__init__.py", line 164, in write
    s = writes(nb, version, **kwargs)
  File "/home/docs/checkouts/readthedocs.org/user_builds/mpl-interactions/envs/200/lib/python3.7/site-packages/nbformat/__init__.py", line 110, in writes
    return versions[version].writes_json(nb, **kwargs)
  File "/home/docs/checkouts/readthedocs.org/user_builds/mpl-interactions/envs/200/lib/python3.7/site-packages/nbformat/v4/nbjson.py", line 54, in writes
    nb = split_lines(nb)
  File "/home/docs/checkouts/readthedocs.org/user_builds/mpl-interactions/envs/200/lib/python3.7/site-packages/nbformat/v4/rwbase.py", line 81, in split_lines
    if output.output_type in {'execute_result', 'display_data'}:
AttributeError: 'dict' object has no attribute 'output_type'

which is because when this was just a dict it was ok to overwrite the output with a custom made dictionary. but now nbformat expects the output to be some sort of nbformat object. So we need to change this parts:

https://github.com/ianhi/mpl-interactions/blob/74966bcc43bca45890151329f19ca0004b1de538/docs/gifmaker.py#L40-L47

to use https://nbformat.readthedocs.io/en/latest/api.html#nbformat.v4.new_output

you can test this locally from the terminal by going to the docs folder and running make html.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants