mohid_cmd Package Development

Licensed under the Apache License, Version 2.0 Python Version Git on GitHub pre-commit The uncompromising Python code formatter Documentation Status Sphinx linkcheck GitHub Workflow Status Codecov Testing Coverage Report CodeQL analysis Issue Tracker

The MIDOSS-MOHID command processor package, MOHID-Cmd, provides the mohid command-line tool for doing various operations associated with the MIDOSS project version of the MOHID model.

Python Versions

Python Version

The mohid_cmd package is developed and tested using Python 3.9. The package uses some Python language features that are not available in versions prior to 3.6, in particular:

Getting the Code

Git on GitHub

Clone the code and documentation repository from GitHub with:

$ git clone git@github.com:MIDOSS/MOHID-Cmd.git

Development Environment

The MOHID-Cmd package depends on the NEMO-Cmd package, so you need to clone the NEMO-Cmd repo beside your clone of the MOHID-Cmd repository.

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

$ cd MIDOSS
$ conda env create -f MOHID-Cmd/envs/environment-dev.yaml
$ conda activate mohid-cmd
(mohid-cmd)$ python3 -m pip install --editable NEMO-Cmd/
(mohid-cmd)$ python3 -m pip install --editable MOHID-Cmd/

The --editable option in the python3 -m pip install command above installs the packages from the cloned repos via symlinks so that the installed packages will be automatically updated as the repos evolve.

To deactivate the environment use:

(mohid-cmd)$ conda deactivate

Coding Style

Coding Style

pre-commit The uncompromising Python code formatter

The SalishSeaNowcast 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 MOHID-Cmd
$ conda activate mohid-cmd
(salishsea-nowcast)$ pre-commit install

Note

You only need to install the hooks once immediately after you make a new clone of the `SalishSeaNowcast repository`_ and build your SalishSeaNowcastDevelopmentEnvironment.

Building the Documentation

Documentation Status

The documentation for the MOHID-Cmd 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://mohid-cmd.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 mohid-cmd development environment activated, use:

(mohid-cmd)$ (cd docs && make clean html)

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

Removing everything under '_build'...
Running Sphinx v2.2.2
making output directory... done
loading intersphinx inventory from https://docs.python.org/objects.inv...
intersphinx inventory has moved: https://docs.python.org/objects.inv -> https://docs.python.org/3/objects.inv
building [mo]: targets for 0 po files that are out of date
building [html]: targets for 5 source files that are out of date
updating environment: [new config] 5 added, 0 changed, 0 removed
reading sources... [100%] subcommands
looking for now-outdated files... none found
pickling environment... done
checking consistency... done
preparing documents... done
writing output... [100%] subcommands
generating indices...  genindexdone
writing additional pages...
done
copying static files... ... done
copying extra files... 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 have write access to the repository on GitHub, whenever you push changes to GitHub the documentation is automatically re-built and rendered at https://mohid-cmd.readthedocs.io/en/latest/.

Running the Unit Tests

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

With your mohid-cmd development environment activated, use:

(mohid-cmd)$ cd MOHID-Cmd/
(mohid-cmd)$ pytest

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

=========================== test session starts ============================
platform linux -- Python 3.7.3, pytest-5.3.1, py-1.8.0, pluggy-0.13.0
rootdir: /media/doug/warehouse/MIDOSS/MOHID-Cmd
collected 84 items

tests/test_gather.py .....                                            [  5%]
tests/test_monte_carlo.py ............................                [ 39%]
tests/test_prepare.py ........................                        [ 67%]
tests/test_run.py ...........................                         [100%]

============================ 84 passed in 2.80s ============================

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 MOHID-Cmd/
(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 MOHID-Cmd/htmlcov/index.html.

Continuous Integration

GitHub Workflow Status Codecov Testing Coverage Report

The MOHID-Cmd 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 MOHID-Cmd package code and documentation source files are available as a Git repository at https://github.com/MIDOSS/MOHID-Cmd.

Issue Tracker

Issue Tracker

Development tasks, bug reports, and enhancement ideas are recorded and managed in the issue tracker at https://github.com/MIDOSS/MOHID-Cmd/issues.

License

Licensed under the Apache License, Version 2.0

The code and documentation of the MIDOSS-MOHID Command Processor project are copyright 2018-2021 by the MIDOSS project contributors, The University of British Columbia, and Dalhousie University.

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.