From d12a379a6632382b0f257f3000a2cbd840793f02 Mon Sep 17 00:00:00 2001 From: jakeymac Date: Sat, 17 Aug 2024 18:43:09 -0600 Subject: [PATCH] updates for tethys 4.3 --- install.yml | 9 +++- setup.py | 8 ++-- tethysapp/dask_tutorial/__init__.py | 2 +- tethysapp/dask_tutorial/app.py | 6 +-- tethysapp/dask_tutorial/controllers.py | 44 +++++++++---------- tethysapp/dask_tutorial/handoff.py | 3 -- tethysapp/dask_tutorial/job_functions.py | 9 +--- .../app_workspace => resources}/.gitkeep | 0 .../templates/dask_tutorial/base.html | 8 ++-- .../templates/dask_tutorial/error.html | 6 +-- .../templates/dask_tutorial/home.html | 7 ++- .../templates/dask_tutorial/jobs_table.html | 8 ++-- .../templates/dask_tutorial/results.html | 8 ++-- tethysapp/dask_tutorial/tests/tests.py | 44 ++++++------------- .../workspaces/user_workspaces/.gitkeep | 0 15 files changed, 67 insertions(+), 95 deletions(-) delete mode 100644 tethysapp/dask_tutorial/handoff.py rename tethysapp/dask_tutorial/{workspaces/app_workspace => resources}/.gitkeep (100%) delete mode 100644 tethysapp/dask_tutorial/workspaces/user_workspaces/.gitkeep diff --git a/install.yml b/install.yml index fc271dc..7d95f29 100644 --- a/install.yml +++ b/install.yml @@ -1,5 +1,7 @@ # This file should be committed to your app code. -version: 1.0 +version: 1.1 +# This should be greater or equal to your tethys-platform in your environment +tethys_version: ">=4.0.0" # This should match the app - package name in your setup.py name: dask_tutorial @@ -8,8 +10,13 @@ requirements: skip: false conda: channels: + - conda-forge packages: + - dask + - tethys_dask_scheduler pip: + npm: + post: \ No newline at end of file diff --git a/setup.py b/setup.py index 97dd079..5319e02 100644 --- a/setup.py +++ b/setup.py @@ -1,16 +1,16 @@ from setuptools import setup, find_namespace_packages -from tethys_apps.app_installation import find_resource_files +from tethys_apps.app_installation import find_all_resource_files +from tethys_apps.base.app_base import TethysAppBase # -- Apps Definition -- # app_package = 'dask_tutorial' -release_package = 'tethysapp-' + app_package +release_package = f'{TethysAppBase.package_namespace}-{app_package}' # -- Python Dependencies -- # dependencies = [] # -- Get Resource File -- # -resource_files = find_resource_files('tethysapp/' + app_package + '/templates', 'tethysapp/' + app_package) -resource_files += find_resource_files('tethysapp/' + app_package + '/public', 'tethysapp/' + app_package) +resource_files = find_all_resource_files(app_package, TethysAppBase.package_namespace) setup( diff --git a/tethysapp/dask_tutorial/__init__.py b/tethysapp/dask_tutorial/__init__.py index 8766881..c927d02 100644 --- a/tethysapp/dask_tutorial/__init__.py +++ b/tethysapp/dask_tutorial/__init__.py @@ -1 +1 @@ -# Included for native namespace package support \ No newline at end of file +# Included for native namespace package support diff --git a/tethysapp/dask_tutorial/app.py b/tethysapp/dask_tutorial/app.py index ff6eb0a..faaa583 100644 --- a/tethysapp/dask_tutorial/app.py +++ b/tethysapp/dask_tutorial/app.py @@ -2,7 +2,7 @@ from tethys_sdk.app_settings import SchedulerSetting -class DaskTutorial(TethysAppBase): +class App(TethysAppBase): """ Tethys app class for Dask Tutorial. """ @@ -13,7 +13,7 @@ class DaskTutorial(TethysAppBase): index = 'home' icon = f'{package}/images/dask-logo.png' root_url = 'dask-tutorial' - color = '#CA4D34' + color = '#c23616' tags = '' enable_feedback = False feedback_emails = [] @@ -28,4 +28,4 @@ def scheduler_settings(self): ), ) - return scheduler_settings + return scheduler_settings \ No newline at end of file diff --git a/tethysapp/dask_tutorial/controllers.py b/tethysapp/dask_tutorial/controllers.py index 24411cf..23185ec 100644 --- a/tethysapp/dask_tutorial/controllers.py +++ b/tethysapp/dask_tutorial/controllers.py @@ -1,15 +1,14 @@ import random -from django.shortcuts import render, reverse, redirect from tethys_sdk.routing import controller from django.http.response import HttpResponseRedirect from django.contrib import messages from tethys_sdk.gizmos import Button from tethys_sdk.gizmos import JobsTable from tethys_compute.models.dask.dask_job_exception import DaskJobException -from tethysapp.dask_tutorial.app import DaskTutorial as app +from .app import App # get job manager for the app -job_manager = app.get_job_manager() +job_manager = App.get_job_manager() @controller @@ -17,6 +16,7 @@ def home(request): """ Controller for the app home page. """ + dask_delayed_button = Button( display_text='Dask Delayed Job', name='dask_delayed_button', @@ -25,7 +25,7 @@ def home(request): 'data-bs-placement': 'top', 'title': 'Dask Delayed Job' }, - href=reverse('dask_tutorial:run_job', kwargs={'job_type': 'delayed'}) + href=App.reverse('run_job', kwargs={'job_type': 'delayed'}) ) dask_distributed_button = Button( @@ -36,7 +36,7 @@ def home(request): 'data-bs-placement': 'top', 'title': 'Dask Future Job' }, - href=reverse('dask_tutorial:run_job', kwargs={'job_type': 'distributed'}) + href=App.reverse('run_job', kwargs={'job_type': 'distributed'}) ) dask_multiple_leaf_button = Button( @@ -47,7 +47,7 @@ def home(request): 'data-bs-placement': 'top', 'title': 'Dask Multiple Leaf Jobs' }, - href=reverse('dask_tutorial:run_job', kwargs={'job_type': 'multiple-leaf'}) + href=App.reverse('run_job', kwargs={'job_type': 'multiple-leaf'}) ) jobs_button = Button( @@ -58,17 +58,17 @@ def home(request): 'data-bs-placement': 'top', 'title': 'Show All Jobs' }, - href=reverse('dask_tutorial:jobs_table') + href=App.reverse('jobs_table') ) context = { 'dask_delayed_button': dask_delayed_button, 'dask_distributed_button': dask_distributed_button, 'dask_multiple_leaf_button': dask_multiple_leaf_button, - 'jobs_button': jobs_button, + 'jobs_button': jobs_button } - return render(request, 'dask_tutorial/home.html', context) + return App.render(request, 'home.html', context) @controller @@ -84,8 +84,7 @@ def jobs_table(request): striped=False, bordered=False, condensed=False, - actions=['logs', 'delete'], - results_url='dask_tutorial:result', + results_url=f'{App.package}:result', refresh_interval=1000, show_detailed_status=True, ) @@ -98,12 +97,12 @@ def jobs_table(request): 'data-bs-placement': 'top', 'title': 'Home' }, - href=reverse('dask_tutorial:home') + href=App.reverse('home') ) context = {'jobs_table': jobs_table_options, 'home_button': home_button} - return render(request, 'dask_tutorial/jobs_table.html', context) + return App.render(request, 'jobs_table.html', context) @controller @@ -123,7 +122,7 @@ def result(request, job_id): 'data-bs-placement': 'top', 'title': 'Home' }, - href=reverse('dask_tutorial:home') + href=App.reverse('home') ) jobs_button = Button( @@ -134,7 +133,7 @@ def result(request, job_id): 'data-bs-placement': 'top', 'title': 'Show All Jobs' }, - href=reverse('dask_tutorial:jobs_table') + href=App.reverse('jobs_table') ) context = { @@ -144,14 +143,13 @@ def result(request, job_id): 'jobs_button': jobs_button } - return render(request, 'dask_tutorial/results.html', context) + return App.render(request, 'results.html', context) @controller def error_message(request): messages.add_message(request, messages.ERROR, 'Invalid Scheduler!') - return redirect(reverse('dask_tutorial:home')) - + return App.redirect(App.reverse('home')) @controller def run_job(request, job_type): @@ -159,10 +157,10 @@ def run_job(request, job_type): Controller for the app home page. """ # Get scheduler from dask_primary setting. - scheduler = app.get_scheduler(name='dask_primary') + scheduler = App.get_scheduler(name='dask_primary') if job_type.lower() == 'delayed': - from tethysapp.dask_tutorial.job_functions import delayed_job + from .job_functions import delayed_job # Create dask delayed object delayed = delayed_job() @@ -183,7 +181,7 @@ def run_job(request, job_type): try: client = scheduler.client except DaskJobException: - return redirect(reverse('dask_tutorial:error_message')) + return App.redirect(App.reverse('error_message')) # Create future job instance future = distributed_job(client) @@ -203,7 +201,7 @@ def run_job(request, job_type): try: client = scheduler.client except DaskJobException: - return redirect(reverse('dask_tutorial:error_message')) + return App.redirect(App.reverse('error_message')) # Create future job instance futures = multiple_leaf_job(client) @@ -222,4 +220,4 @@ def run_job(request, job_type): ) dask.execute(future) - return HttpResponseRedirect(reverse('dask_tutorial:jobs_table')) + return HttpResponseRedirect(App.reverse('jobs_table')) \ No newline at end of file diff --git a/tethysapp/dask_tutorial/handoff.py b/tethysapp/dask_tutorial/handoff.py deleted file mode 100644 index 1e15fb8..0000000 --- a/tethysapp/dask_tutorial/handoff.py +++ /dev/null @@ -1,3 +0,0 @@ -# Define your handoff handlers here -# for more information, see: -# http://docs.tethysplatform.org/en/dev/tethys_sdk/handoff.html \ No newline at end of file diff --git a/tethysapp/dask_tutorial/job_functions.py b/tethysapp/dask_tutorial/job_functions.py index 6e2c932..bcf42e0 100644 --- a/tethysapp/dask_tutorial/job_functions.py +++ b/tethysapp/dask_tutorial/job_functions.py @@ -1,22 +1,18 @@ import time import dask - def inc(x): time.sleep(3) return x + 1 - def double(x): time.sleep(3) return x + 2 - def add(x, y): time.sleep(10) return x + y - def sum_up(x): time.sleep(5) return sum(x) @@ -25,7 +21,6 @@ def sum_up(x): def convert_to_dollar_sign(result): return '$' + str(result) - # Delayed Job def delayed_job(): output = [] @@ -36,7 +31,6 @@ def delayed_job(): output.append(c) return dask.delayed(sum_up, pure=False)(output) - # Distributed Job def distributed_job(client): output = [] @@ -47,7 +41,6 @@ def distributed_job(client): output.append(c) return client.submit(sum_up, output) - # Multiple Leaf Distributed Job def multiple_leaf_job(client): output = [] @@ -56,4 +49,4 @@ def multiple_leaf_job(client): b = client.submit(double, x, pure=False) c = client.submit(add, a, b, pure=False) output.append(c) - return output + return output \ No newline at end of file diff --git a/tethysapp/dask_tutorial/workspaces/app_workspace/.gitkeep b/tethysapp/dask_tutorial/resources/.gitkeep similarity index 100% rename from tethysapp/dask_tutorial/workspaces/app_workspace/.gitkeep rename to tethysapp/dask_tutorial/resources/.gitkeep diff --git a/tethysapp/dask_tutorial/templates/dask_tutorial/base.html b/tethysapp/dask_tutorial/templates/dask_tutorial/base.html index 7ba1b8e..667cc00 100644 --- a/tethysapp/dask_tutorial/templates/dask_tutorial/base.html +++ b/tethysapp/dask_tutorial/templates/dask_tutorial/base.html @@ -1,6 +1,6 @@ {% extends "tethys_apps/app_no_nav.html" %} -{% load static %} +{% load static tethys %} {% block title %}{{ tethys_app.name }}{% endblock %} @@ -20,10 +20,10 @@ {% block content_dependent_styles %} {{ block.super }} - + {% endblock %} {% block scripts %} {{ block.super }} - -{% endblock %} + +{% endblock %} \ No newline at end of file diff --git a/tethysapp/dask_tutorial/templates/dask_tutorial/error.html b/tethysapp/dask_tutorial/templates/dask_tutorial/error.html index f416e6a..2288b59 100644 --- a/tethysapp/dask_tutorial/templates/dask_tutorial/error.html +++ b/tethysapp/dask_tutorial/templates/dask_tutorial/error.html @@ -1,5 +1,5 @@ -{% extends "dask_tutorial/base.html" %} -{% load tethys_gizmos %} +{% extends tethys_app.package|add:"/base.html" %} +{% load tethys %} {% block app_content %}
@@ -9,4 +9,4 @@ {% block app_actions %} {% gizmo jobs_button %} -{% endblock %} +{% endblock %} \ No newline at end of file diff --git a/tethysapp/dask_tutorial/templates/dask_tutorial/home.html b/tethysapp/dask_tutorial/templates/dask_tutorial/home.html index 405a419..33335ba 100644 --- a/tethysapp/dask_tutorial/templates/dask_tutorial/home.html +++ b/tethysapp/dask_tutorial/templates/dask_tutorial/home.html @@ -1,5 +1,5 @@ -{% extends "dask_tutorial/base.html" %} -{% load tethys_gizmos %} +{% extends tethys_app.package|add:"/base.html" %} +{% load tethys %} {% block app_actions %} {% gizmo jobs_button %} @@ -14,5 +14,4 @@

