moad_tools Package Development
Continuous Integration |
|
Documentation |
|
Package |
|
Meta |
The UBC EOAS MOAD Group Tools package (moad_tools) is a collection of
Python modules that facilitate code reuse for the UBC EOAS MOAD Group.
Python Versions
The moad_tools package is developed using Python 3.14.
It is tested for Python versions >=3.12.
Getting the Code
Clone the code and documentation repository from GitHub with:
$ git clone git@github.com:UBC-MOAD/moad_tools.git
Development Environment
moad_tools uses Pixi for package and environment management.
If you don’t already have Pixi installed,
please follow its installation instructions to do so.
Most commands are executed using pixi run in the moad_tools/ directory
(or a sub-directory).
Dependencies will be downloaded and linked in to environments if you do pixi install
after you clone the repository,
or when you use pixi run for the first time.
The
defaultenvironment has the packages installed that are required to import and use the modules in themoad_toolsnamespaceThe
midossenvironment has the packages installed that are required to import and use the modules in themoad_tools.midossnamespace, and to run the command-line interface tools in that namespace; e.g. pixi run -e midoss random-oil-spills --helpOther 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
To get detailed information about the environments, the packages installed in them, Pixi tasks that are defined for them, etc., use pixi info.
moad_tools 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.
To deactivate the environment use:
(moad-tools-dev)$ conda deactivate
Coding Style
The moad_tools 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, activate the conda development environment, and run pre-commit install:
$ cd moad_tools
$ 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 moad_tools repository and build your Development Environment.
Documentation
The :moad_tools documentation 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://ubc-moad-tools.readthedocs.io/en/latest/.
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.
Use:
$ cd moad_tools/
$ pixi run docs
to do a clean build of the documentation. The output looks something like:
✨ Pixi task (docs in docs): make clean html
Removing everything under '_build'...
Running Sphinx v9.1.0
loading translations [en]... done
making output directory... done
loading intersphinx inventory 'mohidcmd' from https://mohid-cmd.readthedocs.io/en/latest/objects.inv ...
loading intersphinx inventory 'numpy' from https://numpy.org/doc/1.18/objects.inv ...
loading intersphinx inventory 'pandas' from https://pandas.pydata.org/docs/objects.inv ...
loading intersphinx inventory 'python' from https://docs.python.org/3/objects.inv ...
loading intersphinx inventory 'rasterio' from https://rasterio.readthedocs.io/en/latest/objects.inv ...
loading intersphinx inventory 'shapely' from https://shapely.readthedocs.io/en/latest/objects.inv ...
loading intersphinx inventory 'xarray' from https://xarray.pydata.org/en/stable/objects.inv ...
intersphinx inventory has moved: https://xarray.pydata.org/en/stable/objects.inv -> https://docs.xarray.dev/en/stable/objects.inv
building [mo]: targets for 0 po files that are out of date
writing output...
building [html]: targets for 3 source files that are out of date
updating environment: [new config] 3 added, 0 changed, 0 removed
reading sources... [100%] pkg_development
looking for now-outdated files... none found
pickling environment... done
checking consistency... done
preparing documents... done
copying assets...
copying static files...
Writing evaluated template result to /media/doug/warehouse/MOAD/moad_tools/docs/_build/html/_static/language_data.js
Writing evaluated template result to /media/doug/warehouse/MOAD/moad_tools/docs/_build/html/_static/documentation_options.js
Writing evaluated template result to /media/doug/warehouse/MOAD/moad_tools/docs/_build/html/_static/basic.css
Writing evaluated template result to /media/doug/warehouse/MOAD/moad_tools/docs/_build/html/_static/js/versions.js
copying static files: done
copying extra files...
copying extra files: done
copying assets: done
writing output... [100%] pkg_development
generating indices... genindex py-modindex done
highlighting module code... [100%] moad_tools.observations
writing additional pages... search done
dumping search index in English (code: en)... done
dumping object inventory... done
build succeeded.
The HTML pages are in _build/html.
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.
To preview in Firefox from the command-line you can do:
$ firefox docs/_build/html/index.html
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://ubc-moad-tools.readthedocs.io/en/latest/.
Link Checking the Documentation
Sphinx also provides a link checker utility which can be run to find broken or redirected links in the docs. Use:
$ cd moad_tools/
$ pixi run linkcheck
The output looks something like:
✨ Pixi task (linkcheck in docs): make clean linkcheck
Removing everything under '_build'...
Running Sphinx v9.1.0
loading translations [en]... done
making output directory... done
loading intersphinx inventory 'mohidcmd' from https://mohid-cmd.readthedocs.io/en/latest/objects.inv ...
loading intersphinx inventory 'numpy' from https://numpy.org/doc/1.18/objects.inv ...
loading intersphinx inventory 'pandas' from https://pandas.pydata.org/docs/objects.inv ...
loading intersphinx inventory 'python' from https://docs.python.org/3/objects.inv ...
loading intersphinx inventory 'rasterio' from https://rasterio.readthedocs.io/en/latest/objects.inv ...
loading intersphinx inventory 'shapely' from https://shapely.readthedocs.io/en/latest/objects.inv ...
loading intersphinx inventory 'xarray' from https://xarray.pydata.org/en/stable/objects.inv ...
intersphinx inventory has moved: https://xarray.pydata.org/en/stable/objects.inv -> https://docs.xarray.dev/en/stable/objects.inv
building [mo]: targets for 0 po files that are out of date
writing output...
building [linkcheck]: targets for 3 source files that are out of date
updating environment: [new config] 3 added, 0 changed, 0 removed
reading sources... [100%] pkg_development
looking for now-outdated files... none found
pickling environment... done
checking consistency... done
preparing documents... done
copying assets...
copying assets: done
writing output... [100%] pkg_development
( moad_tools: line 261) -ignored- https://github.com/MIDOSS/marine_transport_data
( moad_tools: line 4) -ignored- https://docs.google.com/drawings/d/10PM53-UnnILYCAPKU9MxiR-Y4OW0tIMhVzSjaHr-iSc/edit
( moad_tools: line 4) -ignored- https://docs.google.com/drawings/d/1-4gl2yNNWxqXK-IOr4KNZxO-awBC-bNrjRNrt86fykU/edit
( pkg_development: line 23) ok https://black.readthedocs.io/en/stable/
( pkg_development: line 451) ok https://coverage.readthedocs.io/en/latest/
( pkg_development: line 29) ok https://codecov.io/gh/UBC-MOAD/moad_tools/branch/main/graph/badge.svg
( pkg_development: line 23) ok https://app.codecov.io/gh/UBC-MOAD/moad_tools
( pkg_development: line 36) ok https://app.readthedocs.org/projects/ubc-moad-tools/badge/?version=latest
( pkg_development: line 112) ok https://docs.conda.io/en/latest/
( pkg_development: line 112) ok https://docs.conda.io/en/latest/miniconda.html
( pkg_development: line 500) ok https://docs.github.com/en/actions
( pkg_development: line 23) ok https://docs.python.org/3/
( moad_tools: line 261) ok https://docs.python.org/3/library/datetime.html#datetime.datetime
( pkg_development: line 418) ok https://docs.pytest.org/en/latest/
( moad_tools: line 3) ok https://docs.python.org/3/library/exceptions.html#KeyError
( moad_tools: line 261) ok https://docs.python.org/3/library/functions.html#float
( pkg_development: line 204) ok https://app.readthedocs.org/projects/ubc-moad-tools/builds/
( moad_tools: line 33) ok https://docs.python.org/3/library/functions.html#int
( moad_tools: line 116) ok https://docs.python.org/3/library/pathlib.html#pathlib.Path
( moad_tools: line 261) ok https://docs.python.org/3/library/stdtypes.html#dict
( moad_tools: line 4) ok https://docs.google.com/spreadsheets/d/1dlT0JydkFG43LorqgtHle5IN6caRYjf_3qLrUYqANDY/edit
( moad_tools: line 1) ok https://docs.google.com/document/d/14hAxrTFpKloy88zRYLL4TiqLwbn8s53MYQeCt6B3MJ4/edit
( moad_tools: line 261) ok https://docs.python.org/3/library/stdtypes.html#list
( moad_tools: line 24) ok https://docs.python.org/3/library/stdtypes.html#str
( moad_tools: line 67) ok https://docs.xarray.dev/en/stable/generated/xarray.Dataset.html#xarray.Dataset
( moad_tools: line 261) ok https://docs.python.org/3/library/stdtypes.html#tuple
( pkg_development: line 515) ok https://git-scm.com/
( pkg_development: line 26) ok https://github.com/UBC-MOAD/moad_tools/actions/workflows/pytest-with-coverage.yaml/badge.svg
( pkg_development: line 32) ok https://github.com/UBC-MOAD/moad_tools/actions/workflows/codeql-analysis.yaml/badge.svg
( pkg_development: line 23) ok https://github.com/UBC-MOAD/moad_tools
( pkg_development: line 487) ok https://github.com/UBC-MOAD/moad_tools/actions
( pkg_development: line 293) ok https://github.com/UBC-MOAD/moad_tools/actions?query=workflow%3Asphinx-linkcheck
( pkg_development: line 23) ok https://github.com/UBC-MOAD/moad_tools/actions?query=workflow:CodeQL
( pkg_development: line 478) ok https://github.com/UBC-MOAD/moad_tools/actions?query=workflow%3Apytest-with-coverage
( pkg_development: line 23) ok https://github.com/UBC-MOAD/moad_tools/issues
( pkg_development: line 480) ok https://github.com/UBC-MOAD/moad_tools/workflows/pytest-with-coverage/badge.svg
( pkg_development: line 23) ok https://github.com/UBC-MOAD/moad_tools/actions?query=workflow:pytest-with-coverage
( pkg_development: line 23) ok https://github.com/UBC-MOAD/moad_tools/releases
( pkg_development: line 65) ok https://img.shields.io/badge/%F0%9F%A5%9A-Hatch-4051b5.svg
( pkg_development: line 23) ok https://github.com/UBC-MOAD/moad_tools/actions?query=workflow:sphinx-linkcheck
( pkg_development: line 62) ok https://img.shields.io/badge/code%20style-black-000000.svg
( pkg_development: line 59) ok https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white
( pkg_development: line 295) ok https://github.com/UBC-MOAD/moad_tools/workflows/sphinx-linkcheck/badge.svg
( pkg_development: line 56) ok https://img.shields.io/badge/version%20control-git-blue.svg?logo=github
( pkg_development: line 53) ok https://img.shields.io/badge/license-Apache%202-cb2533.svg
( pkg_development: line 43) ok https://img.shields.io/github/v/release/UBC-MOAD/moad_tools?logo=github
( pkg_development: line 46) ok https://img.shields.io/python/required-version-toml?tomlFilePath=https://raw.githubusercontent.com/UBC-MOAD/moad_tools/main/pyproject.toml&logo=Python&logoColor=gold&label=Python
( pkg_development: line 49) ok https://img.shields.io/github/issues/UBC-MOAD/moad_tools?logo=github
( moad_tools: line 161) ok https://mohid-cmd.readthedocs.io/en/latest/
( moad_tools: line 67) ok https://numpy.org/doc/1.18/reference/generated/numpy.ndarray.html#numpy.ndarray
( moad_tools: line 161) ok https://mohid-cmd.readthedocs.io/en/latest/monte-carlo.html#monte-carlo-sub-command
( moad_tools: line 261) ok https://numpy.org/doc/1.18/reference/random/generator.html#numpy.random.Generator
( pkg_development: line 128) ok https://pip.pypa.io/en/stable/topics/local-project-installs/#editable-installs
( moad_tools: line 5) ok https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.html#pandas.DataFrame
( pkg_development: line 23) ok https://github.com/pypa/hatch
( pkg_development: line 451) ok https://pytest-cov.readthedocs.io/en/latest/
( moad_tools: line 67) ok https://rasterio.readthedocs.io/en/latest/api/rasterio.io.html#rasterio.io.DatasetReader
( pkg_development: line 23) ok https://ubc-moad-tools.readthedocs.io/en/latest/
( pkg_development: line 23) ok https://pre-commit.com
( pkg_development: line 154) ok https://pre-commit.com/
( index: line 9) ok https://www.apache.org/licenses/LICENSE-2.0
( pkg_development: line 187) ok https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html
( pkg_development: line 187) ok https://www.sphinx-doc.org/en/master/
( moad_tools: line 1) ok https://www.ndbc.noaa.gov/data/realtime2/
( pkg_development: line 487) ok https://github.com/UBC-MOAD/moad_tools/commits/main
( pkg_development: line 83) ok https://www.python.org/
( pkg_development: line 39) ok https://github.com/UBC-MOAD/moad_tools/actions/workflows/sphinx-linkcheck.yaml/badge.svg
( index: line 6) ok https://github.com/UBC-MOAD/docs/blob/main/CONTRIBUTORS.rst
build succeeded.
Look for any errors in the above output or in _build/linkcheck/output.txt
make linkcheck is run monthly via a scheduled GitHub Actions workflow
Running the Unit Tests
The test suite for the moad_tools package is in moad_tools/tests/.
The pytest tool is used for test parametrization and as the test runner for the suite.
Use:
$ cd moad_tools/
$ pixi run -e test pytest
to run the test suite. The output looks something like:
================================ test session starts ================================
platform linux -- Python 3.14.4, pytest-9.0.3, pluggy-1.6.0
Using --randomly-seed=3958680343
rootdir: /media/doug/warehouse/MOAD/moad_tools
configfile: pyproject.toml
plugins: randomly-3.15.0, cov-7.1.0
collected 96 items
tests/midoss/test_hdf5_to_netcdf4.py ss [ 2%]
tests/midoss/test_geotiff_watermask.py ss [ 4%]
tests/midoss/test_random_oil_spills.py .s.............................................
............................ss............ [ 96%]
tests/test_observations.py ... [100%]
=========================== 89 passed, 7 skipped in 1.57s ===========================
You can monitor what lines of code the test suite exercises using the coverage.py and pytest-cov tools with the command:
$ cd moad_tools/
$ 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
moad_tools/htmlcov/index.html.
Continuous Integration
The moad_tools 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-with-coverage.yaml file.
Version Control Repository
The moad_tools package code and documentation source files are available
in the moad_tools Git repository at https://github.com/UBC-MOAD/moad_tools.
Issue Tracker
Development tasks, bug reports, and enhancement ideas are recorded and managed in the issue tracker at https://github.com/UBC-MOAD/moad_tools/issues
License
The UBC EOAS MOAD Group moad_tools Python package code and documentation are copyright 2018 – present by the UBC EOAS MOAD Group and The University of British Columbia.
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.25.2.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