Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MNT moving to pixi for better CI reprodocibility #451

Merged
merged 12 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 22 additions & 66 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
cancel-in-progress: false

jobs:
pytest:
Expand All @@ -15,25 +15,17 @@ jobs:
strategy:
fail-fast: false # need to see which ones fail
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python: ["3.9", "3.10", "3.11", "3.12", "3.13"]
# this is to make the CI run on different sklearn versions
include:
- python: "3.9"
sklearn_version: ">=1.1,<1.2"
numpy_version: "numpy<2"
- python: "3.10"
sklearn_version: ">=1.2,<1.3"
numpy_version: "numpy"
- python: "3.11"
sklearn_version: ">=1.4,<1.5"
numpy_version: "numpy"
- python: "3.12"
sklearn_version: ">=1.5,<1.6"
numpy_version: "numpy"
- python: "3.13"
sklearn_version: "nightly"
numpy_version: "numpy"
os: [windows-latest, ubuntu-latest, macos-latest]
environment: [
# ci-min-deps,
# ci-sklearn11,
# ci-sklearn12,
# ci-sklearn13,
# ci-sklearn14,
ci-sklearn15,
ci-sklearn16,
ci-sklearn17
]

# Timeout: https://stackoverflow.com/a/59076067/4521646
timeout-minutes: 15
Expand All @@ -52,55 +44,19 @@ jobs:
echo PR_COMMIT_MESSAGE=$(git log -1 --pretty=format:\"%s\") >> $GITHUB_ENV
shell: bash

- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v5
- uses: prefix-dev/[email protected]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a next iterations, you can add something like this actions: https://github.com/skrub-data/

It allows to run the pixi update via an Actions and open a pull-request

with:
python-version: ${{ matrix.python }}
pixi-version: v0.39.0
environments: ${{ matrix.environment }}
# we can freeze the environment and manually bump the dependencies to the
# latest version time to time.
frozen: true

- name: Install dependencies
run: |
set -x
python -m pip install -U pip
if [ "${{ matrix.os }}" == "macos-latest" ]; then
brew install libomp
fi
pip install "pytest<8"
pip install "${{ matrix.numpy_version }}"
if [ ${{ matrix.sklearn_version }} == "nightly" ]; then
pip install --pre --extra-index https://pypi.anaconda.org/scientific-python-nightly-wheels/simple scikit-learn
pip install .[docs,tests]
else
pip install .[docs,tests] "scikit-learn${{ matrix.sklearn_version }}"
fi
pip install black=="23.9.1" ruff=="0.0.292" mypy=="1.6.0"
if [ ${{ matrix.os }} == "ubuntu-latest" ]; then
sudo apt install pandoc && pandoc --version;
fi
python --version
pip --version
pip list
shell: bash

- name: Check black
run: black --check --diff .

- name: Check ruff
run: ruff check --diff .

- name: Tests
env:
SUPER_SECRET: ${{ secrets.HF_HUB_TOKEN }}
PYTHONIOENCODING: "utf-8"
run: |
python -m pytest -s -v --cov-report=xml -m "not inference" skops/

- name: Mypy
run: mypy --config-file pyproject.toml skops
- name: Linters
run: pixi run -e lint lint

- name: Inference tests (conditional)
if: contains(env.PR_COMMIT_MESSAGE, '[CI inference]')
run: |
python -l -m pytest -s -v -m "inference" skops/
- name: Run tests
run: pixi run -e ${{ matrix.environment }} tests

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
Expand Down
2 changes: 2 additions & 0 deletions .pixi/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[concurrency]
downloads = 20
4 changes: 2 additions & 2 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ version: 2

# Set the version of Python and other tools you might need
build:
os: ubuntu-20.04
os: ubuntu-lts-latest
tools:
python: "3.10"
python: "3.12"

# Build documentation in the docs/ directory with Sphinx
sphinx:
Expand Down
42 changes: 27 additions & 15 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,29 +57,41 @@ entails. If you don't understand an issue, it's on us, not on you!
Setting up the dev environment
------------------------------

Following these steps you can prepare a dev environment for yourself to
contribute to `skops`.
We use `pixi <https://github.com/prefix-dev/pixi>`_ in our CI and development
workflows and recommend you use it to test the changes you make.

Using conda/mamba
~~~~~~~~~~~~~~~~~
Once you have ``pixi`` installed, you can run the tests with:

.. code:: bash

mamba create -c conda-forge -n skops python=3.10
mamba activate skops
python -m pip install -e ".[tests,docs]"
# add pre-commit hooks
mamba install -c conda-forge pre-commit
pre-commit install
pixi run tests

You can also replace the above `mamba` commands with `conda` if you don't have
`mamba` installed.
And you can choose an environment to run the tests with:

.. code:: bash

pixi run -e ci-sklearn15 tests

In order to setup ``pre-commit`` hooks, you'd need to run the linter once, ignoring
the outputs:

.. code:: bash

pixi run -e lint lint

VSCode-like IDEs automatically detect ``pixi`` environments and you can use them as
your python interpreter.

Running Tests Manually
~~~~~~~~~~~~~~~~~~~~~~

You can get an interactive shell into an environment with a command like the following:

.. code:: bash

Running Tests
~~~~~~~~~~~~~
pixi shell -e ci-sklearn15

skops uses pytest as its test runner, just run it from the project root:
``skops`` uses ``pytest`` as its test runner, just run it from the project root:

.. code:: bash

Expand Down
11 changes: 10 additions & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
-e .[docs]
matplotlib>=3.3
pandas>=1
fairlearn>=0.7.0
sphinx>=3.2.0
sphinx-gallery>=0.7.0
sphinx-rtd-theme>=1
numpydoc>=1.0.0
sphinx-prompt>=1.3.0
sphinx-issues>=1.2.0
-e .[rich]
4 changes: 2 additions & 2 deletions examples/plot_model_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
model_card_authors = "skops_user"
citation_bibtex = "**BibTeX**\n\n```\n@inproceedings{...,year={2020}}\n```"
model_card.add(
**{
**{ # type: ignore
"Citation": citation_bibtex,
"Model Card Authors": model_card_authors,
"Model description": model_description,
Expand All @@ -139,7 +139,7 @@
"The model is evaluated on test data using accuracy and F1-score with "
"macro average."
)
model_card.add(**{"Model description/Evaluation Results": eval_descr})
model_card.add(**{"Model description/Evaluation Results": eval_descr}) # type: ignore

accuracy = accuracy_score(y_test, y_pred)
f1 = f1_score(y_test, y_pred, average="micro")
Expand Down
Loading
Loading