diff --git a/.github/workflows/unit.yaml b/.github/workflows/unit.yaml index 37cd569..680e8c7 100644 --- a/.github/workflows/unit.yaml +++ b/.github/workflows/unit.yaml @@ -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/action@v3.0.0 - - 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 diff --git a/.gitignore b/.gitignore index f77c28d..79c73b0 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,8 @@ __pycache__/ # C extensions *.so +*nox_ui.ipynb +*Untitled* # Distribution / packaging .Python diff --git a/component/tile/map_tile.py b/component/tile/map_tile.py index a1d5795..6e32965 100644 --- a/component/tile/map_tile.py +++ b/component/tile/map_tile.py @@ -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 @@ -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) diff --git a/no_ui.ipynb b/no_ui.ipynb index dae5fd7..924eeea 100644 --- a/no_ui.ipynb +++ b/no_ui.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -12,9 +12,198 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "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": [ + "" + ] + }, + "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" @@ -22,18 +211,34 @@ }, { "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" ] diff --git a/noxfile.py b/noxfile.py index e0add02..08bf258 100644 --- a/noxfile.py +++ b/noxfile.py @@ -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) @@ -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") diff --git a/requirements.txt b/requirements.txt index aef2cc8..68ac26e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,4 +7,7 @@ git+https://github.com/12rambau/sepal_ui.git@sepal_pre_release # custom libs geopandas -planet>=2.0a6 +planet<2.7 + + +# trigger build diff --git a/ui.ipynb b/ui.ipynb index 83456ac..bdc58ad 100644 --- a/ui.ipynb +++ b/ui.ipynb @@ -1,6 +1,7 @@ { "cells": [ { +<<<<<<< HEAD "cell_type": "markdown", "metadata": {}, "source": [ @@ -8,11 +9,17 @@ ] }, { +======= +>>>>>>> main "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ +<<<<<<< HEAD +======= + "\n", +>>>>>>> main "from sepal_ui import sepalwidgets as sw\n", "from component.message import cm\n", "from component import tile" @@ -108,9 +115,9 @@ ], "metadata": { "kernelspec": { - "display_name": "(venv) planet-order", + "display_name": "(test) test-planet-order", "language": "python", - "name": "venv-planet-order" + "name": "test-planet-order" }, "language_info": { "codemirror_mode": { @@ -124,6 +131,7 @@ "pygments_lexer": "ipython3", "version": "3.10.12" }, + "title": "Planet image order module", "voila": { "theme": "dark" }