Skip to content

Commit

Permalink
sagemathgh-36483: Remove spurious diffs in doc build changes
Browse files Browse the repository at this point in the history
    
Remove all spurious and chronic diffs in the changes of our
documentation preview.

Improve CHANGES.html using diffsite. See https://deploy-preview-36483--
sagemath-tobias.netlify.app/changes

diffsite allows to compare changes visually. Scroll until vertical
alignment breaks or search for some diff text.

<!-- ^^^^^
Please provide a concise, informative and self-explanatory title.
Don't put issue numbers in there, do this in the PR body below.
For example, instead of "Fixes sagemath#1234" use "Introduce new method to
calculate 1+1"
-->
<!-- Describe your changes here in detail -->

<!-- Why is this change required? What problem does it solve? -->
<!-- If this PR resolves an open issue, please link to it here. For
example "Fixes sagemath#12345". -->
<!-- If your change requires a documentation PR, please link it
appropriately. -->

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->
<!-- If your change requires a documentation PR, please link it
appropriately -->
<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
<!-- Feel free to remove irrelevant items. -->

- [x] The title is concise, informative, and self-explanatory.
- [x] The description explains in detail what this PR is about.
- [ ] I have linked a relevant issue or discussion.
- [ ] I have created tests covering the changes.
- [ ] I have updated the documentation accordingly.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on
- sagemath#12345: short description why this is a dependency
- sagemath#34567: ...
-->

- sagemath#36475

<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
    
URL: sagemath#36483
Reported by: Kwankyu Lee
Reviewer(s): Matthias Köppe
  • Loading branch information
