salishsea.eos.ubc.ca Site Web App
Continuous Integration |
|
Documentation |
|
Package |
|
Meta |
The salishsea.eos.ubc.ca site is a dynamic web application written in Python 3 using the Pyramid web framework. These docs provide a brief explanation of the structure of the app, and details about its development.
If you are new to Python web frameworks you should probably start by reading the Pyramid Hello World docs, and then maybe proceed to the Quick Tutorial.
If you have experience with any of the many other Python web frameworks such as Django, flask, bottle, etc. you could start with the Quick Tutorial, or dive into the narrative documentation.
App Structure
The salishsea_site directory tree contains the app package:
The app configuration is defined in
salishsea_site/__init__.py. That file also contains functions that map URL paths to route names. It also contains static view functions that serve the site static assets (see below) and model run results figures and other static files produced by the Salish Sea NEMO and SOG 1-D models.The
salishsea_site/views/directory contains Python modules that define the view functions that the routes connect to. The view functions handle the HTTP requests coming into the app, and calculate the dynamic elements of the responses which are returned by the functions asdictobjects. The view modules are organized to correspond to the site’s top-of-page navigation bar.The
salishsea_site/templates/directory tree contains the page templates that the view functions pass to the renderer to produce the HTML stream that is sent to the user’s browser in the HTTP response. Thedictobjects returned by the view functions contain the template variable names and the values to substitute for them. The templates are written in HTML5. They use the Bootstrap 3 HTML/CSS/JS framework for layout and client-side dynamic elements. The Mako template library is used to provide variable substitution, inheritance, and flow control in the templates. The templates are organized in sub-directories that correspond to the view modules.The
salishsea_site/static/directory tree contains the app’s static assets, CSS files, images, and PDF documents. They are served by a static view defined insalishsea_site/__init__.py.
The runtime configurations for running the app in a development environment,
and for its production deployment are contained in the development.ini and production.ini files in the top level of the repository.
Please see Web App Package Development for details of how to set up an app development environment, and Running the App in Dev Mode for instructions on how to run the app in development mode on your local machine.
The tests/ directory tree contains the unit test suite for the package.
It is intended to be run using the pytest tool.
Please see Running the Unit Tests for details.
The docs/ directory tree contains the reStructuredText source files for these docs,
and the Sphinx configuration and Makefile to render them to HTML.
Please see Building the Documentation for details.
Web App Package Development
Python Versions
The salishsea-site package is developed, tested, and deployed using Python 3.13.
Getting the Code
Clone the salishsea-site code and documentation repository from GitHub with:
$ git clone git@github.com:SalishSeaCast/salishsea-site.git
or
$ git clone https://github.com/SalishSeaCast/salishsea-site.git
if you don’t have ssh key authentication set up on GitHub (or copy the link from the Clone or download button on the repository page).
Development Environment
salishsea-site uses Pixi for package and environment management.
If you don’t already have Pixi installed,
please follow its installation instructions to do so.
Use pixi install command to download the package dependencies and link them into environments.
Most commands are executed using pixi run in the salishsea-site/ directory
(or a sub-directory).
The
defaultenvironment has the packages installed that are required to run the production deployment of the web application.Other environments used by commands in the sections below have addition packages for running the test suite, building and link checking the documentation, etc.
If you are using an integrated development environment like VSCode or PyCharm where you need a Python interpreter to support coding assistance features, run development tasks, etc., use the interpreter in the
devenvironment. You can get its full path with pixi run -e dev which python
You can launch a sub-shell in one of the environments with a command like pixi shell -e dev. That is convenient if you are running a lot of commands because it removed the need to type pixi run -e dev before each of them. Use exit to leave the sub-shell.
To get detailed information about the environments, the packages installed in them, Pixi tasks that are defined for them, etc., use pixi info.
salishsea-site is installed in editable install mode in all of the environments that
Pixi creates.
That means that changes you make to the code are immediately reflected in the environments.
Coding Style
The salishsea-site package uses Git pre-commit hooks managed by pre-commit to maintain consistent code style and and other aspects of code, docs, and repo QA.
To install the pre-commit hooks in a newly cloned repo, run pre-commit install:
$ cd salishsea-site
$ pixi run -e dev pre-commit install
Note
You only need to install the hooks once immediately after you make a new clone of the salishsea-site repository and build your Development Environment.
Running the App in Dev Mode
You can run the app in a development server on you local machine with the command:
$ cd salishsea-site
$ pixi run -e dev pserve --reload development.ini
With the dev server running you can view the site by navigating to http://localhost:6543/ in your browser.
The --reload option in the pserve command causes the dev server to monitor the app files in the salishsea-site/ directory tree and restart whenever it detects that a file has been changed.
That allows you to easily edit app code and templates and instantly see changes in your browser after a page refresh.
Logger messages from the app appear in the terminal session where you ran the pserve command.
To stop the dev server use Ctrl-C in the terminal session where you ran the pserve command.
Note
Several pages in the app require access to parts of the /results/ directory tree on skookum.
If you are working on a waterhole machine that has /results/ mounted,
you are good to go.
If you need to get /results/ mounted on a waterhole machine,
please open an EOAS IT ticket with the request.
If you are working on a remote machine or a laptop you can use sshfs to mount /results/ from skookum at a local /results/ mount point.
Building the Documentation
The documentation for the salishsea-site package is written in reStructuredText and converted to HTML using Sphinx.
If you have write access to the repository on GitHub, whenever you push changes to GitHub the documentation is automatically re-built and rendered at https://salishsea-site.readthedocs.io.
Additions, improvements, and corrections to these docs are always welcome.
The quickest way to fix typos, etc. on existing pages is to use the Edit on GitHub link in the upper right corner of the page to get to the online editor for the page on GitHub.
For more substantial work, and to add new pages, follow the instructions in the Development Environment section above. In the development environment you can build the docs locally instead of having to push commits to GitHub to trigger a build on readthedocs.org and wait for it to complete. Below are instructions that explain how to:
build the docs with your changes, and preview them in Firefox
check the docs for broken links
Building and Previewing the Documentation
Building the documentation is driven by the docs/Makefile.
To do a clean build of the documentation use:
$ cd salishsea-site
$ pixi run docs
The output looks something like:
The HTML rendering of the docs ends up in docs/_build/html/.
You can open the index.html file in that directory tree in your browser to preview the results of the build before committing and pushing your changes to Bitbucket.
If you have write access to the repository on GitHub, whenever you push changes to GitHub the documentation is automatically re-built and rendered at https://salishsea-site.readthedocs.io.
Link Checking the Documentation
Sphinx also provides a link checker utility which can be run to find broken or redirected links in the docs. Run the link checker with:
$ cd salishsea-site
$ pixi run linkcheck
The output looks something like:
linkcheck is run monthly via a scheduled GitHub Actions workflow
Running the Unit Tests
The test suite for the salishsea-site package is in salishsea-site/tests/.
The pytest tools is used for test fixtures and as the test runner for the suite.
Use:
$ cd salishsea-site/
$ pixi run -e test pytest
to run the test suite. The output looks something like:
You can monitor what lines of code the test suite exercises using the coverage.py and pytest-cov tools with the command:
$ cd salishsea-site/
$ pixi run -e test pytest-cov
The test coverage report will be displayed below the test suite run output.
Alternatively, you can use
$ pixi run -e test pytest-cov-html
to produce an HTML report that you can view in your browser by opening salishsea-site/htmlcov/index.html.
Continuous Integration
The salishsea-site package unit test suite is run and a coverage report is generated whenever changes are pushed to GitHub. The results are visible on the repo actions page, from the green checkmarks beside commits on the repo commits page, or from the green checkmark to the left of the “Latest commit” message on the repo code overview page . The testing coverage report is uploaded to codecov.io
The GitHub Actions workflow configuration that defines the continuous integration tasks is in the .github/workflows/pytest-coverage.yaml file.
Version Control Repository
The salishsea-site package code and documentation source files are available in the salishsea-site Git repository at https://github.com/SalishSeaCast/salishsea-site.
Issue Tracker
Development tasks, bug reports, and enhancement ideas are recorded and managed in the issue tracker at https://github.com/SalishSeaCast/salishsea-site/issues.
License
The salishsea.eos.ubc.ca site content, code, and documentation are Copyright 2014 – present by the Mesoscale Ocean and Atmospheric Dynamics (MOAD) group in the Department of Earth, Ocean, and Atmospheric Sciences at The University of British Columbia. Please see https://salishsea.eos.ubc.ca/contributors for details.
They are licensed under the Apache License, Version 2.0. https://www.apache.org/licenses/LICENSE-2.0 Please see the LICENSE file for details of the license.
Release Process
Releases are done at Doug’s discretion when significant pieces of development work have been completed.
The release process steps are:
Use pixi run -e dev hatch version release to bump the version from
.devnto the next release version identifier; e.g.26.1.dev0to26.1Use pixi update to update the lock file to reflect the new version identifier
Commit the version bump
Create an annotated tag for the release with Git -> New Tag… in PyCharm or git tag -e -a vyy.n; git tag -e -a v26.1
Push the version bump commit and tag to GitHub
Use the GitHub web interface to create a release, editing the auto-generated release notes into sections:
### Features ### Bug Fixes ### Documentation ### Maintenance ### Dependency Updates
Use the GitHub Issues -> Milestones web interface to edit the release milestone:
Change the Due date to the release date
Delete the “when it’s ready” comment in the Description
Use the GitHub Issues -> Milestones web interface to create a milestone for the next release:
Set the Title to the next release version, prepended with a
v; e.g.v26.2Set the Due date to the end of the year of the next release
Set the Description to something like
v26.2 release - when it's ready :-)Create the next release milestone
Review the open issues, especially any that are associated with the milestone for the just released version, and update their milestone.
Close the milestone for the just released version.
Use pixi run -e dev hatch version minor,dev to bump the version for the next development cycle, or use pixi run -e dev hatch version major,minor,dev for a year rollover version bump
Use pixi update to update the lock file to reflect the new version identifier
Commit the version bump
Push the version bump commit to GitHub