Dask Distributed Job

Multi Leaf Distributed Job

{% gizmo dask_multiple_leaf_button %} -{% endblock %} - +{% endblock %} \ No newline at end of file diff --git a/tethysapp/dask_tutorial/templates/dask_tutorial/jobs_table.html b/tethysapp/dask_tutorial/templates/dask_tutorial/jobs_table.html index 66b8c1a..884b473 100644 --- a/tethysapp/dask_tutorial/templates/dask_tutorial/jobs_table.html +++ b/tethysapp/dask_tutorial/templates/dask_tutorial/jobs_table.html @@ -1,7 +1,5 @@ -{% extends "dask_tutorial/base.html" %} -{% load static tethys_gizmos %} - -{% load tethys_gizmos %} +{% extends tethys_app.package|add:"/base.html" %} +{% load static tethys %} {% block global_scripts %} {{ block.super }} @@ -34,4 +32,4 @@

Jobs Table

{% gizmo_dependencies css %} {{ block.super }} {% gizmo_dependencies js %} -{% endblock %} +{% endblock %} \ No newline at end of file diff --git a/tethysapp/dask_tutorial/templates/dask_tutorial/results.html b/tethysapp/dask_tutorial/templates/dask_tutorial/results.html index 910cb9b..2751c46 100644 --- a/tethysapp/dask_tutorial/templates/dask_tutorial/results.html +++ b/tethysapp/dask_tutorial/templates/dask_tutorial/results.html @@ -1,7 +1,5 @@ -{% extends "dask_tutorial/base.html" %} -{% load static tethys_gizmos %} - -{% load tethys_gizmos %} +{% extends tethys_app.package|add:"/base.html" %} +{% load static tethys %} {% block title %}- Gizmos - Map View{% endblock %} @@ -35,4 +33,4 @@ {% gizmo_dependencies css %} {{ block.super }} {% gizmo_dependencies js %} -{% endblock %} +{% endblock %} \ No newline at end of file diff --git a/tethysapp/dask_tutorial/tests/tests.py b/tethysapp/dask_tutorial/tests/tests.py index d38d93a..8aef7b9 100644 --- a/tethysapp/dask_tutorial/tests/tests.py +++ b/tethysapp/dask_tutorial/tests/tests.py @@ -1,24 +1,19 @@ # Most of your test classes should inherit from TethysTestCase from tethys_sdk.testing import TethysTestCase -# Use if your app has persistent stores that will be tested against. -# Your app class from app.py must be passed as an argument to the TethysTestCase functions to both -# create and destroy the temporary persistent stores for your app used during testing -# from ..app import DaskTutorial - -# Use if you'd like a simplified way to test rendered HTML templates. -# You likely need to install BeautifulSoup, as it is not included by default in Tethys Platform -# 1. Open a terminal -# 2. Enter command ". /usr/lib/tethys/bin/activate" to activate the Tethys python environment -# 3. Enter command "pip install beautifulsoup4" -# For help, see https://www.crummy.com/software/BeautifulSoup/bs4/doc/ +# For testing rendered HTML templates it may be helpful to use BeautifulSoup. # from bs4 import BeautifulSoup +# For help, see https://www.crummy.com/software/BeautifulSoup/bs4/doc/ + """ -To run any tests: - 1. Open a terminal - 2. Enter command ". /usr/lib/tethys/bin/activate" to activate the Tethys python environment - 3. In portal_config.yml make sure that the default database user is set to tethys_super or is a super user of the database +To run tests for an app: + + 1. Open a terminal and activate the Tethys environment:: + + conda activate tethys + + 2. In portal_config.yml make sure that the default database user is set to tethys_super or is a super user of the database DATABASES: default: ENGINE: django.db.backends.postgresql_psycopg2 @@ -28,28 +23,15 @@ HOST: 127.0.0.1 PORT: 5435 - 4. Enter tethys test command. - The general form is: "tethys test -f tethys_apps.tethysapp....." - See below for specific examples - - To run all tests across this app: - Test command: "tethys test -f tethys_apps.tethysapp.dask_tutorial" + 3. From the root directory of your app, run the ``tethys manage test`` command:: - To run all tests in this file: - Test command: "tethys test -f tethys_apps.tethysapp.dask_tutorial.tests.tests" + tethys manage test tethysapp//tests - To run tests in the DaskTutorialTestCase class: - Test command: "tethys test -f tethys_apps.tethysapp.dask_tutorial.tests.tests.DaskTutorialTestCase" - - To run only the test_if_tethys_platform_is_great function in the DaskTutorialTestCase class: - Test command: "tethys test -f tethys_apps.tethysapp.dask_tutorial.tests.tests.DaskTutorialTestCase.test_if_tethys_platform_is_great" To learn more about writing tests, see: - https://docs.djangoproject.com/en/1.9/topics/testing/overview/#writing-tests - https://docs.python.org/2.7/library/unittest.html#module-unittest + https://docs.tethysplatform.org/en/stable/tethys_sdk/testing.html """ - class DaskTutorialTestCase(TethysTestCase): """ In this class you may define as many functions as you'd like to test different aspects of your app. diff --git a/tethysapp/dask_tutorial/workspaces/user_workspaces/.gitkeep b/tethysapp/dask_tutorial/workspaces/user_workspaces/.gitkeep deleted file mode 100644 index e69de29..0000000