Skip to content

Commit e21c9eb

Browse files
committed
remove __init__ from JupyterCellNode and JupyterKernelNode
__init__ needs to be compatible with docutils.nodes.Element to facilitate doctree copying. Given that each type of node is constructed in just one place (in the associated directive) this does not break encapulation too badly.
1 parent 739c770 commit e21c9eb

File tree

1 file changed

+13
-22
lines changed

1 file changed

+13
-22
lines changed

jupyter_sphinx/execute.py

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@ class JupyterKernel(Directive):
6262

6363
def run(self):
6464
return [JupyterKernelNode(
65-
kernel_name=self.arguments[0] if self.arguments else '',
66-
kernel_id=self.options.get('id', ''),
65+
'',
66+
kernel_name=self.arguments[0].strip() if self.arguments else '',
67+
kernel_id=self.options.get('id', '').strip(),
6768
)]
6869

6970

@@ -74,13 +75,6 @@ class JupyterKernelNode(docutils.nodes.Element):
7475
next, if any, JupyterKernelNode) should be executed in a separate kernel.
7576
"""
7677

77-
def __init__(self, kernel_name, kernel_id):
78-
super().__init__(
79-
'',
80-
kernel_name=kernel_name.strip(),
81-
kernel_id=kernel_id.strip(),
82-
)
83-
8478

8579
def csv_option(s):
8680
return [p.strip() for p in s.split(',')] if s else []
@@ -153,7 +147,16 @@ def run(self):
153147
self.assert_has_content()
154148
content = self.content
155149

156-
return [JupyterCellNode(content, self.options)]
150+
return [JupyterCellNode(
151+
'',
152+
docutils.nodes.literal_block(
153+
text='\n'.join(content),
154+
),
155+
hide_code=('hide-code' in self.options),
156+
hide_output=('hide-output' in self.options),
157+
code_below=('code-below' in self.options),
158+
raises=self.options.get('raises'),
159+
)]
157160

158161

159162
class JupyterCellNode(docutils.nodes.container):
@@ -163,18 +166,6 @@ class JupyterCellNode(docutils.nodes.container):
163166
doctree-transformation step.
164167
"""
165168

166-
def __init__(self, source_lines, options):
167-
return super().__init__(
168-
'',
169-
docutils.nodes.literal_block(
170-
text='\n'.join(source_lines),
171-
),
172-
hide_code=('hide-code' in options),
173-
hide_output=('hide-output' in options),
174-
code_below=('code-below' in options),
175-
raises=options.get('raises'),
176-
)
177-
178169

179170
### Doctree transformations
180171

0 commit comments

Comments
 (0)