Skip to content

Commit 7f35bea

Browse files
committed
fix all issues
1 parent 254480f commit 7f35bea

File tree

7 files changed

+63
-33
lines changed

7 files changed

+63
-33
lines changed

doc/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
sys.path.insert(0, os.path.abspath("../.."))
1212

13-
import jupyter_sphinx
13+
import jupyter_sphinx # noqa: E402
1414

1515
project = "Jupyter Sphinx"
1616
copyright = "2019, Jupyter Development Team"

jupyter_sphinx/__init__.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,23 @@
1010
from sphinx.util.fileutil import copy_asset
1111

1212
from ._version import __version__
13-
from .ast import (WIDGET_VIEW_MIMETYPE, CellInput, CellInputNode, CellOutput,
14-
CellOutputNode, CombineCellInputOutput, JupyterCell,
15-
JupyterCellNode, JupyterDownloadRole, JupyterKernelNode,
16-
JupyterWidgetStateNode, JupyterWidgetViewNode,
17-
MimeBundleNode)
13+
from .ast import (
14+
WIDGET_VIEW_MIMETYPE,
15+
CellInput,
16+
CellInputNode,
17+
CellOutput,
18+
CellOutputNode,
19+
CombineCellInputOutput,
20+
JupyterCell,
21+
JupyterCellNode,
22+
JupyterDownloadRole,
23+
JupyterKernelNode,
24+
JupyterWidgetStateNode,
25+
JupyterWidgetViewNode,
26+
MimeBundleNode,
27+
)
1828
from .execute import ExecuteJupyterCells, JupyterKernel
19-
from .thebelab import (ThebeButton, ThebeButtonNode, ThebeOutputNode,
20-
ThebeSourceNode)
29+
from .thebelab import ThebeButton, ThebeButtonNode, ThebeOutputNode, ThebeSourceNode
2130

2231
REQUIRE_URL_DEFAULT = (
2332
"https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js"
@@ -26,10 +35,11 @@
2635

2736
logger = logging.getLogger(__name__)
2837

29-
##############################################################################
3038
# Constants and functions we'll use later
3139

3240
# Used for nodes that do not need to be rendered
41+
42+
3343
def skip(self, node):
3444
raise docutils.nodes.SkipNode
3545

@@ -48,6 +58,7 @@ def halt(self, node):
4858
lambda self, node: self.depart_container(node),
4959
)
5060

61+
5162
# Used to render the container and its children as HTML
5263
def visit_container_html(self, node):
5364
self.body.append(node.visit_html())
@@ -78,7 +89,7 @@ def visit_thebe_source(self, node):
7889
lambda self, node: self.depart_container(node),
7990
)
8091

81-
##############################################################################
92+
8293
# Sphinx callback functions
8394
def builder_inited(app):
8495
"""

jupyter_sphinx/ast.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -618,14 +618,14 @@ def apply(self):
618618
moved_outputs = set()
619619

620620
for cell_node in self.document.traverse(JupyterCellNode):
621-
if cell_node.attributes["execute"] == False:
622-
if cell_node.attributes["hide_code"] == False:
621+
if not cell_node.attributes["execute"]:
622+
if not cell_node.attributes["hide_code"]:
623623
# Cell came from jupyter-input
624624
sibling = cell_node.next_node(descend=False, siblings=True)
625625
if (
626626
isinstance(sibling, JupyterCellNode)
627-
and sibling.attributes["execute"] == False
628-
and sibling.attributes["hide_code"] == True
627+
and not sibling.attributes["execute"]
628+
and sibling.attributes["hide_code"]
629629
):
630630
# Sibling came from jupyter-output, so we merge
631631
cell_node += sibling.children[1]

jupyter_sphinx/execute.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,23 @@ def LoggerAdapterWrapper(logger_adapter):
4343

4444
import jupyter_sphinx as js
4545

46-
from .ast import (CellOutputNode, JupyterCellNode, JupyterKernelNode,
47-
JupyterWidgetStateNode, apply_styling, cell_output_to_nodes,
48-
get_widgets)
46+
from .ast import (
47+
CellOutputNode,
48+
JupyterCellNode,
49+
JupyterKernelNode,
50+
JupyterWidgetStateNode,
51+
apply_styling,
52+
cell_output_to_nodes,
53+
get_widgets,
54+
)
4955
from .thebelab import ThebeButtonNode, add_thebelab_library
50-
from .utils import (blank_nb, default_notebook_names, output_directory,
51-
sphinx_abs_dir, split_on)
56+
from .utils import (
57+
blank_nb,
58+
default_notebook_names,
59+
output_directory,
60+
sphinx_abs_dir,
61+
split_on,
62+
)
5263

5364

5465
class JupyterKernel(Directive):
@@ -88,7 +99,7 @@ def run(self):
8899
]
89100

90101

91-
### Doctree transformations
102+
# Doctree transformations
92103
class ExecuteJupyterCells(SphinxTransform):
93104
"""Execute code cells in Jupyter kernels.
94105
@@ -141,8 +152,9 @@ def apply(self):
141152
kernel_name = default_kernel
142153
file_name = next(default_names)
143154

