Skip to content

Commit

Permalink
Merge branch 'fix-frontend-petsc' into 'master'
Browse files Browse the repository at this point in the history
Fix frontend PETSc and relax notebook format requirements

See merge request ogs/ogs!4764
  • Loading branch information
bilke committed Oct 16, 2023
2 parents 1402565 + 254dcfd commit 6755be8
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 70 deletions.
125 changes: 62 additions & 63 deletions Tests/Data/Notebooks/testrunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,66 @@ def save_to_website(exec_notebook_file, web_path):
shutil.copytree(figures_path, symlink_figures_path)


def check_and_modify_frontmatter():
# Check frontmatter has its own cell
first_cell = nb["cells"][0]
if (
first_cell.cell_type == "markdown"
and first_cell.source.startswith("+++")
and not first_cell.source.endswith("+++")
):
print(
f"Error: {notebook_filename} notebook metadata is not a separate cell (in markdown: separate by two newlines)!"
)
success = False

# Modify metadata
first_cell = nb["cells"][0]
if first_cell.source.startswith("---"):
print(
f"Error: {notebook_filename} frontmatter is not in TOML format! Use +++ delimitiers!"
)
success = False
first_cell.source = first_cell.source.replace("+++\n", "+++\nnotebook = true\n", 1)

# Insert Jupyter header with notebook source and binderhub link in second cell
repo = "https://gitlab.opengeosys.org/ogs/ogs"
branch = "master"
if "CI_MERGE_REQUEST_SOURCE_PROJECT_URL" in os.environ:
repo = os.environ["CI_MERGE_REQUEST_SOURCE_PROJECT_URL"]
branch = os.environ["CI_MERGE_REQUEST_SOURCE_BRANCH_NAME"]
binder_link = f"https://mybinder.org/v2/gh/bilke/binder-ogs-requirements/master?urlpath=git-pull%3Frepo={repo}%26urlpath=lab/tree/ogs/{notebook_file_path_relative}%26branch={branch}"
text = f"""
<div class="note">
<p style="margin-top: 0; margin-bottom: 0;">
<img style="margin-top: 0; margin-bottom: 0; height: 2em;" class="inline-block mr-2 no-fancybox"
src="https://upload.wikimedia.org/wikipedia/commons/3/38/Jupyter_logo.svg" alt="">
This page is based on a Jupyter notebook."""
if is_jupytext:
download_file_name = (
Path(convert_notebook_file)
.rename(Path(convert_notebook_file).with_suffix(".ipynb"))
.name
)
text += f"""
<a href="./{download_file_name}" download="{download_file_name}"><img class="no-fancybox" style="display: inline; margin-top: 0; margin-bottom: 0; margin-left: 1em;" src="https://img.shields.io/static/v1?label=Download:&message={download_file_name}&color=blue" /></a>"""
text += f"""
<a href="{repo}/-/blob/{branch}/{notebook_file_path_relative}"><img src="https://img.shields.io/static/v1?label=Source:&message={notebook_filename}&color=brightgreen" class="no-fancybox"
style="display: inline; margin-top: 0; margin-bottom: 0; margin-left: 1em;" /></a>
<a href="{binder_link}">
<img class="no-fancybox" style="display: inline; margin-top: 0; margin-bottom: 0; margin-left: 1em;"
src="https://img.shields.io/static/v1?label=&message=Launch notebook&color=5c5c5c&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABwAAAAcCAYAAAByDd+UAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAC4jAAAuIwF4pT92AAAAB3RJTUUH4gsEADkvyr8GjAAABQZJREFUSMeVlnlsVFUUh7/7ZukwpQxdoK2yGGgqYFKMQkyDUVBZJECQEERZVLQEa4iKiggiFjfqbkADhVSgEVkETVSiJBATsEIRja1RoCwuU5gC7Qww03Zm3rzrH/dOfJSZUm4y6Xt9957vnnN/55wruI7RVjMNQAA3AiX6bxw4BTQAQQDvnF1pbYjrAAEUAmXADGAQ0AOQwCWgHqgGdgCRdNBrAm2wW4A1wN2ACZwG/gbcQBFwg/Z2I/AS0JoKanQzmoXAamA0cBx4EhgDTAYmAvcArwNhYD6wHHDbNts9D20LlgMrgWPAXKAO/j8rPc8A5uiNAUwH9tjnddfDAn1mFkJWyoRR58hsv8KIfraAz/QvC3golf2UwEBZBYGyCoJfj/LFz/ceDxRJ09Hccbz/6dDu0ozg7lICZRVXrNFQEyWaDmAkkNslMAnSE59x9IrsMVt8awBP4rI3P9acs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VzTZm9pnjNuLDLXT97gKdRKXUWXUvt3qUNqX1oYz2Bj1H3mXPABh22JlRnuBl4DHWPAVgKfAjIzkDntYB6hIHFKPXO0gbLUQp0oO49Xv1eCXySCtYtDzt56kU159moQulDqfEccAD4FDgEJFLBrgtog4I6r36oG0IC1d0DqNZEOhjAfzgw6LulUF3CAAAAJXRFWHRkYXRlOmNyZWF0ZQAyMDE4LTExLTA0VDAwOjU3OjQ3LTA0OjAwLtN9UwAAACV0RVh0ZGF0ZTptb2RpZnkAMjAxOC0xMS0wNFQwMDo1Nzo0Ny0wNDowMF+Oxe8AAAAASUVORK5CYII=" />
</a>"""
text += f"""</p></div>\n\n"""

second_cell = nb["cells"][1]
if second_cell.cell_type == "markdown":
second_cell.source = text + second_cell.source
else:
# Insert a new markdown cell
nb["cells"].insert(1, nbformat.v4.new_markdown_cell(text))


# Script arguments
parser = argparse.ArgumentParser(description="Jupyter notebook testrunner.")
parser.add_argument("notebooks", metavar="N", nargs="+", help="Notebooks to test.")
Expand Down Expand Up @@ -152,69 +212,8 @@ def save_to_website(exec_notebook_file, web_path):

# Write new notebook
with open(convert_notebook_file, "w", encoding="utf-8") as f:
repo = "https://gitlab.opengeosys.org/ogs/ogs"
branch = "master"
if "CI_MERGE_REQUEST_SOURCE_PROJECT_URL" in os.environ:
repo = os.environ["CI_MERGE_REQUEST_SOURCE_PROJECT_URL"]
branch = os.environ["CI_MERGE_REQUEST_SOURCE_BRANCH_NAME"]

# Check frontmatter has its own cell
first_cell = nb["cells"][0]
if (
first_cell.cell_type == "markdown"
and first_cell.source.startswith("+++")
and not first_cell.source.endswith("+++")
):
print(
f"Error: {notebook_filename} notebook metadata is not a separate cell (in markdown: separate by two newlines)!"
)
success = False

# Check second cell is markdown
second_cell = nb["cells"][1]
if second_cell.cell_type != "markdown":
print(
f"Error: {notebook_filename} first cell after the frontmatter needs to be a markdown cell! Move the first Python cell below."
)
success = False

# Modify metadata
first_cell = nb["cells"][0]
if first_cell.source.startswith("---"):
print(
f"Error: {notebook_filename} frontmatter is not in TOML format! Use +++ delimitiers!"
)
success = False
first_cell.source = first_cell.source.replace(
"+++\n", "+++\nnotebook = true\n", 1
)

