Reshapr Package Development

Continuous Integration

Pytest with Coverage Status Codecov Testing Coverage Report CodeQL analysis

Documentation

Documentation Status Sphinx linkcheck

Package

Releases Python Version from PEP 621 TOML Issue Tracker

Meta

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

The Reshapr package (Reshapr) is Command-line tool based on Xarray and Dask for extraction of model variable time series from model products like SalishSeaCast, HRDPS & CANESM2/CGCM4.

Python Versions

Python Version from PEP 621 TOML

The Reshapr package is developed and tested using Python 3.14. The package uses some Python language features that are not available in various earlier versions, in particular:

The minimum supported Python version is 3.12. The Continuous Integration workflow on GitHub ensures that the package is tested for all versions of Python>=3.12.

Getting the Code

Git on GitHub

Clone the code and documentation repository from GitHub with:

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

or copy the URI (the stuff after git clone above) from the Code button on the repository page.

Note

The git clone command above assumes that your are connecting to GitHub using SSH. If it fails, please follow the instructions in our Secure Remote Access docs to set up your SSH keys and Copy Your Public ssh Key to GitHub.

Development Environment

Pixi

Reshapr 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 Reshapr/ directory (or a sub-directory). Dependencies will be downloaded and linked in to environments when you use pixi run for the first time.

  • The default environment has the packages installed that are required to run the Reshapr command-line interface; e.g. pixi run reshapr help

  • 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 dev environment. 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.

Reshapr 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

pre-commit The uncompromising Python code formatter

The Reshapr 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 Reshapr
$ 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 Reshapr repository and build your Development Environment.

Building the Documentation

Documentation Status

The documentation for the Reshapr package is written in reStructuredText and converted to HTML using Sphinx. Creating a Development Environment as described above includes the installation of Sphinx. Building the documentation is driven by the docs/Makefile. To do a clean build of the documentation use:

$ cd Reshapr
$ pixi run docs

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 'arrow' from https://arrow.readthedocs.io/en/latest/objects.inv ...
loading intersphinx inventory 'dask' from https://docs.dask.org/en/stable/objects.inv ...
loading intersphinx inventory 'moaddocs' from https://ubc-moad-docs.readthedocs.io/en/latest/objects.inv ...
loading intersphinx inventory 'python' from https://docs.python.org/3/objects.inv ...
loading intersphinx inventory 'salishseanowcast' from https://salishsea-nowcast.readthedocs.io/en/latest/objects.inv ...
loading intersphinx inventory 'xarray' from 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 22 source files that are out of date
updating environment: [new config] 22 added, 0 changed, 0 removed
reading sources... [100%] subcommands/info
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/Reshapr/docs/_build/html/_static/language_data.js
Writing evaluated template result to /media/doug/warehouse/MOAD/Reshapr/docs/_build/html/_static/documentation_options.js
Writing evaluated template result to /media/doug/warehouse/MOAD/Reshapr/docs/_build/html/_static/basic.css
Writing evaluated template result to /media/doug/warehouse/MOAD/Reshapr/docs/_build/html/_static/js/versions.js
copying static files: done
copying extra files...
copying extra files: done
copying assets: done
writing output... [100%] subcommands/info
generating indices... genindex py-modindex done
highlighting module code... [100%] reshapr.utils.date_formatters
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. If you use Firefox, you can probably accomplish that with:

$ 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://reshapr.readthedocs.io/en/latest/.

Running the Unit Tests

The test suite for the Reshapr package is in Reshapr/tests/. The pytest tool is used for test parametrization and as the test runner for the suite.

To run the test suite in the most recent supported version of Python use:

$ cd Reshapr/
$ 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=852482656
rootdir: /media/doug/warehouse/MOAD/Reshapr
configfile: pyproject.toml
plugins: randomly-3.15.0, cov-7.1.0

tests/api/v1/test_extract_api_v1.py .........                                   [  2%]
tests/core/test_info.py ...............................                         [ 13%]
tests/core/test_dask_cluster.py .........                                       [ 16%]
tests/utils/test_date_formatters.py ...........                                 [ 19%]
tests/test_cluster_configs.py .....                                             [ 21%]
tests/test_model_profiles.py .........................................................
...............................                                                 [ 50%]
tests/cli/test_cli.py ..                                                        [ 51%]
tests/core/test_extract.py ...........................................................
......................................................................................
...                                                                             [100%]

=============================== 303 passed in 8.42s ================================

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

$ cd Reshapr/
$ 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 Reshapr/htmlcov/index.html.

Continuous Integration

Pytest with Coverage Status Codecov Testing Coverage Report

The Reshapr 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

Git on GitHub

The Reshapr package code and documentation source files are available as a Git repository at https://github.com/UBC-MOAD/Reshapr.

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/Reshapr/issues.

License

Licensed under the Apache License, Version 2.0

The code and documentation of the Reshapr project are copyright 2022 – 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 pixi run -e dev hatch version release to bump the version from .devn to the next release version identifier; e.g. 25.2.dev0 to 26.1

  2. Use pixi update to update the lock file to reflect the new version identifier

  3. Commit the version bump

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

  5. Push the version bump commit and tag to GitHub

  6. Use the GitHub web interface to create a release, editing the auto-generated release notes into sections:

    ### Features
    
    ### Bug Fixes
    
    ### Documentation
    
    ### Maintenance
    
    ### Dependency Updates
    
  7. 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

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

    • Set 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

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

  10. Close the milestone for the just released version.

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

  12. Use pixi update to update the lock file to reflect the new version identifier

  13. Commit the version bump

  14. Push the version bump commit to GitHub