Setting up the development environment#

scikit-lr contains Cython extensions, so it must be compiled to be used from the source tree. The development environment is declared in environment.yml and uses packages from conda-forge, compilers included, so the same steps work on Linux, macOS and Windows. On Windows, the compilers of conda-forge use the ones of Microsoft, so the Build Tools for Visual Studio must be installed with the “Desktop development with C++” workload.

Cloning the repository#

Fork the repository on GitHub, clone your fork and add the main repository as the upstream remote, to keep your branches up to date with it:

$ git clone https://github.com/<your-username>/scikit-lr.git
$ cd scikit-lr
$ git remote add upstream https://github.com/alfaro96/scikit-lr.git

Installing scikit-lr#

Create the environment with micromamba (or conda), activate it and install scikit-lr in editable mode:

$ micromamba create -f environment.yml
$ micromamba activate scikit-lr
$ pip install --no-build-isolation --no-deps -e .

--no-build-isolation builds scikit-lr with the packages of the environment, instead of with packages that pip would download, so the extensions are compiled against the scikit-learn that runs them. --no-deps keeps pip from installing the dependencies, which come from conda-forge.

The editable install recompiles the extensions when sklr is imported, so there is no need to reinstall after changing a Python or Cython file, or a meson.build file. It is only needed after changing the environment, such as the version of Python, scikit-learn or Cython. When environment.yml changes, update the environment with:

$ micromamba env update -f environment.yml

Finally, install the pre-commit hooks, which check every commit:

$ pre-commit install

Building with Meson#

scikit-lr is built with meson-python. The meson.build file of each directory lists the files that are installed, so a new Python module or Cython extension must be added to it. Otherwise it cannot be imported, and the CI reports that it is missing from the wheels. The scikit-learn guide explains how Meson works.

Troubleshooting#

If importing sklr fails because a meson executable inside a pip-build-env-* directory does not exist, scikit-lr was installed without --no-build-isolation. pip built it in a temporary environment that no longer exists, so the editable install cannot recompile it. Install it again with the command above.

If importing sklr raises an ImportError because it was built against another scikit-learn, the environment changed after installing it. Install it again, so that it is compiled against the installed scikit-learn.