The typical workflow for contributing to river is:
- Fork the
masterbranch from the GitHub repository. - Clone your fork locally.
- Commit changes.
- Push the changes to your fork.
- Send a pull request from your fork back to the original
masterbranch.
We encourage you to use a virtual environment. You'll want to activate it every time you want to work on river.
$ python -m venv .venv
$ source .venv/bin/activateYou can also create a virtual environment via conda:
$ conda create -n river -y python=3.8 anaconda
$ conda activate riverThen, navigate to your cloned fork and install the required dependencies:
$ pip install -e ".[dev]"Next, install river in development mode:
$ python setup.py developFinally, install the pre-commit push hooks. This will run some code quality checks every time you push to GitHub.
$ pre-commit install --hook-type pre-pushYou can optionally run pre-commit at any time as so:
$ pre-commit run --all-filesYou're now ready to make some changes. We strongly recommend that you to check out river's source code for inspiration before getting into the thick of it. How you make the changes is up to you of course. However we can give you some pointers as to how to test your changes. Here is an example workflow that works for most cases:
- Create and open a Jupyter notebook at the root of the directory.
- Add the following in the code cell:
%load_ext autoreload
%autoreload 2- The previous code will automatically reimport
riverfor you whenever you make changes. - For instance, if a change is made to
linear_model.LinearRegression, then rerunning the following code doesn't require rebooting the notebook:
from river import linear_model
model = linear_model.LinearRegression()- Pick a base class from the
basemodule. - Check if any of the mixin classes from the
basemodule apply to your implementation. - Make you've implemented the required methods, with the following exceptions:
- Stateless transformers do not require a
learn_onemethod. - In case of a classifier, the
predict_oneis implemented by default, but can be overridden.
- Stateless transformers do not require a
- Add type hints to the parameters of the
__init__method. - If possible provide a default value for each parameter. If, for whatever reason, no good default exists, then implement the
_unit_test_paramsmethod. This is a private method that is meant to be used for testing. - Write a comprehensive docstring with example usage. Try to have empathy for new users when you do this.
- Check that the class you have implemented is imported in the
__init__.pyfile of the module it belongs to. - When you're done, run the
utils.check_estimatorfunction on your class and check that no exceptions are raised.
If you're adding a class or a function, then you'll need to add a docstring. We follow the Google docstring convention, so please do too.
To build the documentation, you need to install some extra dependencies:
$ pip install -e ".[docs]"From the root of the repository, you can then run the make livedoc command to take a look at the documentation in your browser. This will run a custom script which parses all the docstrings and generate MarkDown files that MkDocs can render.
All classes and function are automatically picked up and added to the documentation. The only thing you have to do is to add an entry to the relevant file in the docs/releases directory.
$ make cythonUnit tests
These tests absolutely have to pass.
$ pytestStatic typing
These tests absolutely have to pass.
$ mypy riverWeb dependent tests
This involves tests that need an internet connection, such as those in the datasets module which requires downloading some files. In most cases you probably don't need to run these.
$ pytest -m webNotebook tests
You don't have to worry too much about these, as we only check them before each release. If you break them because you changed some code, then it's probably because the notebooks have to be modified, not the other way around.
$ make execute-notebooks