Skip to content

Commit

Permalink
Switch to pixi (#384)
Browse files Browse the repository at this point in the history
* Add dependencies to pixi.toml

* Pixi-ize pre-commit

* Add pixi tasks

* Update CI

* Fix build dependencies

* update lockfile

* Fix doctest

* Try to fix readthedocs

* Use latest pixi on conda-forge

* Find some minimum versions

* Bump minimum formulaic version

* Find minimum numpy version

* Make polars a test dependency

* Update lockfile

* Fix typing issues

* Fix benchmarks

* Update contributing docs

* Make ruff happy

* Remove unnecessary pre-commit option from CI
  • Loading branch information
stanmart authored Sep 11, 2024
1 parent 0d808fb commit 8c88f59
Show file tree
Hide file tree
Showing 22 changed files with 18,382 additions and 266 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# GitHub syntax highlighting
pixi.lock linguist-language=YAML linguist-generated=true
84 changes: 26 additions & 58 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,87 +3,55 @@ on: [push]

jobs:
pre-commit-checks:
name: pre-commit checks
name: Linux - pre-commit checks
timeout-minutes: 30
runs-on: ubuntu-latest
env:
PRE_COMMIT_USE_MICROMAMBA: 1
steps:
- name: Checkout branch
uses: actions/checkout@v4
- name: Set up micromamba
uses: mamba-org/setup-micromamba@f8b8a1e23a26f60a44c853292711bacfd3eac822
- name: Add micromamba to GITHUB_PATH
run: echo "${HOME}/micromamba-bin" >> "$GITHUB_PATH"
- name: Install Python 3.10
uses: actions/setup-python@v5
- name: Set up pixi
uses: prefix-dev/[email protected]
with:
python-version: "3.10"
- name: Run pre-commit checks
uses: pre-commit/[email protected]
environments: lint default
- name: pre-commit
run: pixi run -e lint pre-commit-run --color=always --show-diff-on-failure

unit-tests:
name: Tests - ${{ matrix.os }} - Py${{ matrix.python-version }} - ${{ matrix.note }}
name: Tests
runs-on: ${{ matrix.os }}
env:
CI: True
strategy:
fail-fast: true
matrix:
include:
- { os: ubuntu-latest, python-version: '3.9', note: 'Default Builds' }
- { os: ubuntu-latest, python-version: '3.10', note: 'Default Builds' }
- { os: ubuntu-latest, python-version: '3.11', note: 'Default Builds' }
- { os: ubuntu-latest, python-version: '3.12', note: 'Default Builds' }
- { os: ubuntu-latest, python-version: '3.12', note: 'Nightly Builds' }
- { os: macos-latest, python-version: '3.12', note: 'Default Builds' }
- { os: windows-latest, python-version: '3.12', note: 'Default Builds' }
- { os: ubuntu-latest, environment: 'py310' }
- { os: ubuntu-latest, environment: 'py311' }
- { os: ubuntu-latest, environment: 'py312' }
- { os: windows-latest, environment: 'py312' }
- { os: macos-latest, environment: 'py312' }
- { os: ubuntu-latest, environment: 'oldies' }
- { os: ubuntu-latest, environment: 'nightly' }
steps:
- name: Checkout branch
uses: actions/checkout@v4
- name: Set up conda env
uses: mamba-org/setup-micromamba@f8b8a1e23a26f60a44c853292711bacfd3eac822
- name: Set up pixi
uses: prefix-dev/setup-pixi@992a3081e2f87829e0fff9fb29f4fe6a5d1e80a2
with:
environment-file: ${{ matrix.os == 'windows-latest' && 'environment-win.yml' || 'environment.yml' }}
init-shell: ${{ matrix.os == 'windows-latest' && 'powershell' || 'bash' }}
cache-environment: true
create-args: >-
python=${{ matrix.python-version }}
environments: ${{ matrix.environment }}
- name: Install nightlies
if: matrix.note == 'Nightly Builds'
shell: bash -el {0}
run: |
PRE_WHEELS="https://pypi.anaconda.org/scientific-python-nightly-wheels/simple/"
for pkg in numpy pandas scipy; do
echo "Installing $pkg nightly"
micromamba remove -y --force $pkg
pip install --pre --no-deps --only-binary :all: --upgrade --timeout=60 -i $PRE_WHEELS $pkg
done
micromamba remove -y --force formulaic
pip install --no-deps git+https://github.com/matthewwardrop/formulaic
micromamba list
- name: Install repository (unix)
if: matrix.os != 'windows-latest'
shell: bash -el {0}
run: pip install --no-use-pep517 --no-deps --disable-pip-version-check -e .
- name: Install repository (windows)
if: matrix.os == 'windows-latest'
shell: powershell
run: pip install --no-use-pep517 --no-deps --disable-pip-version-check -e .
- name: Run pytest (unix)
if: matrix.os != 'windows-latest'
shell: bash -el {0}
run: pytest -nauto tests -m "not high_memory" --doctest-modules src/
- name: Run pytest (windows)
if: matrix.os == 'windows-latest'
shell: powershell
run: pytest -nauto tests -m "not high_memory"
if: matrix.NOTE == 'Nightly Builds'
run: pixi run -e ${{ matrix.environment }} install-nightlies
- name: Install repository
run: pixi run -e ${{ matrix.environment }} postinstall
- name: Run pytest
run: pixi run -e ${{ matrix.environment }} test -nauto -m "not high_memory"
- name: Run doctest
if: matrix.os != 'windows-latest'
shell: bash -el {0}
# Check that the readme example will work by running via doctest.
# We run outside the repo to make the test a bit more similar to
# a user running after installing with conda.
run: |
mkdir ../temp
cp README.md ../temp
cd ../temp
python -m doctest -v README.md
pixi run --manifest-path ../tabmat/pixi.toml -e ${{ matrix.environment }} python -m doctest -v README.md
47 changes: 24 additions & 23 deletions .github/workflows/daily.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,42 @@ on:

jobs:
linux-daily-unittests:
name: Daily unit tests - Py${{ matrix.python-version }} - ${{ matrix.note }}
name: "Linux - daily unit tests - ${{ matrix.NOTE }}"
runs-on: ubuntu-latest
env:
CI: True
strategy:
fail-fast: false
matrix:
include:
- { python-version: '3.9', note: 'Default Builds' }
- { python-version: '3.12', note: 'Nightly Builds' }
- environment: 'nightly'
NOTE: 'Nightly Builds' # run once with nightlies
- environment: 'py312'
NOTE: 'Python 3.12' # run once with normal dependencies
steps:
- name: Checkout branch
uses: actions/checkout@v4
- uses: mamba-org/setup-micromamba@f8b8a1e23a26f60a44c853292711bacfd3eac822
- name: Set up pixi
uses: prefix-dev/setup-pixi@992a3081e2f87829e0fff9fb29f4fe6a5d1e80a2
with:
environment-file: environment.yml
create-args: >-
python=${{ matrix.python-version }}
environments: ${{ matrix.environment }}
- name: Install nightlies
if: matrix.note == 'Nightly Builds'
shell: bash -el {0}
run: |
PRE_WHEELS="https://pypi.anaconda.org/scientific-python-nightly-wheels/simple/"
for pkg in numpy pandas scipy; do
echo "Installing $pkg nightly"
micromamba remove -y --force $pkg
pip install --pre --no-deps --only-binary :all: --upgrade --timeout=60 -i $PRE_WHEELS $pkg
done
micromamba remove -y --force formulaic
pip install --no-deps git+https://github.com/matthewwardrop/formulaic
micromamba list
if: matrix.NOTE == 'Nightly Builds'
run: pixi run -e ${{ matrix.environment }} install-nightlies
- name: Install repository
shell: bash -el {0}
run: pip install --no-use-pep517 --no-deps --disable-pip-version-check -e .
run: pixi run -e ${{ matrix.environment }} postinstall
- name: Run pytest
shell: bash -el {0}
run: pytest -nauto tests -m "not high_memory" --doctest-modules src/
run: pixi run -e ${{ matrix.environment }} test -nauto -m "not high_memory"
- name: Run doctest
# Check that the readme example will work by running via doctest.
# We run outside the repo to make the test a bit more similar to
# a user running after installing with conda.
run: |
mkdir ../temp
cp README.md ../temp
cd ../temp
pixi run --manifest-path ../tabmat/pixi.toml -e ${{ matrix.environment }} python -m doctest -v README.md
- name: Issue on failure
uses: actions/github-script@v7
if: ${{ failure() && github.ref == 'refs/heads/main' }}
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Project-specific
benchmark/*.csv
benchmark/data/*.csv
benchmark/data/*.pkl

# Files created by templating
Expand Down Expand Up @@ -147,3 +148,6 @@ pkgs/*
*.c
*.cpp
!*tmpl.cpp
# pixi environments
.pixi
*.egg-info
59 changes: 45 additions & 14 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,47 @@
exclude: ^.pixi$
repos:
- repo: https://github.com/Quantco/pre-commit-mirrors-ruff
rev: 0.6.2
- repo: local
hooks:
- id: ruff-conda
- id: ruff-format-conda
- repo: https://github.com/Quantco/pre-commit-mirrors-mypy
rev: "1.10.1"
hooks:
- id: mypy-conda
- repo: https://github.com/Quantco/pre-commit-mirrors-cython-lint
rev: 0.16.2
hooks:
- id: cython-lint-conda
args: [--no-pycodestyle]
- id: double-quote-cython-strings-conda
# ensure pixi environments are up to date
# workaround for https://github.com/prefix-dev/pixi/issues/1482
- id: pixi-install
name: pixi-install
entry: pixi install -e default -e lint
language: system
always_run: true
require_serial: true
pass_filenames: false
# ruff
- id: ruff
name: ruff
entry: pixi run -e lint ruff check --fix --exit-non-zero-on-fix --force-exclude
language: system
types_or: [python, pyi]
require_serial: true
- id: ruff-format
name: ruff-format
entry: pixi run -e lint ruff format --force-exclude
language: system
types_or: [python, pyi]
require_serial: true
# mypy
- id: mypy
name: mypy
entry: pixi run -e default mypy --allow-redefinition
exclude: (^tests/)
language: system
types: [python]
require_serial: true
# cython-lint
- id: cython-lint
name: cython-lint
entry: pixi run -e lint cython-lint --no-pycodestyle
language: system
types: [cython]
require_serial: true
- id: cython-double-quote
name: cython-double-quote
entry: pixi run -e lint double-quote-cython-strings
language: system
types: [cython]
require_serial: true
14 changes: 6 additions & 8 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ version: 2
build:
os: ubuntu-22.04
tools:
python: mambaforge-22.9
python: mambaforge-4.10
commands:
- mamba install -c conda-forge -c nodefaults pixi==0.27.0
- pixi run -e docs postinstall
- pixi run readthedocs
sphinx:
configuration: docs/conf.py
python:
install:
- method: pip
path: .
conda:
environment: environment.yml
formats:
- pdf
- pdf
48 changes: 24 additions & 24 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,51 +28,51 @@ Releases

Development installation
------------------------
For development, you should do an editable installation:
We use [pixi](https://prefix.dev/) for setting up the project dependencies. [Install it](https://pixi.sh/latest/#installation) first if you do not have it already. The following commands will set up the project for development:

```bash
# First, make sure you have conda-forge as your primary conda channel:
conda config --add channels conda-forge
# And install pre-commit
conda install -y pre-commit

git clone [email protected]:Quantco/tabmat.git
cd tabmat

# Set up our pre-commit hooks for ruff, mypy, and cython-lint.
pre-commit install
pixi run pre-commit-install

# Set up a pixi environment with the dependencies and install the package in editable mode.
pixi run postinstall

# If you want to install the dependencies necessary for benchmarking against other GLM packages:
pixi run -e benchmark postinstall

# Set up a conda environment with name "tabmat"
conda env create
# If you want to work on the documentation:
pixi run -e docs postinstall

# Install this package in editable mode.
conda activate tabmat
pip install --no-use-pep517 --disable-pip-version-check -e .
# You can run any command in the pixi environment with `pixi run <command>`. For example:
pixi run [-e ENVIRONMENT] ipython

# Alternatively, you can create a shell with the pixi environment activated:
pixi shell

# A number of pixi tasks are available for commonly used commands.
# You can run them with `pixi run <task>`.
# To get a list of available tasks, run:
pixi task list
```

Testing and continuous integration
--------------------------------------------------
The test suite is in ``tests/`` and can be run using ``pytest``.
The test suite is in ``tests/`` and can be run using ``pixi run test``.

Developing the documentation
----------------------------------------

The documentation is built with Sphinx. To develop the documentation:

::

cd docs
make html
python -m http.server --directory _build/html

Then, navigate to `<http://localhost:8000>`_ to view the documentation.
The documentation is built with Sphinx. To develop the documentation: ``pixi run serve-docs``. Then, navigate to `<http://localhost:8000>`_ to view the documentation.

Alternatively, if you install `entr <http://eradman.com/entrproject/>`_, then you can auto-rebuild the documentation any time a file changes with:

::

```bash
cd docs
./dev
```

Conda-forge packaging
---------------------
Expand Down
4 changes: 2 additions & 2 deletions docs/benchmarks.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Benchmarks
==========

To generate the data to run all the benchmarks: ``python src/tabmat/benchmark/generate_matrices.py``. Then, to run all the benchmarks: ``python src/tabmat/benchmark/main.py``. To produce or update these figures, open ``src/tabmat/benchmark/visualize_benchmarks.py`` as a notebook via ``jupytext``.
To generate the data to run all the benchmarks: ``pixi run benchmark-generate-matrices``. Then, to run all the benchmarks with default settings: ``python src/tabmat/benchmark/benchmark-run``. To produce or update these figures, open ``src/tabmat/benchmark/visualize_benchmarks.py`` as a notebook via ``jupytext``.

For more info on the benchmark CLI: ``python src/tabmat/benchmark/main.py --help``.
For more info on the benchmark CLI: ``pixi run python src/tabmat/benchmark/main.py --help``.

Performance
^^^^^^^^^^^
Expand Down
Loading

0 comments on commit 8c88f59

Please sign in to comment.