For Developers

Installing from Source

git clone https://github.com/aditya-grover/climate-learn.git
pip install -e climate-learn

Development and documentation dependencies can be installed by specifying the extras [dev] and [docs], respectively.

Formatting and Linting

ClimateLearn uses black for formatting and flake8 for linting.

black .
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics

Testing

ClimateLearn uses pytest for testing. Tests can be run as:

pytest tests/

Notes about writing tests:

  1. Import the package as import climate_learn rather than import src.climate_learn.

  2. For tests that require access to resources not available on GitHub Actions Runner, use the following:

# place this at the start of your test script
GITHUB_ACTIONS = os.environ.get("GITHUB_ACTIONS") == "true"

# place this on the line before your test function definition
@pytest.mark.skipif(GITHUB_ACTIONS, reason="only works locally")
def my_local_test(...):
    ... # test function body

Documentation

ClimateLearn uses reStructuredText. Example docstring:

 1def doc_example_function(arg1, arg2, kwarg1=False):
 2    r"""One sentence description of the function.
 3        Use the following lines to talk about what the function does at a
 4        high level and to provide any necessary additional context.
 5
 6    .. highlight:: python
 7
 8    :param arg1: Description of the first argument.
 9    :type arg1: str
10    :param arg2: Description of the second argument.
11    :type arg2: int|float
12    :param kwarg1: Description of the first keyword argument. Maybe we want
13        to use some syntax highlighting here. This can be achieved as such:
14        :python:`class MyClass`. Defaults to `False`.
15    :type kwarg1: bool, optional
16    :returns: Description of what the function returns.
17    :rtype: bool
18    """
19    return False

Suppose this function is available at the top level of the climate_learn package. It can be imported to the docs as such:

.. This is a reStructuredText comment. Maybe this file is at docs/source/file.rst
.. autofunction:: climate_learn.doc_example_function

Further readings: