Skip to content

Commit

Permalink
workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
dfguerrerom committed Jun 26, 2024
2 parents 0d77ca6 + 92c7031 commit 3feeb8b
Show file tree
Hide file tree
Showing 7 changed files with 305 additions and 34 deletions.
35 changes: 21 additions & 14 deletions .github/workflows/unit.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
name: Unit testing

name: Build
# To test with act: gh act --secret-file $ENV_FILE --workflows .github/workflows/unit.yml
on:
- push
- workflow_dispatch
push:
branches:
- main
pull_request:

env:
EARTHENGINE_TOKEN: ${{ secrets.EARTHENGINE_TOKEN }}

jobs:
lint:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- name: Set up Python "3.10"
uses: actions/setup-python@v4
with:
python-version: "3.8"
- uses: pre-commit/[email protected]
- name: install dependencies
run: python -m pip install -r requirements.txt
- name: build the application
run: |
python -m pip install pytest nbmake
pytest --nbmake ui.ipynb
python-version: "3.10"
- name: Install sepal_ui
run: python -m pip install "git+https://github.com/12rambau/sepal_ui.git@sepal_pre_release"
- name: Build with sepal_ui venv
run: module_venv
- name: Install nox
run: python -m pip install nox
- name: set entry point and run tests
run: nox -s test_ui
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ __pycache__/

# C extensions
*.so
*nox_ui.ipynb
*Untitled*

# Distribution / packaging
.Python
Expand Down
4 changes: 2 additions & 2 deletions component/tile/map_tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


class MapTile(sw.Tile):
def __init__(self):
def __init__(self, test=False):
"""Specific Map integrating all the widget components.
Use this map to gather all your widget and place them on it. It will reduce the amount of work to perform in the notebook
Expand All @@ -31,7 +31,7 @@ def __init__(self):

# create the controls
fullscreen_control = sm.FullScreenControl(
self.m, True, True, position="topright"
self.m, not test, not test, position="topright"
)
aoi_control = AoiControl(self.m, self.aoi_model)
planet_control = PlanetControl(self.m, self.planet_model)
Expand Down
219 changes: 212 additions & 7 deletions no_ui.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -12,28 +12,233 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/html": [
"<style>/*******************************************************************************\n",
" * Customization of the provided css from the different libs used by sepal_ui\n",
" */\n",
"\n",
"/* replace the map panel elements on top */\n",
".leaflet-pane,\n",
".leaflet-top,\n",
".leaflet-bottom {\n",
" z-index: 2 !important;\n",
"}\n",
"\n",
"/* remove the shadow from the widgets on the maps */\n",
".leaflet-widgetcontrol {\n",
" box-shadow: none;\n",
"}\n",
"\n",
"/* remove extra padding on top of the content */\n",
"main.v-content {\n",
" padding-top: 0px !important;\n",
"}\n",
"\n",
".v-alert__wrapper .progress {\n",
" background-color: transparent;\n",
"}\n",
"\n",
"/* set the bar on top of the map (800) when set to fullscreen */\n",
"header.v-app-bar {\n",
" z-index: 800 !important;\n",
"}\n",
"\n",
"/* set the menu_content on top of the map when it's set to fullscreen */\n",
".v-menu__content {\n",
" max-width: 100% !important;\n",
" z-index: 801 !important;\n",
"}\n",
"\n",
"/* make sure navigation drawers are always visible when they exist */\n",
"nav.v-navigation-drawer {\n",
" z-index: 900 !important;\n",
"}\n",
"\n",
"/* create extra position for the leaflet map controls */\n",
".leaflet-center {\n",
" left: 50%;\n",
" transform: translate(-50%, 0%);\n",
"}\n",
"\n",
".leaflet-middle {\n",
" top: 50%;\n",
" position: absolute;\n",
" z-index: 1000;\n",
" pointer-events: none;\n",
" transform: translate(0%, -50%);\n",
"}\n",
"\n",
".leaflet-center.leaflet-middle {\n",
" transform: translate(-50%, -50%);\n",
"}\n",
"\n",
"/* create extra classes to customize the layer_control table */\n",
".v-no-hover:hover {\n",
" background-color: transparent !important;\n",
"}\n",
"\n",
".v-no-border tbody tr td,\n",
".v-no-border tbody tr th {\n",
" border: none !important;\n",
"}\n",
"\n",
"/* extra css rules to make the messages disappear beneath the SimpleSlider */\n",
".v-no-messages .v-messages {\n",
" display: none;\n",
"}\n",
"\n",
".v-no-messages .v-input__slot {\n",
" margin-bottom: 0;\n",
"}\n",
"\n",
"/* specific css for the btn placed on maps */\n",
".v-btn.v-size--default.v-map-btn:not(.v-btn--round) {\n",
" padding: 0px;\n",
" min-width: 0px;\n",
" width: 30px;\n",
" height: 30px;\n",
"}\n",
"\n",
"/* add specific css for the zoom btn of the map */\n",
".v-btn.v-zoom-plus {\n",
" border-bottom-left-radius: 0;\n",
" border-bottom-right-radius: 0;\n",
"}\n",
"\n",
".v-btn.v-zoom-minus {\n",
" margin-top: -1px;\n",
" border-top-left-radius: 0;\n",
" border-top-right-radius: 0;\n",
"}\n",
"\n",
"/* css rules for fullscreen menus */\n",
".v-card.v-menu-fullscreen {\n",
" width: calc(100vw - 80px);\n",
" height: calc(100vh - 20px);\n",
"}\n",
"\n",
"/* hide the disclaimer message placed on top of the ui notebook\n",
" * the message will be displayed until the css is loaded */\n",
"#loading-app {\n",
" display: none !important;\n",
"}\n",
"\n",
"/* Related with https://github.com/12rambau/sepal_ui/issues/893 */\n",
"#rendered_cells {\n",
" contain: revert !important;\n",
" background-color: revert !important;\n",
"}\n",
"\n",
".full-screen-map > .leaflet-container {\n",
" position: fixed !important;\n",
" width: 100vw;\n",
" height: calc(100vh - 48px);\n",
" z-index: 800;\n",
" bottom: 0;\n",
" left: 0;\n",
"}\n",
"</style>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<link rel=\"stylesheet\" href=\"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.1/css/all.min.css\"/>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"/*******************************************************************************\n",
" * remove any links from fontawesome 5 created by jupyter in favor of\n",
" * fontawesome 6. to be removed when Jupyter updates it\n",
" */\n",
"\n",
"function remove_fa5() {\n",
" let links = document.querySelectorAll(\n",
" \"link[href^='https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@^5']\"\n",
" );\n",
"\n",
" links.forEach((link) => link.remove());\n",
"}\n",
"\n",
"if (document.readyState != \"loading\") remove_fa5();\n",
"else document.addEventListener(\"DOMContentLoaded\", remove_fa5);\n"
],
"text/plain": [
"<IPython.core.display.Javascript object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "1ae8408758c44ed59bf8f04367701881",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"ResizeTrigger()"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"from component import tile\n",
"from sepal_ui import aoi"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"map_tile = tile.MapTile()"
"map_tile = tile.MapTile(test=True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "e7d907ad77a84c1c9080aad6ce88a19d",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"MapTile(align_center=True, children=[Card(children=[Html(children=[''], layout=None, tag='h2'), Flex(children=…"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"map_tile"
]
Expand Down
62 changes: 54 additions & 8 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
The nox run are build in isolated environment that will be stored in .nox. to force the venv update, remove the .nox/xxx folder.
"""

from pathlib import Path
import nbformat
from nbconvert.preprocessors import ExecutePreprocessor
from jupyter_client.kernelspec import KernelSpecManager
import nox
import toml


@nox.session(reuse_venv=True)
Expand All @@ -17,15 +20,58 @@ def lint(session):
@nox.session(reuse_venv=True)
def app(session):
"""Run the application."""
init_notebook = toml.load("pyproject.toml")["sepal-ui"]["init-notebook"]
session.install("-r", "requirements.txt")
session.run("jupyter", "trust", init_notebook)
session.run("voila", "--debug", init_notebook)

entry_point = str(Path("ui.ipynb"))

# Duplicate the entry point file
session.run("cp", entry_point, "nox_ui.ipynb")

# change the kernel name in the entry point
session.run("entry_point", "--test", "nox_ui.ipynb")

session.run("jupyter", "trust", entry_point)
session.run(
"voila", "--show_tracebacks=True", "--template=sepal-ui-base", "nox_ui.ipynb"
)


@nox.session()
def test_ui(session):
"""Run the application."""

ksm = KernelSpecManager()
kernel_names = list(ksm.get_all_specs())
print(kernel_names)

# get the current path
root_folder = Path(__file__).parent
repo_name = root_folder.name

# Copy the ui.ipynb to test_ui.ipynb
session.run("cp", root_folder / "ui.ipynb", root_folder / "nox_ui.ipynb")

session.run("entry_point", "--test", root_folder / "nox_ui.ipynb")

test_notebooks = [root_folder / "nox_ui.ipynb"]

for notebook in test_notebooks:
with open(notebook) as ff:
nb_in = nbformat.read(ff, nbformat.NO_CONVERT)

print("Running notebook", notebook)

try:
ep = ExecutePreprocessor(timeout=600, kernel_name=f"test-{repo_name}")

nb_out = ep.preprocess(nb_in)
except Exception as e:
print("########### Error running notebook", notebook)
raise e


@nox.session(reuse_venv=True)
def jupyter(session):
"""Run the application in a jupyter notebook."""
"""Run the application."""
session.install("-r", "requirements.txt")
session.run("jupyter", "trust", "map_ui.ipynb")
session.run("jupyter", "notebook", "map_ui.ipynb")
session.run("jupyter", "trust", "no_ui.ipynb")
session.run("jupyter", "notebook", "no_ui.ipynb")
Loading

0 comments on commit 3feeb8b

Please sign in to comment.