moad_tools Package Development

Continuous Integration

Pytest with Coverage Status Codecov Testing Coverage Report CodeQL analysis

Documentation

Documentation Status Sphinx linkcheck

Package

Releases Python Version Issue Tracker

Meta

Licensed under the Apache License, Version 2.0 Git on GitHub pre-commit
The uncompromising Python code formatter Hatch project

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

Python Version

The moad_tools package is developed using Python 3.12. It is tested for Python versions >=3.11.

Getting the Code

Git on GitHub

Clone the code and documentation repository from GitHub with:

$ git clone git@github.com:UBC-MOAD/moad_tools.git

Development Environment

Setting up an isolated development environment using Conda is recommended. Assuming that you have Miniconda3 installed, you can create and activate an environment called moad-tools that will have all of the Python packages necessary for development, testing, and building the documentation with the commands below:

$ cd moad_tools
$ conda env create -f envs/environment-dev.yaml
$ conda activate moad-tools

moad_tools is installed in editable install mode as part of the conda environment creation process. That means that the package is installed from the cloned repo via symlinks so that it will be automatically updated as the repo evolves.

To deactivate the environment use:

(moad-tools)$ conda deactivate

Coding Style

pre-commit The uncompromising Python code formatter

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
$ conda activate moad-tools
(moad-tools)$ 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

Documentation Status

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. With your moad-tools environment activated, use:

(moad-tools)$ cd moad_tools/docs/
(moad-tools) docs$ make clean html

to do a clean build of the documentation. The output looks something like:

  Removing everything under '_build'...
  Running Sphinx v7.2.6
  making output directory... done
  loading intersphinx inventory from https://mohid-cmd.readthedocs.io/en/latest/objects.inv...
  loading intersphinx inventory from https://numpy.org/doc/1.18/objects.inv...
  loading intersphinx inventory from https://pandas.pydata.org/docs/objects.inv...
  loading intersphinx inventory from https://docs.python.org/3/objects.inv...
  loading intersphinx inventory from https://rasterio.readthedocs.io/en/latest/objects.inv...
  loading intersphinx inventory from https://shapely.readthedocs.io/en/latest/objects.inv...
  loading intersphinx inventory 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... done
  copying extra files... done
  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:

(moad-tools) docs$ firefox _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/.

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.

With your moad-tools development environment activated, use:

(mohid-cmd)$ cd moad_tools/
(mohid-cmd)$ pytest

to run the test suite. The output looks something like:


================================================================================================================================================================= test session starts ================================================================================================================================================================= platform linux – Python 3.12.0, pytest-7.4.3, pluggy-1.3.0 Using –randomly-seed=3176178277 rootdir: /media/doug/warehouse/MOAD/moad_tools plugins: randomly-3.15.0, cov-4.1.0 collected 89 items

tests/test_random_oil_spills.py .s………………………………………………. ………………………… [ 97%] tests/test_observations.py .. [100%]

============================= 88 passed, 1 skipped in 2.01s =============================

You can monitor what lines of code the test suite exercises using the coverage.py and pytest-cov tools with the command:

(mohid-cmd)$ cd moad_tools/
(mohid-cmd)$ pytest --cov=./

The test coverage report will be displayed below the test suite run output.

Alternatively, you can use

(mohid-cmd)$ pytest --cov=./ --cov-report html

to produce an HTML report that you can view in your browser by opening moad_tools/htmlcov/index.html.

Continuous Integration

Pytest with Coverage Status Codecov Testing Coverage Report

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

Git on GitHub

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

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

Licensed under the Apache License, Version 2.0

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 Hatch project

Releases are done at Doug’s discretion when significant pieces of development work have been completed.

The release process steps are:

  1. Use hatch version release to bump the version from .devn to the next release version identifier; e.g. 23.1.dev0 to 23.1

  2. Commit the version bump

  3. Create an annotated tag for the release with Git -> New Tag… in PyCharm or git tag -e -a vyy.n; git tag -e -a v23.1

  4. Push the version bump commit and tag to GitHub

  5. Use the GitHub web interface to create a release, editing the auto-generated release notes as necessary

  6. 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

  7. 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. v23.2

    • Set the Due date to the end of the year of the next release

    • Set the Description to something like v23.2 release - when it's ready :-)

    • Create the next release milestone

  8. Review the open issues, especially any that are associated with the milestone for the just released version, and update their milestone.

  9. Close the milestone for the just released version.

  10. Use hatch version minor,dev to bump the version for the next development cycle, or use hatch version major,minor,dev for a year rollover version bump

  11. Commit the version bump

  12. Push the version bump commit to GitHub