Before contributing to OpTree, please follow the instructions below to setup.
-
Fork OpTree (fork) on GitHub and clone the repository.
git clone git@github.com:<your username>/optree.git # use the SSH protocol cd optree git remote add upstream git@github.com:metaopt/optree.git
-
Setup a development environment via
conda:conda env create --file conda-recipe.yaml conda activate optree
-
Setup the
pre-commithooks:pre-commit install --install-hooks
Then you are ready to rock. Thanks for contributing to OpTree!
To install OpTree in an "editable" mode, run:
make install-editable # or run `pip3 install --no-build-isolation --editable .`in the main directory. This installation is removable by:
make uninstallWe use several tools to secure code quality, including:
- Python code style:
ruff,isort,pylint - Type hint check:
mypy - C++ code style:
cpplint,clang-format,clang-tidy - License:
addlicense - Documentation:
pydocstyle,doc8,xdoctest
To make things easier, we create several shortcuts as follows.
To automatically format the code, run:
make formatTo check if everything conforms to the specification, run:
make lintThis command will run automatic tests in the main directory:
make testTo build compatible manylinux2014 (PEP 599) wheels for distribution, you can use cibuildwheel.
You will need to install docker first.
Then run the following command:
python3 -m pip install --upgrade cibuildwheel
python3 -m cibuildwheel --platform=linux --output-dir=wheelhouse --config-file=pyproject.tomlIt will build wheel binaries for all supported CPython versions. The outputs will be placed in the wheelhouse directory.
To build a wheel for a specific CPython version, you can use the CIBW_BUILD environment variable.
For example, the following command will build a wheel for Python 3.9:
CIBW_BUILD="cp39*manylinux*" python3 -m cibuildwheel --platform=linux --output-dir=wheelhouse --config-file=pyproject.tomlYou can change cp39* to cp312* to build for Python 3.12. See https://cibuildwheel.readthedocs.io/en/stable/options for more options.
Documentation is written under the docs/source directory as ReStructuredText (.rst) files.
index.rst is the main page.
A Tutorial on ReStructuredText can be found here.
API References are automatically generated by Sphinx and should be modified when any code changes.
To compile documentation into webpage, run
make docsThe generated webpage is located under directory docs/build and will open the browser after building documentation.
Detailed documentation is hosted online at https://optree.readthedocs.io.