# Insert Jupyter header with notebook source and binderhub link
binder_link = f"https://mybinder.org/v2/gh/bilke/binder-ogs-requirements/master?urlpath=git-pull%3Frepo={repo}%26urlpath=lab/tree/ogs/{notebook_file_path_relative}%26branch={branch}"
text = f"""
<div class="note">
<p style="margin-top: 0; margin-bottom: 0;">
<img style="margin-top: 0; margin-bottom: 0; height: 2em;" class="inline-block mr-2 no-fancybox"
src="https://upload.wikimedia.org/wikipedia/commons/3/38/Jupyter_logo.svg" alt="">
This page is based on a Jupyter notebook."""
if is_jupytext:
download_file_name = (
Path(convert_notebook_file)
.rename(Path(convert_notebook_file).with_suffix(".ipynb"))
.name
)
text += f"""
<a href="./{download_file_name}" download="{download_file_name}"><img class="no-fancybox" style="display: inline; margin-top: 0; margin-bottom: 0; margin-left: 1em;" src="https://img.shields.io/static/v1?label=Download:&message={download_file_name}&color=blue" /></a>"""
text += f"""
<a href="{repo}/-/blob/{branch}/{notebook_file_path_relative}"><img src="https://img.shields.io/static/v1?label=Source:&message={notebook_filename}&color=brightgreen" class="no-fancybox"
style="display: inline; margin-top: 0; margin-bottom: 0; margin-left: 1em;" /></a>
<a href="{binder_link}">
<img class="no-fancybox" style="display: inline; margin-top: 0; margin-bottom: 0; margin-left: 1em;"
src="https://img.shields.io/static/v1?label=&message=Launch notebook&color=5c5c5c&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABwAAAAcCAYAAAByDd+UAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAC4jAAAuIwF4pT92AAAAB3RJTUUH4gsEADkvyr8GjAAABQZJREFUSMeVlnlsVFUUh7/7ZukwpQxdoK2yGGgqYFKMQkyDUVBZJECQEERZ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78Pkxh9JEwU4JlGsYbO3a+c7g50/esFGIqcBb4fEzgNBlWwgI2AVsAH13V0oL1K5LvNcBOYACwsfb7qiX3n2mcmGXGirPjHf8uPHqw/Xy/IeuAV/TG3gaOAGyfPwJUbm4HosAdpKilzk7vIVT1iAPTTWG8Of5MY/vIFn8Pt2UVZkfbqi0hvFrFlcBaQNo2DKoxt6CqjQ84nzKktkV+YIE+hz1OaUVyou0iKx41BAR02KYB7wMdnWBJm4aOgOz8MWUDTpa6/NazGdUlo8c2ZuVukdBWfOnCtHlffXAwdPsEK2o47Ju0i2MysAt1xxkLtOpwpwzpFd4+sOHXKHDAIa16YNTJrJzS3x9ZVdvoy+WbecNTLfUCs7Xd/aQr3umGy0rgshIhQ8pNhpSmIeVzTZm9pnjNuLDLXT97gKdRKXUWXUvt3qUNqX1oYz2Bj1H3mXPABh22JlRnuBl4DHWPAVgKfAjIzkDntYB6hIHFKPXO0gbLUQp0oO49Xv1eCXySCtYtDzt56kU159moQulDqfEccAD4FDgEJFLBrgtog4I6r36oG0IC1d0DqNZEOhjAfzgw6LulUF3CAAAAJXRFWHRkYXRlOmNyZWF0ZQAyMDE4LTExLTA0VDAwOjU3OjQ3LTA0OjAwLtN9UwAAACV0RVh0ZGF0ZTptb2RpZnkAMjAxOC0xMS0wNFQwMDo1Nzo0Ny0wNDowMF+Oxe8AAAAASUVORK5CYII=" />
</a>"""
text += f"""</p></div>\n\n"""
second_cell.source = text + second_cell.source

if args.hugo:
check_and_modify_frontmatter()
nbformat.write(nb, f)

status_string = ""
Expand Down
2 changes: 1 addition & 1 deletion scripts/ci/extends/template-build-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
ctest_arguments="${ctest_arguments} -LE large"
fi
if [[ "$CI_MERGE_REQUEST_LABELS" =~ [.*web\ only.*] ]]; then
if [[ "$CI_MERGE_REQUEST_LABELS" =~ .*web\ only.* ]]; then
ctest_arguments="${ctest_arguments} -R nb-"
fi
Expand Down
2 changes: 2 additions & 0 deletions scripts/ci/jobs/web-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ preview web site:
- scripts/ci/jobs/web.yml
- scripts/ci/jobs/web-preview.yml
- Tests/Data/**/*.ipynb
- Tests/Data/**/*.md
- Tests/Data/Notebooks/testrunner.py
artifacts:
paths:
- web/public
Expand Down
13 changes: 7 additions & 6 deletions scripts/cmake/DependenciesExternalProject.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,14 @@ if(OGS_USE_PETSC)
if(NOT "--download-fc" IN_LIST OGS_PETSC_CONFIG_OPTIONS)
list(APPEND _configure_opts --with-fc=0)
endif()
if(DEFINED ENV{CC})
list(APPEND _configure_opts --with-cc=$ENV{CC})
if(NOT "${HOSTNAME}" MATCHES "frontend.*")
if(DEFINED ENV{CC})
list(APPEND _configure_opts --with-cc=$ENV{CC})
endif()
if(DEFINED ENV{CXX})
list(APPEND _configure_opts --with-cxx=$ENV{CXX})
endif()
endif()
if(DEFINED ENV{CXX})
list(APPEND _configure_opts --with-cxx=$ENV{CXX})
endif()
message(STATUS "config opts: ${_configure_opts}")

unset(ENV{PETSC_DIR})
BuildExternalProject(
Expand Down

0 comments on commit 6755be8

Please sign in to comment.