Skip to content

Commit

Permalink
updates for tethys 4.3
Browse files Browse the repository at this point in the history
  • Loading branch information
jakeymac committed Aug 18, 2024
1 parent b7c4dcb commit 6acc35e
Show file tree
Hide file tree
Showing 14 changed files with 57 additions and 74 deletions.
9 changes: 8 additions & 1 deletion install.yml
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -8,8 +10,13 @@ requirements:
skip: false
conda:
channels:
- conda-forge
packages:
- dask
- tethys_dask_scheduler

pip:

npm:

post:
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
2 changes: 1 addition & 1 deletion tethysapp/dask_tutorial/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# Included for native namespace package support
# Included for native namespace package support
6 changes: 3 additions & 3 deletions tethysapp/dask_tutorial/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from tethys_sdk.app_settings import SchedulerSetting


class DaskTutorial(TethysAppBase):
class App(TethysAppBase):
"""
Tethys app class for Dask Tutorial.
"""
Expand All @@ -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 = []
Expand All @@ -28,4 +28,4 @@ def scheduler_settings(self):
),
)

return scheduler_settings
return scheduler_settings
24 changes: 11 additions & 13 deletions tethysapp/dask_tutorial/controllers.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -26,14 +25,14 @@ def home(request):
'data-bs-placement': 'top',
'title': 'Show All Jobs'
},
href=reverse('dask_tutorial:jobs_table')
href=App.reverse('jobs_table')
)

context = {
'jobs_button': jobs_button
}

return render(request, 'dask_tutorial/home.html', context)
return App.render(request, 'home.html', context)


@controller
Expand All @@ -49,8 +48,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,
)
Expand All @@ -63,12 +61,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
Expand All @@ -88,7 +86,7 @@ def result(request, job_id):
'data-bs-placement': 'top',
'title': 'Home'
},
href=reverse('dask_tutorial:home')
href=App.reverse('home')
)

jobs_button = Button(
Expand All @@ -99,7 +97,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 = {
Expand All @@ -109,10 +107,10 @@ 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'))
2 changes: 1 addition & 1 deletion tethysapp/dask_tutorial/job_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ def sum_up(x):


def convert_to_dollar_sign(result):
return '$' + str(result)
return '$' + str(result)
File renamed without changes.
8 changes: 4 additions & 4 deletions tethysapp/dask_tutorial/templates/dask_tutorial/base.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends "tethys_apps/app_no_nav.html" %}

{% load static %}
{% load static tethys %}

{% block title %}{{ tethys_app.name }}{% endblock %}

Expand All @@ -20,10 +20,10 @@

{% block content_dependent_styles %}
{{ block.super }}
<link href="{% static 'dask_tutorial/css/main.css' %}" rel="stylesheet"/>
<link href="{% static tethys_app|public:'css/main.css' %}" rel="stylesheet"/>
{% endblock %}

{% block scripts %}
{{ block.super }}
<script src="{% static 'dask_tutorial/js/main.js' %}" type="text/javascript"></script>
{% endblock %}
<script src="{% static tethys_app|public:'js/main.js' %}" type="text/javascript"></script>
{% endblock %}
6 changes: 3 additions & 3 deletions tethysapp/dask_tutorial/templates/dask_tutorial/error.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "dask_tutorial/base.html" %}
{% load tethys_gizmos %}
{% extends tethys_app.package|add:"/base.html" %}
{% load tethys %}

{% block app_content %}
<div class="error-message">
Expand All @@ -9,4 +9,4 @@

{% block app_actions %}
{% gizmo jobs_button %}
{% endblock %}
{% endblock %}
6 changes: 3 additions & 3 deletions tethysapp/dask_tutorial/templates/dask_tutorial/home.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends "dask_tutorial/base.html" %}
{% load tethys_gizmos %}
{% extends tethys_app.package|add:"/base.html" %}
{% load tethys %}

{% block app_actions %}
{% gizmo jobs_button %}
{% endblock %}
{% endblock %}
Original file line number Diff line number Diff line change
@@ -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 }}
Expand Down Expand Up @@ -34,4 +32,4 @@ <h2>Jobs Table</h2>
{% gizmo_dependencies css %}
{{ block.super }}
{% gizmo_dependencies js %}
{% endblock %}
{% endblock %}
8 changes: 3 additions & 5 deletions tethysapp/dask_tutorial/templates/dask_tutorial/results.html
Original file line number Diff line number Diff line change
@@ -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 %}

Expand Down Expand Up @@ -35,4 +33,4 @@
{% gizmo_dependencies css %}
{{ block.super }}
{% gizmo_dependencies js %}
{% endblock %}
{% endblock %}
44 changes: 13 additions & 31 deletions tethysapp/dask_tutorial/tests/tests.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.<app_name>.<folder_name>.<file_name>.<class_name>.<function_name>"
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/<app_name>/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.
Expand Down
Empty file.

0 comments on commit 6acc35e

Please sign in to comment.