-
-
Notifications
You must be signed in to change notification settings - Fork 528
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
Revive sage live doc using jupyter-sphinx #36144
Merged
vbraun
merged 42 commits into
sagemath:develop
from
kwankyu:p/rework-on-live-sage-documentation
Oct 31, 2023
Merged
Changes from 41 commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
8121580
Rework sage live doc
kwankyu 19c1c09
Style activate button
kwankyu 62928db
Fix activate button
kwankyu 6ae42f5
Fix a typo
kwankyu 12afe87
Fix the patch to jupyter-sphinx
kwankyu fd494e7
Adjust css styles of thebe elements
kwankyu fc84c30
Showcase live doc on a-tour-of-sage
kwankyu 5f4dcb1
More edits on a-tour-of-Sage
kwankyu 8bb20a6
Support furo dark mode
kwankyu 27977dc
Fine fixes
kwankyu 482d51f
Minor edits to the front of sage doc
kwankyu fafce5c
Add more comments to renamed jupyter-sphinx-furo.js
kwankyu 910e866
Activate live doc in github doc previews
kwankyu 5f8fb1a
Adjust button styles
kwankyu b5ff41a
Minimize the patch on jupyter-sphinx
kwankyu 1ec45d6
Fix doctests
kwankyu a5dd948
Fix a doctest
kwankyu da82502
Allow custom binder repo
kwankyu 225446f
%display latex is the default
kwankyu 612d396
Use unofficial binder repo temporarily
kwankyu 49dfc56
Minor css tweak
kwankyu 7102fe0
Use the official thing
kwankyu 747f3c5
Edit installation doc
kwankyu 59ccc74
More edits of installation guide
kwankyu 1061ab5
Use binder repo sagemath/sage-binder-env/dev
kwankyu d72bc2a
Fix thebe config error
kwankyu f80b252
Binder repo branch part can have slashes
kwankyu d644d93
Merge branch 'develop' into p/36144
kwankyu 3fbf531
Edit doc
kwankyu b5c20e8
Merge branch 'develop' into p/36144/p/rework-on-live-sage-documentation
kwankyu 91c6fa5
Merge branch 'develop' into p/36144/p/rework-on-live-sage-documentation
kwankyu c21421f
Show kernel status
kwankyu 5b98e92
Merge branch 'develop' into p/36144/p/rework-on-live-sage-documentation
kwankyu f833de2
Merge branch 'develop' into p/36144/p/rework-on-live-sage-documentation
kwankyu ffa0af9
Fix for auto mode
kwankyu 51fb8a0
Fix auto mode also in javascript
kwankyu b516acc
More edits on a-tour-of-sage
kwankyu 2a150fb
Make auto mode behave according to system preference
kwankyu f592be0
Patch jupyter-sphinx a bit more
kwankyu 33205e4
Fixes for conda failures
kwankyu 146d170
Fix jupyter-sphinx css for dark mode
kwankyu 857741c
Live doc for CI is left for further discussion
kwankyu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
tarball=jupyter_sphinx-VERSION.tar.gz | ||
sha1=241f6dfcd3aae4f44f330e2ba76480011b382d3d | ||
md5=e7ab370d9793be5b20bce5447ccbd45b | ||
cksum=2021246952 | ||
sha1=fb2abdd5e35da0886b12d45a6373c4dbcc24b244 | ||
md5=130daa6be810976c9f8e30aa04011e50 | ||
cksum=2882523000 | ||
upstream_url=https://pypi.io/packages/source/j/jupyter_sphinx/jupyter_sphinx-VERSION.tar.gz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.3.2 | ||
0.4.0.p0 |
57 changes: 57 additions & 0 deletions
57
build/pkgs/jupyter_sphinx/patches/0001-Patch-for-sage-live-doc.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
From 5bffbe38302c695123779f87300d84090b4bd118 Mon Sep 17 00:00:00 2001 | ||
From: Kwankyu Lee <[email protected]> | ||
Date: Mon, 28 Aug 2023 00:18:59 +0900 | ||
Subject: [PATCH] Patch for sage live doc | ||
|
||
--- | ||
jupyter_sphinx/__init__.py | 4 ++-- | ||
jupyter_sphinx/execute.py | 11 +++++++++++ | ||
2 files changed, 13 insertions(+), 2 deletions(-) | ||
|
||
diff --git a/jupyter_sphinx/__init__.py b/jupyter_sphinx/__init__.py | ||
index 34af884..b7ca8ee 100644 | ||
--- a/jupyter_sphinx/__init__.py | ||
+++ b/jupyter_sphinx/__init__.py | ||
@@ -31,7 +31,7 @@ from .thebelab import ThebeButton, ThebeButtonNode, ThebeOutputNode, ThebeSource | ||
REQUIRE_URL_DEFAULT = ( | ||
"https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js" | ||
) | ||
-THEBELAB_URL_DEFAULT = "https://unpkg.com/thebelab@^0.4.0" | ||
+THEBELAB_URL_DEFAULT = "https://unpkg.com/thebe@latest/lib/index.js" | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
@@ -186,7 +186,7 @@ def setup(app): | ||
app.add_config_value("jupyter_sphinx_embed_url", None, "html") | ||
|
||
# thebelab config, can be either a filename or a dict | ||
- app.add_config_value("jupyter_sphinx_thebelab_config", None, "html") | ||
+ app.add_config_value("jupyter_sphinx_thebelab_config", None, "env") | ||
app.add_config_value("jupyter_sphinx_thebelab_url", THEBELAB_URL_DEFAULT, "html") | ||
|
||
# linenos config | ||
diff --git a/jupyter_sphinx/execute.py b/jupyter_sphinx/execute.py | ||
index 558a26b..de44455 100644 | ||
--- a/jupyter_sphinx/execute.py | ||
+++ b/jupyter_sphinx/execute.py | ||
@@ -152,6 +152,17 @@ class ExecuteJupyterCells(SphinxTransform): | ||
kernel_name = default_kernel | ||
file_name = next(default_names) | ||
|
||
+ # Save time when jupyter notebook execution is not necessary | ||
+ if not any(not "execute" in node or node["execute"] for node in nodes): | ||
+ # mimics empty cell output for each node | ||
+ for node in nodes: | ||
+ source = node.children[0] | ||
+ source.attributes["classes"].append("code_cell") | ||
+ node.attributes["cm_language"] = kernel_name | ||
+ node += CellOutputNode(classes=["cell_output"]) | ||
+ apply_styling(node, thebe_config) | ||
+ continue | ||
+ | ||
# Add empty placeholder cells for non-executed nodes so nodes | ||
# and cells can be zipped and the provided input/output | ||
# can be inserted later | ||
-- | ||
2.42.0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* from https://codemirror.net/5/theme/monokai.css */ | ||
/* Based on Sublime Text's Monokai theme */ | ||
|
||
.cm-s-monokai.CodeMirror { background: #272822; color: #f8f8f2; } | ||
.cm-s-monokai div.CodeMirror-selected { background: #49483E; } | ||
.cm-s-monokai .CodeMirror-line::selection, .cm-s-monokai .CodeMirror-line > span::selection, .cm-s-monokai .CodeMirror-line > span > span::selection { background: rgba(73, 72, 62, .99); } | ||
.cm-s-monokai .CodeMirror-line::-moz-selection, .cm-s-monokai .CodeMirror-line > span::-moz-selection, .cm-s-monokai .CodeMirror-line > span > span::-moz-selection { background: rgba(73, 72, 62, .99); } | ||
.cm-s-monokai .CodeMirror-gutters { background: #272822; border-right: 0px; } | ||
.cm-s-monokai .CodeMirror-guttermarker { color: white; } | ||
.cm-s-monokai .CodeMirror-guttermarker-subtle { color: #d0d0d0; } | ||
.cm-s-monokai .CodeMirror-linenumber { color: #d0d0d0; } | ||
.cm-s-monokai .CodeMirror-cursor { border-left: 1px solid #f8f8f0; } | ||
|
||
.cm-s-monokai span.cm-comment { color: #75715e; } | ||
.cm-s-monokai span.cm-atom { color: #ae81ff; } | ||
.cm-s-monokai span.cm-number { color: #ae81ff; } | ||
|
||
.cm-s-monokai span.cm-comment.cm-attribute { color: #97b757; } | ||
.cm-s-monokai span.cm-comment.cm-def { color: #bc9262; } | ||
.cm-s-monokai span.cm-comment.cm-tag { color: #bc6283; } | ||
.cm-s-monokai span.cm-comment.cm-type { color: #5998a6; } | ||
|
||
.cm-s-monokai span.cm-property, .cm-s-monokai span.cm-attribute { color: #a6e22e; } | ||
.cm-s-monokai span.cm-keyword { color: #f92672; } | ||
.cm-s-monokai span.cm-builtin { color: #66d9ef; } | ||
.cm-s-monokai span.cm-string { color: #e6db74; } | ||
|
||
.cm-s-monokai span.cm-variable { color: #f8f8f2; } | ||
.cm-s-monokai span.cm-variable-2 { color: #9effff; } | ||
.cm-s-monokai span.cm-variable-3, .cm-s-monokai span.cm-type { color: #66d9ef; } | ||
.cm-s-monokai span.cm-def { color: #fd971f; } | ||
.cm-s-monokai span.cm-bracket { color: #f8f8f2; } | ||
.cm-s-monokai span.cm-tag { color: #f92672; } | ||
.cm-s-monokai span.cm-header { color: #ae81ff; } | ||
.cm-s-monokai span.cm-link { color: #ae81ff; } | ||
.cm-s-monokai span.cm-error { background: #f92672; color: #f8f8f0; } | ||
|
||
.cm-s-monokai .CodeMirror-activeline-background { background: #373831; } | ||
.cm-s-monokai .CodeMirror-matchingbracket { | ||
text-decoration: underline; | ||
color: white !important; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
div.jupyter_container { | ||
margin: .5rem 0; | ||
} | ||
|
||
div.jupyter_container + div.jupyter_container { | ||
margin: 0 0 .5rem 0; | ||
} | ||
|
||
div.jupyter_container div.cell_input pre { | ||
margin: .5rem; | ||
} | ||
|
||
div.jupyter_container div.cell_output div.output { | ||
margin: .5rem; | ||
} | ||
|
||
.thebelab-cell .jp-OutputArea { | ||
margin: 0 .5rem; | ||
} | ||
|
||
.thebelab-cell .jp-OutputArea-output { | ||
margin: 0 0 .5rem 0; | ||
overflow-x: auto; | ||
} | ||
|
||
.thebelab-button { | ||
margin: .5rem 0 .5rem .5rem; | ||
padding: 0 .5rem; | ||
min-width: 2rem; | ||
} | ||
|
||
.thebelab-button:active { | ||
color: #0f0fff; | ||
} | ||
|
||
.thebelab-busy { | ||
margin-left: .5rem; | ||
} | ||
|
||
#thebelab-activate-button { | ||
position: fixed; | ||
right: -5.1rem; | ||
top: calc(50% - 1.5rem); | ||
width: 6rem; | ||
border-radius: 1rem; | ||
transition-property: right; | ||
transition-duration: 300ms; | ||
transition-timing-function: ease-out; | ||
z-index: 100; | ||
} | ||
|
||
#thebelab-activate-button:hover { | ||
right: .4rem; | ||
} | ||
|
||
#thebelab-activate-button:active { | ||
color: #0f0fff; | ||
} | ||
|
||
body[data-theme="dark"] { | ||
.jupyter_container { | ||
color: white; | ||
background-color: black; | ||
} | ||
|
||
.jupyter_container .highlight { | ||
background-color: black; | ||
} | ||
|
||
.thebelab-button { | ||
color: #d0d0d0; | ||
background-color: #383838; | ||
} | ||
|
||
.thebelab-button:active { | ||
color: #368ce2; | ||
} | ||
|
||
#thebelab-activate-button { | ||
background-color: #383838; | ||
} | ||
|
||
#thebelab-activate-button:active { | ||
color: #368ce2; | ||
} | ||
|
||
.thebelab-cell .jp-OutputArea-output { | ||
color: white; | ||
background-color: black; | ||
} | ||
|
||
.thebelab-cell .jp-OutputArea-output pre { | ||
color: white; | ||
background-color: black; | ||
} | ||
} | ||
|
||
@media (prefers-color-scheme: dark) { | ||
body[data-theme="auto"] { /* the same styles with body[data-theme="dark"] */ | ||
.jupyter_container { | ||
color: white; | ||
background-color: black; | ||
} | ||
|
||
.jupyter_container .highlight { | ||
background-color: black; | ||
} | ||
|
||
.thebelab-button { | ||
color: #d0d0d0; | ||
background-color: #383838; | ||
} | ||
|
||
.thebelab-button:active { | ||
color: #368ce2; | ||
} | ||
|
||
#thebelab-activate-button { | ||
background-color: #383838; | ||
} | ||
|
||
#thebelab-activate-button:active { | ||
color: #368ce2; | ||
} | ||
|
||
.thebelab-cell .jp-OutputArea-output { | ||
color: white; | ||
background-color: black; | ||
} | ||
|
||
.thebelab-cell .jp-OutputArea-output pre { | ||
color: white; | ||
background-color: black; | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
// Change the editor theme according to the furo light/dark/auto mode | ||
function changeTheme(editor, theme) { | ||
if (theme === 'dark') { | ||
editor.setOption('theme', 'monokai'); // the same with pygments dark style in conf.py | ||
} else if (theme === 'auto' && window.matchMedia('(prefers-color-scheme: dark)').matches) { | ||
editor.setOption('theme', 'monokai'); | ||
} else { | ||
editor.setOption('theme', 'default'); | ||
} | ||
} | ||
|
||
// Change the editor theme of all CodeMirror cells | ||
function changeThemeAll(theme) { | ||
const querySet = document.querySelectorAll('.CodeMirror'); | ||
for (var i = 0; i < querySet.length; i++) { | ||
changeTheme(querySet[i].CodeMirror, theme); | ||
} | ||
} | ||
|
||
// Use the theme data of the body element set by setTheme function | ||
// defined in https://github.com/pradyunsg/furo/blob/main/src/furo/assets/scripts/furo.js | ||
const body = document.body; | ||
const observer1 = new MutationObserver((mutationsList) => { | ||
for (let mutation of mutationsList) { | ||
if (mutation.type === 'attributes' && mutation.attributeName === 'data-theme') { | ||
const theme = body.dataset.theme; | ||
changeThemeAll(theme); | ||
} | ||
} | ||
}); | ||
observer1.observe(body, { attributes: true }); | ||
|
||
|
||
// In the furo auto mode, we watch prefers-color-scheme and use the theme data | ||
// of the body element to change the CodeMirror editor theme | ||
const prefersDarkMode = window.matchMedia('(prefers-color-scheme: dark)'); | ||
|
||
function handlePrefersColorSchemeChange(e) { | ||
const theme = body.dataset.theme; | ||
if (theme === 'auto') { | ||
changeThemeAll(theme); | ||
} | ||
} | ||
|
||
prefersDarkMode.addEventListener('change', handlePrefersColorSchemeChange); | ||
|
||
|
||
// Change the editor theme of a new CodeMirror cell. | ||
const callback = function(mutationsList, observer) { | ||
for(const mutation of mutationsList) { | ||
if (mutation.type === 'childList') { | ||
const theme = body.dataset.theme; | ||
for (const addedNode of mutation.addedNodes) { | ||
if (addedNode.classList && addedNode.classList.contains('CodeMirror')) { | ||
changeTheme(addedNode.CodeMirror, theme); | ||
}}}}}; | ||
const observer2 = new MutationObserver(callback); | ||
observer2.observe(document.getElementsByClassName("content")[0], { childList: true, subtree: true }); | ||
|
||
|
||
// Listen to the kernel status changes | ||
// https://thebe.readthedocs.io/en/stable/events.html | ||
thebelab.on("status", function (evt, data) { | ||
if (data.status === 'building') { | ||
const elements = document.querySelectorAll('.thebelab-cell'); | ||
elements.forEach(element => { | ||
element.style.filter = 'opacity(50%)'; | ||
}); | ||
const element = document.getElementById("thebelab-activate-button"); | ||
element.innerHTML = "Building"; | ||
element.style.right = '.4rem'; | ||
} | ||
else if (data.status === 'built') { | ||
const elements = document.querySelectorAll('.thebelab-cell'); | ||
elements.forEach(element => { | ||
element.style.filter = 'opacity(60%)'; | ||
}); | ||
const element = document.getElementById("thebelab-activate-button"); | ||
element.innerHTML = "Built"; | ||
element.style.right = '.4rem'; | ||
} | ||
else if (data.status === 'launching') { | ||
const elements = document.querySelectorAll('.thebelab-cell'); | ||
elements.forEach(element => { | ||
element.style.filter = 'opacity(70%)'; | ||
}); | ||
const element = document.getElementById("thebelab-activate-button"); | ||
element.innerHTML = "Launching"; | ||
element.style.right = '.4rem'; | ||
} | ||
else if (data.status === 'failed') { | ||
const elements = document.querySelectorAll('.thebelab-cell'); | ||
elements.forEach(element => { | ||
element.style.filter = 'opacity(50%)'; | ||
}); | ||
const element = document.getElementById("thebelab-activate-button"); | ||
element.innerHTML = 'Failed: ' + data.message; | ||
element.style.right = '.4rem'; | ||
element.style.width = 'auto'; | ||
element.style.color = 'red'; | ||
} | ||
else if (data.status === 'ready') { | ||
const elements = document.querySelectorAll('.thebelab-cell'); | ||
elements.forEach(element => { | ||
element.style.filter = 'opacity(100%)'; | ||
}); | ||
const element = document.getElementById("thebelab-activate-button"); | ||
element.innerHTML = "Ready"; | ||
element.style.right = null; | ||
// Run custom code when the kernel is ready | ||
const kernel = data.kernel; | ||
kernel.requestExecute({code: "%display latex"}); | ||
} | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should activate it in the doc-build workflow only on pushes to release tags.
Elsewhere, in particular in a PR, I think it is problematic that the live doc uses a Sage version that is unrelated to the tested branch!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right.
I will change this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How we will incorporate live doc to our ci (if ever) will be discussed separately. So I will remove the two lines.
But as this PR now needs review, I will keep the lines for now. If it is decided to merge this PR, then I will immediately push a commit to remove them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To conditionalize its use in "build.yml" , one could use
$GITHUB_REF
https://docs.github.com/en/actions/learn-github-actions/variables