Release Manager committed Oct 21, 2023
2 parents 3dac1c3 + c81d50f commit d219a84
Show file tree
Hide file tree
Showing 28 changed files with 214 additions and 60 deletions.
70 changes: 61 additions & 9 deletions .github/workflows/doc-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,19 @@ jobs:
git config --global --add safe.directory $(pwd)
git config --global user.email "[email protected]"
git config --global user.name "Build & Test workflow"
# mathjax path in old doc
mathjax_path_from=$(SAGE_USE_CDNS=no /sage/sage -python -c "from sage_docbuild.conf import mathjax_path; print(mathjax_path)")
.ci/retrofit-worktree.sh worktree-image /sage
# Keep track of changes to built HTML
new_version=$(cat src/VERSION.txt)
# mathjax path in new doc
mathjax_path_to=$(SAGE_USE_CDNS=yes /sage/sage -python -c "from sage_docbuild.conf import mathjax_path; print(mathjax_path)")
new_version=$(cat src/VERSION.txt)
# Wipe out chronic diffs between old doc and new doc
(cd /sage/local/share/doc/sage/html/en && \
find . -name "*.html" | xargs sed -i -e '/class="sidebar-brand-text"/ s/Sage [0-9a-z.]* /Sage '"$new_version"' /' \
-e 's;'"$mathjax_path_from"';'"$mathjax_path_to"';' \
-e '\;<script type="application/vnd\.jupyter\.widget-state+json">;,\;</script>; d')
# Create git repo from old doc
(cd /sage/local/share/doc/sage/html/en && \
find . -name "*.html" | xargs sed -i '/class="sidebar-brand-text"/s/Sage [0-9a-z.]* /Sage '$new_version' /;s,'$mathjax_path_from,$mathjax_path_to,';'; \
git init && \
(echo "*.svg binary"; echo "*.pdf binary") >> .gitattributes && \
(echo ".buildinfo"; echo '*.inv'; echo '.git*'; echo '*.svg'; echo '*.pdf'; echo '*.png'; echo 'searchindex.js') > .gitignore; \
Expand Down Expand Up @@ -125,12 +131,58 @@ jobs:
run: |
set -ex
mkdir -p ./docs
# Create changelog
echo '## Preview of CHANGES.html'
(cd /sage/local/share/doc/sage/html/en && git diff --name-only) | tee ./docs/CHANGES.txt
(cd /sage/local/share/doc/sage/html/en && git diff; rm -rf .git) > ./docs/html.diff
echo '## Preview of html.diff'; head -n 400 ./docs/html.diff
(echo '<p><a href="html.diff">HTML diff</a>'; sed -E 's,(.*),<p><a href="\1">\1</a>,' ./docs/CHANGES.txt) > ./docs/CHANGES.html
(cd /sage/local/share/doc/sage/html/en && git commit -a -m 'new')
# Wipe out chronic diffs between old doc and new doc
(cd /sage/local/share/doc/sage/html/en && \
find . -name "*.html" | xargs sed -i -e '\;<script type="application/vnd\.jupyter\.widget-state+json">;,\;</script>; d')
# Create CHANGES.html
echo '<html>' > ./docs/CHANGES.html
echo '<head>' >> ./docs/CHANGES.html
echo '<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/default.min.css">' >> ./docs/CHANGES.html
echo '<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>' >> ./docs/CHANGES.html
echo '<script>hljs.highlightAll();</script>' >> ./docs/CHANGES.html
cat >> ./docs/CHANGES.html << EOF
<script>
document.addEventListener('DOMContentLoaded', () => {
const diffSite = 'https://pianomister.github.io/diffsite/'
const baseDocURL = 'https://sagemath-tobias.netlify.app/'
const diffParagraphs = document.querySelectorAll('p.diff');
diffParagraphs.forEach(paragraph => {
const rootURL = window.location.origin + '/';
const docAnchor = paragraph.querySelector('a');
const path = docAnchor.textContent; // .href doesn't work
const anchor = document.createElement('a');
anchor.href = diffSite + '?url1=' + rootURL + path + '&url2=' + baseDocURL + path;
anchor.textContent = 'compare with the base';
anchor.setAttribute('target', '_blank');
paragraph.appendChild(anchor);
});
});
</script>
EOF
echo '</head>' >> ./docs/CHANGES.html
echo '<body>' >> ./docs/CHANGES.html
(cd /sage/local/share/doc/sage/html/en && git diff HEAD^; rm -rf .git) > ./docs/diff.txt
/sage/sage -python - << EOF
import re, html
with open('./docs/diff.txt', 'r') as f:
diff_text = f.read()
diff_blocks = re.split(r'^(?=diff --git)', diff_text, flags=re.MULTILINE)
out_blocks = []
for block in diff_blocks:
match = re.search(r'^diff --git a/(.*) b/\1', block, flags=re.MULTILINE)
if match:
path = match.group(1)
out_blocks.append(f'<p class="diff"><a href="{path}">{path}</a>&emsp;</p>\n<pre><code class="language-diff">' + html.escape(block).strip() + '</code></pre>')
output_text = '\n'.join(out_blocks)
with open('./docs/diff.html', 'w') as f:
f.write(output_text)
EOF
cat ./docs/diff.html >> ./docs/CHANGES.html
echo '</body>' >> ./docs/CHANGES.html
echo '</html>' >>./docs/CHANGES.html
rm ./docs/diff.txt ./docs/diff.html
(cd /sage/local/share/doc/sage/html/en && git reset --hard HEAD)
# For some reason the deploy step below cannot find /sage/...
# So copy everything from there to local folder
# We also need to replace the symlinks because netlify is not following them
Expand Down
4 changes: 3 additions & 1 deletion src/sage/calculus/transforms/dft.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def plot(self):
S = self.list()
return line([[RR(I[i]), RR(S[i])] for i in range(len(I) - 1)])

def dft(self, chi=lambda x: x):
def dft(self, chi=None):
r"""
A discrete Fourier transform "over `\QQ`" using exact
`N`-th roots of unity.
Expand Down Expand Up @@ -340,6 +340,8 @@ def dft(self, chi=lambda x: x):
implemented Group (permutation, matrix), call .characters()
and test if the index list is the set of conjugacy classes.
"""
if chi is None:
chi = lambda x: x
J = self.index_object() # index set of length N
N = len(J)
S = self.list()
Expand Down
4 changes: 3 additions & 1 deletion src/sage/combinat/finite_state_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,7 @@
from sage.structure.sage_object import SageObject


def full_group_by(l, key=lambda x: x):
def full_group_by(l, key=None):
"""
Group iterable ``l`` by values of ``key``.

Expand Down Expand Up @@ -1003,6 +1003,8 @@ def full_group_by(l, key=lambda x: x):
Here, the result ``r`` has been sorted in order to guarantee a
consistent order for the doctest suite.
"""
if key is None:
key = lambda x: x
elements = defaultdict(list)
original_keys = {}
for item in l:
Expand Down
8 changes: 6 additions & 2 deletions src/sage/combinat/root_system/type_A.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def dynkin_diagram(self):
g.add_edge(i, i+1)
return g

def _latex_dynkin_diagram(self, label=lambda i: i, node=None, node_dist=2):
def _latex_dynkin_diagram(self, label=None, node=None, node_dist=2):
r"""
Return a latex representation of the Dynkin diagram.
Expand All @@ -297,6 +297,8 @@ def _latex_dynkin_diagram(self, label=lambda i: i, node=None, node_dist=2):
\draw[fill=white] (0 cm, 0 cm) circle (.25cm) node[below=4pt]{$1$};
<BLANKLINE>
"""
if label is None:
label = lambda i: i
if node is None:
node = self._latex_draw_node
if self.n > 1:
Expand All @@ -306,7 +308,7 @@ def _latex_dynkin_diagram(self, label=lambda i: i, node=None, node_dist=2):
return ret + "".join(node((i-1)*node_dist, 0, label(i))
for i in self.index_set())

def ascii_art(self, label=lambda i: i, node=None):
def ascii_art(self, label=None, node=None):
"""
Return an ascii art representation of the Dynkin diagram.
Expand All @@ -332,6 +334,8 @@ def ascii_art(self, label=lambda i: i, node=None):
n = self.n
if n == 0:
return ""
if label is None:
label = lambda i: i
if node is None:
node = self._ascii_art_node
ret = "---".join(node(label(i)) for i in range(1,n+1)) + "\n"
Expand Down
8 changes: 6 additions & 2 deletions src/sage/combinat/root_system/type_A_affine.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def dynkin_diagram(self):
g.add_edge(0, n)
return g

def _latex_dynkin_diagram(self, label=lambda i: i, node=None, node_dist=2):
def _latex_dynkin_diagram(self, label=None, node=None, node_dist=2):
r"""
Return a latex representation of the Dynkin diagram.
Expand All @@ -128,6 +128,8 @@ def _latex_dynkin_diagram(self, label=lambda i: i, node=None, node_dist=2):
\draw[fill=white] (3.0 cm, 1.2 cm) circle (.25cm) node[anchor=south east]{$0$};
<BLANKLINE>
"""
if label is None:
label = lambda i: i
if node is None:
node = self._latex_draw_node
if self.n == 1:
Expand All @@ -148,7 +150,7 @@ def _latex_dynkin_diagram(self, label=lambda i: i, node=None, node_dist=2):
ret += node(mid, 1.2, label(0), 'anchor=south east')
return ret

def ascii_art(self, label=lambda i: i, node=None):
def ascii_art(self, label=None, node=None):
"""
Return an ascii art representation of the extended Dynkin diagram.
Expand Down Expand Up @@ -178,6 +180,8 @@ def ascii_art(self, label=lambda i: i, node=None):
O<=>O
2 3
"""
if label is None:
label = lambda i: i
if node is None:
node = self._ascii_art_node
n = self.n
Expand Down
4 changes: 3 additions & 1 deletion src/sage/combinat/root_system/type_A_infinity.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def _latex_(self):
"""
return 'A_{{{}}}'.format(self.n._latex_())

def ascii_art(self, label=lambda i: i, node=None):
def ascii_art(self, label=None, node=None):
"""
Return an ascii art representation of the extended Dynkin diagram.
Expand All @@ -100,6 +100,8 @@ def ascii_art(self, label=lambda i: i, node=None):
0 1 2 3 4 5 6
"""
if label is None:
label = lambda i: i
if node is None:
node = self._ascii_art_node

Expand Down
8 changes: 6 additions & 2 deletions src/sage/combinat/root_system/type_B.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def dynkin_diagram(self):
g.set_edge_label(n-1, n, 2)
return g

def ascii_art(self, label=lambda i: i, node=None):
def ascii_art(self, label=None, node=None):
"""
Return an ascii art representation of the Dynkin diagram.
Expand All @@ -261,6 +261,8 @@ def ascii_art(self, label=lambda i: i, node=None):
O---O---O---O=>=O
3 4 5 6 7
"""
if label is None:
label = lambda i: i
if node is None:
node = self._ascii_art_node
n = self.n
Expand All @@ -271,7 +273,7 @@ def ascii_art(self, label=lambda i: i, node=None):
ret += "".join("{!s:4}".format(label(i)) for i in range(1, n + 1))
return ret

def _latex_dynkin_diagram(self, label=lambda i: i, node=None, node_dist=2, dual=False):
def _latex_dynkin_diagram(self, label=None, node=None, node_dist=2, dual=False):
r"""
Return a latex representation of the Dynkin diagram.
Expand Down Expand Up @@ -307,6 +309,8 @@ def _latex_dynkin_diagram(self, label=lambda i: i, node=None, node_dist=2, dual=
- :meth:`sage.combinat.root_system.type_C.CartanType._latex_dynkin_diagram`
- :meth:`sage.combinat.root_system.type_BC_affine.CartanType._latex_dynkin_diagram`
"""
if label is None:
label = lambda i: i
if node is None:
node = self._latex_draw_node
if self.n == 1:
Expand Down
8 changes: 6 additions & 2 deletions src/sage/combinat/root_system/type_BC_affine.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def _latex_(self):
else:
return "BC_{%s}^{(2)}" % self.n

def _latex_dynkin_diagram(self, label=lambda i: i, node=None, node_dist=2, dual=False):
def _latex_dynkin_diagram(self, label=None, node=None, node_dist=2, dual=False):
r"""
Return a latex representation of the Dynkin diagram.
Expand Down Expand Up @@ -180,6 +180,8 @@ def _latex_dynkin_diagram(self, label=lambda i: i, node=None, node_dist=2, dual=
\draw[fill=white] (0 cm, 0 cm) circle (.25cm) node[below=4pt]{$0$};
<BLANKLINE>
"""
if label is None:
label = lambda i: i
if node is None:
node = self._latex_draw_node
if self.n == 1:
Expand All @@ -206,7 +208,7 @@ def _latex_dynkin_diagram(self, label=lambda i: i, node=None, node_dist=2, dual=
ret += "}\n" + node(0, 0, label(0))
return ret

def ascii_art(self, label=lambda i: i, node=None):
def ascii_art(self, label=None, node=None):
"""
Return a ascii art representation of the extended Dynkin diagram.
Expand All @@ -227,6 +229,8 @@ def ascii_art(self, label=lambda i: i, node=None):
O=<=O
2 3
"""
if label is None:
label = lambda i: i
if node is None:
node = self._ascii_art_node
n = self.n
Expand Down
8 changes: 6 additions & 2 deletions src/sage/combinat/root_system/type_B_affine.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def dynkin_diagram(self):
g.add_edge(0,2)
return g

def _latex_dynkin_diagram(self, label=lambda i: i, node=None, node_dist=2, dual=False):
def _latex_dynkin_diagram(self, label=None, node=None, node_dist=2, dual=False):
r"""
Return a latex representation of the Dynkin diagram.
Expand Down Expand Up @@ -130,6 +130,8 @@ def _latex_dynkin_diagram(self, label=lambda i: i, node=None, node_dist=2, dual=
\draw[fill=white] (6 cm, 0 cm) circle (.25cm) node[below=4pt]{$4$};
<BLANKLINE>
"""
if label is None:
label = lambda i: i
if node is None:
node = self._latex_draw_node
if self.n == 1:
Expand All @@ -155,7 +157,7 @@ def _latex_dynkin_diagram(self, label=lambda i: i, node=None, node_dist=2, dual=
ret += node(i*node_dist, 0, label(i+1))
return ret

def ascii_art(self, label=lambda i: i, node=None):
def ascii_art(self, label=None, node=None):
"""
Return an ascii art representation of the extended Dynkin diagram.
Expand Down Expand Up @@ -184,6 +186,8 @@ def ascii_art(self, label=lambda i: i, node=None):
"""
n = self.n
from .cartan_type import CartanType
if label is None:
label = lambda i: i
if node is None:
node = self._ascii_art_node
if n == 1:
Expand Down
8 changes: 6 additions & 2 deletions src/sage/combinat/root_system/type_C.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def dynkin_diagram(self):
"""
return self.dual().dynkin_diagram().dual()

def _latex_dynkin_diagram(self, label=lambda x: x, node=None, node_dist=2, dual=False):
def _latex_dynkin_diagram(self, label=None, node=None, node_dist=2, dual=False):
r"""
Return a latex representation of the Dynkin diagram.
Expand Down Expand Up @@ -268,9 +268,11 @@ def _latex_dynkin_diagram(self, label=lambda x: x, node=None, node_dist=2, dual=
- :meth:`sage.combinat.root_system.type_C.CartanType._latex_dynkin_diagram`
- :meth:`sage.combinat.root_system.type_BC_affine.CartanType._latex_dynkin_diagram`
"""
if label is None:
label = lambda i: i
return self.dual()._latex_dynkin_diagram(label=label, node=node, node_dist=node_dist, dual=not dual)

def ascii_art(self, label=lambda i: i, node=None):
def ascii_art(self, label=None, node=None):
"""
Return a ascii art representation of the extended Dynkin diagram.
Expand All @@ -289,6 +291,8 @@ def ascii_art(self, label=lambda i: i, node=None):
O---O---O---O=<=O
3 4 5 6 7
"""
if label is None:
label = lambda i: i
return self.dual().ascii_art(label=label, node=node).replace("=>=", "=<=")

def _default_folded_cartan_type(self):
Expand Down
8 changes: 6 additions & 2 deletions src/sage/combinat/root_system/type_C_affine.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def dynkin_diagram(self):
g.add_edge(0,1,2)
return g

def _latex_dynkin_diagram(self, label=lambda i: i, node=None, node_dist=2, dual=False):
def _latex_dynkin_diagram(self, label=None, node=None, node_dist=2, dual=False):
r"""
Return a latex representation of the Dynkin diagram.
Expand Down Expand Up @@ -117,6 +117,8 @@ def _latex_dynkin_diagram(self, label=lambda i: i, node=None, node_dist=2, dual=
\draw[fill=white] (0 cm, 0 cm) circle (.25cm) node[below=4pt]{$0$};
<BLANKLINE>
"""
if label is None:
label = lambda i: i
if node is None:
node = self._latex_draw_node
if self.n == 1:
Expand All @@ -134,7 +136,7 @@ def _latex_dynkin_diagram(self, label=lambda i: i, node=None, node_dist=2, dual=
ret += "}\n" + node(0, 0, label(0))
return ret

def ascii_art(self, label=lambda i: i, node=None):
def ascii_art(self, label=None, node=None):
"""
Return a ascii art representation of the extended Dynkin diagram.
Expand All @@ -156,6 +158,8 @@ def ascii_art(self, label=lambda i: i, node=None):
O<=>O
0 1
"""
if label is None:
label = lambda i: i
if node is None:
node = self._ascii_art_node
n = self.n
Expand Down
Loading

0 comments on commit d219a84

Please sign in to comment.