Skip to content

Commit

Permalink
use SimpleNamespace for domain data
Browse files Browse the repository at this point in the history
  • Loading branch information
mgeier committed Apr 8, 2024
1 parent d3b2864 commit d24abad
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/nbsphinx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import re
import subprocess
import sys
from types import SimpleNamespace
from urllib.parse import unquote
import uuid

Expand Down Expand Up @@ -600,9 +601,9 @@ def parse(self, inputstring, document):

# NB: The source file could have a different suffix
# if nbsphinx_custom_formats is used.
notebookfile = env.docname + '.ipynb'
doc_data.notebook = notebookfile
auxfile = os.path.join(domain.auxdir, notebookfile)
notebook_file = env.docname + '.ipynb'
doc_data.notebook_file = notebook_file
auxfile = os.path.join(domain.auxdir, notebook_file)
sphinx.util.ensuredir(os.path.dirname(auxfile))
resources['nbsphinx_save_notebook'] = auxfile

Expand Down Expand Up @@ -1641,13 +1642,12 @@ def merge_domaindata(self, docnames, otherdata):
self.data[docname] = otherdata[docname]

def process_doc(self, env, docname, document):
# TODO: namespace? notebook, local_files, thumbnail
# TODO: default for local_files: set()
# TODO: default for thumbnail: {}
# TODO: default for has_widgets: False
# TODO: default for notebook: empty string? None?
# TODO: notebook vs. notebookfile?
self.data[docname] = None # TODO: empty dict?
self.data[docname] = SimpleNamespace(
thumbnail={},
notebook_file=None,
local_files=set(),
has_widgets=False,
)

def has_widgets(self):
return any(v.has_widgets for v in self.data.values())
Expand Down Expand Up @@ -1683,8 +1683,8 @@ def html_collect_pages(app):
notebooks, 'copying notebooks ... ',
'brown', len(notebooks)):
sphinx.util.copyfile(
os.path.join(domain.auxdir, data.notebook),
os.path.join(app.builder.outdir, data.notebook))
os.path.join(domain.auxdir, data.notebook_file),
os.path.join(app.builder.outdir, data.notebook_file))

context = {
'nbsphinx_responsive_width': app.config.nbsphinx_responsive_width,
Expand Down

0 comments on commit d24abad

Please sign in to comment.