Skip to content

Commit

Permalink
Merge branch 'develop' into oriented_matroids
Browse files Browse the repository at this point in the history
  • Loading branch information
thecaligarmo committed Sep 7, 2024
2 parents eb1cc24 + 24698e7 commit ea931e4
Show file tree
Hide file tree
Showing 2,890 changed files with 72,372 additions and 79,330 deletions.
78 changes: 50 additions & 28 deletions .ci/create-changes-html.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#!/bin/sh
if [ $# != 2 ]; then
echo >&2 "usage: $0 BASE_DOC_COMMIT DOC_REPO"
echo >&2 "creates CHANGES.html in the current directory"
echo >&2 "for the diffs of DOC_REPO against BASE_DOC_COMMIT"
echo >&2 "Usage: $0 DIFF_TEXT DOC_REPO"
echo >&2 "This script generates a CHANGES.html file in the current directory"
echo >&2 "and adds anchor targets in the documents within DOC_REPO"
echo >&2 "based on the diff hunks in the DIFF_TEXT file."
exit 1
fi
BASE_DOC_COMMIT="$1"
DIFF_TEXT="$1"
DOC_REPOSITORY="$2"

# Wipe out chronic diffs between old doc and new doc
(cd $DOC_REPOSITORY && find . -name "*.html" | xargs sed -i -e '\;<script type="application/vnd\.jupyter\.widget-state+json">;,\;</script>; d')
# Create CHANGES.html
echo '<html>' > CHANGES.html
echo '<head>' >> CHANGES.html
Expand All @@ -19,79 +18,102 @@ echo '<script>hljs.highlightAll();</script>' >> CHANGES.html
cat >> CHANGES.html << EOF
<script>
document.addEventListener('DOMContentLoaded', () => {
const baseDocURL = 'https://sagemath.netlify.app'
// This URL is hardcoded in the file .github/workflows/doc-publish.yml.
// See NETLIFY_ALIAS of the "Deploy to Netlify" step.
const baseDocURL = 'https://doc-develop--sagemath.netlify.app'
const diffSite = 'https://pianomister.github.io/diffsite'
const diffParagraphs = document.querySelectorAll('p.diff');
diffParagraphs.forEach(paragraph => {
const rootURL = window.location.origin;
const docAnchor = paragraph.querySelector('a'); // first "a" element
const docAnchor = paragraph.querySelector('a');
const url = new URL(docAnchor.href);
const path = url.pathname;
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.innerHTML += '&nbsp;&nbsp;';
paragraph.appendChild(anchor);
paragraph.innerHTML += '&nbsp;';
const hunkAnchors = paragraph.querySelectorAll('a.hunk');
hunkAnchors.forEach(hunkAnchor => {
const hunks = paragraph.parentNode.querySelectorAll('p.hunk');
hunks.forEach(hunk => {
const hunkAnchor = hunk.querySelector('a');
const url = new URL(hunkAnchor.href);
const path = url.pathname;
const pathHash = path + url.hash.replace('#', '%23');
const anchor = document.createElement('a');
anchor.href = diffSite + '/?url1=' + rootURL + pathHash + '&url2=' + baseDocURL + path;
anchor.textContent = hunkAnchor.textContent;
anchor.textContent = 'compare with the base';
anchor.setAttribute('target', '_blank');
paragraph.appendChild(anchor);
paragraph.innerHTML += '&nbsp;';
hunk.innerHTML += '&nbsp;&nbsp;';
hunk.appendChild(anchor);
});
});
});
</script>
EOF
echo '</head>' >> CHANGES.html
echo '<body>' >> CHANGES.html
(cd $DOC_REPOSITORY && git diff $BASE_DOC_COMMIT -- "*.html") > diff.txt
python3 - << EOF
import os, re, html
with open('diff.txt', 'r') as f:
from itertools import chain
with open('$DIFF_TEXT', '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:
doc = match.group(1)
file_path = os.path.join('$DOC_REPOSITORY', doc)
path = match.group(1)
file_path = os.path.join('$DOC_REPOSITORY', path)
try:
with open(file_path, 'r') as file:
content = file.readlines()
except FileNotFoundError:
content = []
count = 0
hunks = []
hunk_lines = []
in_hunk = False
for line in block.splitlines():
if line.startswith('@@ -'):
if hunk_lines:
hunks.append('<pre><code class="language-diff">'
+ html.escape('\n'.join(hunk_lines)).strip()
+ '</code></pre>')
hunk_lines = []
search_result = re.search(r'@@ -(\d+),(\d+) \+(\d+),(\d+)', line)
if search_result:
line_number = int(search_result.group(3))
for i in range(line_number - 1, -1, -1):
if content[i].startswith('<'):
line_number = int(search_result.group(3)) - 1
span = int(search_result.group(4))
for i in chain(range(line_number, line_number + span), range(line_number - 1, -1, -1)):
try:
ln = content[i]
except IndexError:
continue
for idx, char in enumerate(ln):
if not char.isspace():
break
else:
idx = len(ln)
if ln.startswith('<', idx) and not ln.startswith('</', idx):
count += 1
content[i] = f'<span id="hunk{count}" style="visibility: hidden;"></span>' + content[i]
content[i] = ln[:idx] + f'<span id="hunk{count}" style="visibility: hidden;"></span>' + ln[idx:]
hunks.append(f'<p class="hunk"><a href="{path}#hunk{count}" class="hunk" target="_blank">hunk #{count}</a></p>')
break
hunk_lines.append(line)
if hunk_lines:
hunks.append('<pre><code class="language-diff">'
+ html.escape('\n'.join(hunk_lines)).strip()
+ '</code></pre>')
if content:
with open(file_path, 'w') as file:
file.writelines(content)
path = doc
hunks = '&nbsp;'.join(f'<a href="{path}#hunk{i+1}" class="hunk" target="_blank">#{i + 1}</a>' for i in range(count))
out_blocks.append(f'<p class="diff"><a href="{path}">{doc}</a>&nbsp;' + hunks + '&emsp;</p>'
+ '\n<pre><code class="language-diff">'
+ html.escape(block).strip() + '</code></pre>')
out_blocks.append(f'<div class="diff"><p class="diff"><a href="{path}">{path}</a></p>\n' + '\n'.join(hunks) + '\n</div>')
output_text = '\n'.join(out_blocks)
with open('diff.html', 'w') as f:
f.write(output_text)
EOF
cat diff.html >> CHANGES.html
echo '</body>' >> CHANGES.html
echo '</html>' >> CHANGES.html
rm diff.txt diff.html
rm diff.html
71 changes: 0 additions & 71 deletions .ci/set_labels_by_changes.sh

This file was deleted.

28 changes: 17 additions & 11 deletions .ci/write-dockerfile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ ADD="ADD $__CHOWN"
RUN=RUN
cat <<EOF
ARG BASE_IMAGE=$(eval echo "${FULL_BASE_IMAGE_AND_TAG}")
FROM \${BASE_IMAGE} as with-system-packages
FROM \${BASE_IMAGE} AS with-system-packages
EOF
case $SYSTEM in
debian*|ubuntu*)
Expand Down Expand Up @@ -199,7 +199,7 @@ EOF
*)
cat <<EOF
ARG BASE_IMAGE
FROM \${BASE_IMAGE} as with-system-packages
FROM \${BASE_IMAGE} AS with-system-packages
EOF
INSTALL=$(sage-print-system-package-command $SYSTEM install " ")
;;
Expand Down Expand Up @@ -260,9 +260,15 @@ case ${DOCKER_BUILDKIT-0} in
CHECK_STATUS_THEN='STATUS=$(cat STATUS 2>/dev/null); case "$STATUS" in ""|0) ;; *) exit $STATUS;; esac; '
esac

if [ -n "$GITHUB_ACTIONS" ]; then
cat <<EOF
ENV GITHUB_ACTIONS=1
EOF
fi

cat <<EOF
FROM with-system-packages as bootstrapped
FROM with-system-packages AS bootstrapped
#:bootstrapping:
RUN rm -rf /new /sage/.git
$ADD Makefile VERSION.txt COPYING.txt condarc.yml README.md bootstrap bootstrap-conda configure.ac sage .homebrew-build-env tox.ini Pipfile.m4 .gitignore /new/
Expand All @@ -277,8 +283,8 @@ $ADD .upstream.d /new/.upstream.d
ADD .ci /.ci
RUN if [ -d /sage ]; then \
echo "### Incremental build from \$(cat /sage/VERSION.txt)" && \
printf '/src\n!/src/doc/bootstrap\n!/src/bin\n!/src/*.m4\n!/src/*.toml\n!/src/VERSION.txt\n' >> /sage/.gitignore && \
printf '/src\n!/src/doc/bootstrap\n!/src/bin\n!/src/*.m4\n!/src/*.toml\n!/src/VERSION.txt\n' >> /new/.gitignore && \
printf '/src/*\n!/src/doc/bootstrap\n!/src/bin\n!/src/*.m4\n!/src/*.toml\n!/src/VERSION.txt\n' >> /sage/.gitignore && \
printf '/src/*\n!/src/doc/bootstrap\n!/src/bin\n!/src/*.m4\n!/src/*.toml\n!/src/VERSION.txt\n' >> /new/.gitignore && \
if ! (cd /new && /.ci/retrofit-worktree.sh worktree-image /sage); then \
echo "retrofit-worktree.sh failed, falling back to replacing /sage"; \
for a in local logs; do \
Expand All @@ -295,7 +301,7 @@ WORKDIR /sage
ARG BOOTSTRAP="${BOOTSTRAP-./bootstrap}"
$RUN sh -x -c "\${BOOTSTRAP}" $ENDRUN $THEN_SAVE_STATUS
FROM bootstrapped as configured
FROM bootstrapped AS configured
#:configuring:
RUN $CHECK_STATUS_THEN mkdir -p logs/pkgs; rm -f config.log; ln -s logs/pkgs/config.log config.log
ARG CONFIGURE_ARGS="${CONFIGURE_ARGS:---enable-build-as-root}"
Expand All @@ -311,7 +317,7 @@ EOF
fi
cat <<EOF
FROM configured as with-base-toolchain
FROM configured AS with-base-toolchain
# We first compile base-toolchain because otherwise lots of packages are missing their dependency on 'patch'
ARG NUMPROC=8
ENV MAKE="make -j\${NUMPROC}"
Expand All @@ -321,7 +327,7 @@ ENV SAGE_CHECK_PACKAGES="!cython,!r,!python3,!gap,!cysignals,!linbox,!git,!ppl,!
#:toolchain:
$RUN $CHECK_STATUS_THEN make \${USE_MAKEFLAGS} base-toolchain $ENDRUN $THEN_SAVE_STATUS
FROM with-base-toolchain as with-targets-pre
FROM with-base-toolchain AS with-targets-pre
ARG NUMPROC=8
ENV MAKE="make -j\${NUMPROC}"
ARG USE_MAKEFLAGS="-k V=0"
Expand All @@ -331,7 +337,7 @@ ENV SAGE_CHECK_PACKAGES="!cython,!r,!python3,!gap,!cysignals,!linbox,!git,!ppl,!
ARG TARGETS_PRE="all-sage-local"
$RUN $CHECK_STATUS_THEN make SAGE_SPKG="sage-spkg -y -o" \${USE_MAKEFLAGS} \${TARGETS_PRE} $ENDRUN $THEN_SAVE_STATUS
FROM with-targets-pre as with-targets
FROM with-targets-pre AS with-targets
ARG NUMPROC=8
ENV MAKE="make -j\${NUMPROC}"
ARG USE_MAKEFLAGS="-k V=0"
Expand All @@ -348,12 +354,12 @@ RUN cd /new && rm -rf .git && \
mv src /sage/src; \
cd /sage && ./bootstrap && ./config.status; \
fi; \
cd /sage && rm -rf /new .git
cd /sage && rm -rf .git; rm -rf /new || echo "(error ignored)"
ARG TARGETS="build"
$RUN $CHECK_STATUS_THEN make SAGE_SPKG="sage-spkg -y -o" \${USE_MAKEFLAGS} \${TARGETS} $ENDRUN $THEN_SAVE_STATUS
FROM with-targets as with-targets-optional
FROM with-targets AS with-targets-optional
ARG NUMPROC=8
ENV MAKE="make -j\${NUMPROC}"
ARG USE_MAKEFLAGS="-k V=0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
// from .devcontainer/portability-devcontainer.json.in
// See https://aka.ms/devcontainer.json for format details.
{
"name": "centos-stream-9-python3.9-minimal (≥ 8-core)",
"name": "centos-stream-9-minimal (≥ 8-core)",
"build": {
"dockerfile": "portability-Dockerfile",
// See tox.ini for definitions
"args": {
"SYSTEM_FACTOR": "centos-stream-9-python3.9",
"SYSTEM_FACTOR": "centos-stream-9",
"PACKAGE_FACTOR": "minimal",
"DOCKER_TARGET": "with-targets",
"DOCKER_TAG": "dev"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
// from .devcontainer/portability-devcontainer.json.in
// See https://aka.ms/devcontainer.json for format details.
{
"name": "centos-7-devtoolset-gcc_11-minimal (≥ 8-core)",
"name": "centos-stream-9-python3.12-minimal (≥ 8-core)",
"build": {
"dockerfile": "portability-Dockerfile",
// See tox.ini for definitions
"args": {
"SYSTEM_FACTOR": "centos-7-devtoolset-gcc_11",
"SYSTEM_FACTOR": "centos-stream-9-python3.12",
"PACKAGE_FACTOR": "minimal",
"DOCKER_TARGET": "with-targets",
"DOCKER_TAG": "dev"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
// from .devcontainer/portability-devcontainer.json.in
// See https://aka.ms/devcontainer.json for format details.
{
"name": "centos-7-devtoolset-gcc_11-standard (≥ 8-core)",
"name": "centos-stream-9-python3.12-standard (≥ 8-core)",
"build": {
"dockerfile": "portability-Dockerfile",
// See tox.ini for definitions
"args": {
"SYSTEM_FACTOR": "centos-7-devtoolset-gcc_11",
"SYSTEM_FACTOR": "centos-stream-9-python3.12",
"PACKAGE_FACTOR": "standard",
"DOCKER_TARGET": "with-targets",
"DOCKER_TAG": "dev"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
// from .devcontainer/portability-devcontainer.json.in
// See https://aka.ms/devcontainer.json for format details.
{
"name": "centos-stream-9-python3.9-standard (≥ 8-core)",
"name": "centos-stream-9-standard (≥ 8-core)",
"build": {
"dockerfile": "portability-Dockerfile",
// See tox.ini for definitions
"args": {
"SYSTEM_FACTOR": "centos-stream-9-python3.9",
"SYSTEM_FACTOR": "centos-stream-9",
"PACKAGE_FACTOR": "standard",
"DOCKER_TARGET": "with-targets",
"DOCKER_TAG": "dev"
Expand Down
Loading

0 comments on commit ea931e4

Please sign in to comment.