144-
# Add empty placeholder cells for non-executed nodes so nodes and cells can be zipped
145-
# and the provided input/output can be inserted later
155+
# Add empty placeholder cells for non-executed nodes so nodes
156+
# and cells can be zipped and the provided input/output
157+
# can be inserted later
146158
notebook = execute_cells(
147159
kernel_name,
148160
[
@@ -268,7 +280,7 @@ def apply(self):
268280
doctree.append(JupyterWidgetStateNode(state=get_widgets(notebook)))
269281

270282

271-
### Roles
283+
# Roles
272284

273285

274286
def execute_cells(kernel_name, cells, execute_kwargs):

jupyter_sphinx/thebelab.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ def __init__(self, rawsource="", *children, text="Make live", **attributes):
5454
def html(self):
5555
text = self["text"]
5656
return (
57-
'<button title="{text}" class="thebelab-button" id="thebelab-activate-button" '
57+
'<button title="{text}" class="thebelab-button" '
58+
'id="thebelab-activate-button" '
5859
'onclick="initThebelab()">{text}</button>'.format(text=text)
5960
)
6061

@@ -106,7 +107,8 @@ def add_thebelab_library(doctree, env):
106107
return
107108
else:
108109
js.logger.warning(
109-
"The supplied thebelab configuration should be either a filename or a dictionary."
110+
"The supplied thebelab configuration should be either"
111+
" a filename or a dictionary."
110112
)
111113
return
112114

setup.cfg

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@
22
license_file = LICENSE
33

44
[flake8]
5-
max-line-length = 88
5+
max-line-length = 120
66
extend-ignore = E203
7+
8+
[isort]
9+
profile = black

tests/test_execute.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,20 @@
88
from unittest.mock import Mock
99

1010
import pytest
11-
from docutils.nodes import (container, image, literal, literal_block,
12-
math_block, raw)
11+
from docutils.nodes import container, image, literal, literal_block, math_block, raw
1312
from nbformat import from_dict
1413
from sphinx.addnodes import download_reference
1514
from sphinx.errors import ExtensionError
1615
from sphinx.testing.util import SphinxTestApp, assert_node, path
1716

18-
from jupyter_sphinx.ast import (CellInputNode, CellOutputNode, JupyterCellNode,
19-
JupyterDownloadRole, JupyterWidgetStateNode,
20-
JupyterWidgetViewNode, cell_output_to_nodes)
21-
from jupyter_sphinx.thebelab import (ThebeButtonNode, ThebeOutputNode,
22-
ThebeSourceNode)
17+
from jupyter_sphinx.ast import (
18+
JupyterCellNode,
19+
JupyterDownloadRole,
20+
JupyterWidgetStateNode,
21+
JupyterWidgetViewNode,
22+
cell_output_to_nodes,
23+
)
24+
from jupyter_sphinx.thebelab import ThebeButtonNode, ThebeOutputNode, ThebeSourceNode
2325

2426

2527
@pytest.fixture()

0 commit comments

Comments
 (0)