Skip to content

[DEV]: add pixi.lock and add pixi to pyproject.toml - #31384

Open
jklymak wants to merge 3 commits into
matplotlib:mainfrom
jklymak:dev-add-pixi-toml
Open

jklymak wants to merge 3 commits into
matplotlib:mainfrom
jklymak:dev-add-pixi-toml

Conversation

@jklymak

@jklymak jklymak commented Mar 25, 2026 •

Copy link
Copy Markdown
Member

Edit: apologies for the CI churn --- I needed to iterate on the Pixi workflow to get it working end-to-end.

Overview

This PR adds Pixi configuration to pyproject.toml and introduces a committed pixi.lock.

The main goal is to provide a project-committed, pinned dependency snapshot for Matplotlib, addressing #23548. In particular:

  • pyproject.toml defines the Pixi environment under [tool.pixi]
  • pixi.lock records the fully resolved dependency set
  • CI exercises that lockfile to verify that it can be used reproducibly

Why pyproject.toml

Pixi configuration is placed in pyproject.toml rather than a project-level pixi.toml.

The reasoning is:

  • pyproject.toml is already the canonical project configuration
  • it keeps the shared Pixi definition attached to the project itself
  • developers who want local customization can still create an untracked pixi.toml, which Pixi will prefer over pyproject.toml

This gives the project a canonical shared configuration while still allowing personal overrides.

Lockfile policy

A main goal of this PR is to commit a pinned dependency list, and pixi.lock is the mechanism used for that.

pixi.lock should therefore be treated as part of the repository state:

  • changes to Pixi dependency inputs should be accompanied by a regenerated pixi.lock
  • CI uses the lockfile to verify reproducibility
  • old commits retain the dependency snapshot that was current at that point in history

In that sense, pixi.lock is the committed pinned dependency snapshot for the project.

Developer workflow

Basic usage:

pixi install

pixi run python -m pip install \
  --no-build-isolation \
  --config-settings=setup-args="-Db_lto=false" \
  --editable .

After that, for example:

pixi run tests-core
pixi run build-doc

Dependency changes:

If dependencies change, then pixi.lock should be regenerated. It is ignored by default in .gitignore so developers who want to change pixi.lock will need to regenerate it, and force add it to a commit:

mv pixi.toml pixi.backup
pixi lock
git add -f pixi.lock

tools/pixi.example.toml

A template is provided for developers who want to customize their local Pixi setup.

For example:

cp tools/pixi.example.toml pixi.toml

This is intended for local experimentation or system-specific tuning. It is not the project's canonical Pixi configuration.


Key design decisions

Editable install is not managed directly by Pixi

This PR intentionally does not use:

    [pypi-dependencies]
    matplotlib = { path = ".", editable = true }

In testing, that led to lockfile instability (lock-file not up-to-date with the workspace), especially in CI.

Instead, responsibilities are split:

  • Pixi manages the environment and pinned dependencies
  • pip install -e . installs Matplotlib itself

This keeps pixi.lock stable while still supporting editable development installs.

Single environment

Although Pixi supports separate environments such as test and doc, this PR currently uses a single environment containing the relevant dependencies.

The main reason is developer convenience:

  • avoids repeated editable installs in separate environments
  • keeps the workflow simple
  • still allows the lockfile to capture the relevant dependency sets

This can be revisited later if stricter separation is desirable.

CI

This PR adds a minimal CI job that checks that the Pixi environment can be recreated from the committed lockfile.

At the moment the job is intentionally lightweight: it verifies that the lockfile works and that Matplotlib can be built/imported in that environment. It can be extended later to run tests and/or documentation builds.


Notes / future work

  • extend Pixi CI coverage to run more tests and build docs
  • decide whether additional environment separation is worthwhile
  • refine developer-facing documentation around local pixi.toml
    overrides

AI disclosure

I went back and forth w/ chatGPT quite a bot on how to organize this and the various tradeoffs. It also helped with writing this summary, which is of course long-winded, but hopefully complete.

@github-actions github-actions Bot added the Documentation: devdocs files in doc/devel label Mar 25, 2026
@jklymak jklymak changed the title Dev add pixi toml [DEV]: add tools/pixi.toml and doc how to have a development environment for pixi Mar 25, 2026
@jklymak
jklymak marked this pull request as ready for review March 25, 2026 23:41
@jklymak

jklymak commented Mar 26, 2026

Copy link
Copy Markdown
Member Author

.. I'm surprised the tests are running given I labelled this [ci doc]

Comment thread tools/pixi.toml Outdated
depends-on = ["clean-build", "dev-install"]
description = "Clean and rebuild editable install"

[tasks.install-test]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should make features for tests + docs.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes we could do it that way, but I'm not sure of the pros and cons. It did not seem there was a way to make conditional install dependencies so I wasn't sure the advantage of having separate feature envs for a developer versus just having one env.

Comment thread tools/pixi.toml Resolved
Comment thread tools/pixi.toml Outdated
description = "No-op on non-mac platforms"

[target.osx-arm64.tasks.prepare-freetype]
cmd = "cp subprojects/packagefiles/freetype-2.6.1-meson/src/gzip/zconf.h subprojects/freetype-2.6.1/src/gzip"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I also don't understand this, is something going wrong with unpacking the subproject? This seems like something we should be fixing in the meson files rather than here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I don't think it's a general problem, but it's definitely a problem on macOS with the version of zconf

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

OK< I think this was not necessary, as it now works fine without it.

@tacaswell

Copy link
Copy Markdown
Member

It is my understanding that if you have metadata about the build you are (or will soon be able) to point to a repo as a conda dependency and pixi-build will build the conda-package on the fly (the same way it does with pypi-deps). Given that we are going to want pixi.toml in the lop level eventually.

That said, I agree we do not want to check in the pixi.lock file.

@tacaswell

Copy link
Copy Markdown
Member

I mean add a section like

[pypi-dependencies]
matplotlib = { path = "..", editable = true }

@jklymak

jklymak commented Mar 26, 2026

Copy link
Copy Markdown
Member Author

Ah I see. No that didn't work as I don't think it's compatible with build isolation.

@jklymak

jklymak commented Mar 26, 2026

Copy link
Copy Markdown
Member Author

OK< my comment above was incorrect. The new pixi.toml has removed the font copying things, and uses

[pypi-dependencies]
matplotlib = { path = ".", editable = true }

which indeed seems to be fine.

Still not sure if we should run with features or just a separate install steps?

@jklymak
jklymak force-pushed the dev-add-pixi-toml branch from 7d73c47 to 27d86a1 Compare March 28, 2026 04:49
@jklymak
jklymak marked this pull request as draft March 28, 2026 04:58
@jklymak
jklymak force-pushed the dev-add-pixi-toml branch 2 times, most recently from aedf224 to 055029d Compare March 28, 2026 16:22
@jklymak jklymak changed the title [DEV]: add tools/pixi.toml and doc how to have a development environment for pixi [DEV]: add pixi.lock and add pixi to pyproject.toml Mar 28, 2026
@jklymak
jklymak force-pushed the dev-add-pixi-toml branch from 055029d to 85257fe Compare March 28, 2026 16:32
@jklymak
jklymak marked this pull request as ready for review March 28, 2026 16:50
@jklymak
jklymak requested a review from tacaswell March 28, 2026 19:51
@jklymak
jklymak force-pushed the dev-add-pixi-toml branch 3 times, most recently from a0a2ff5 to c0467de Compare March 30, 2026 17:51
@jklymak jklymak added the CI: testing CI configuration and testing label Mar 30, 2026
@jklymak
jklymak force-pushed the dev-add-pixi-toml branch from c0467de to f3e0de0 Compare March 30, 2026 18:09
Comment thread .github/workflows/pixi_tests.yml Resolved
Comment thread .github/workflows/pixi_tests.yml Resolved
Comment thread pyproject.toml Resolved
Comment thread .github/workflows/pixi_tests.yml Resolved
Comment thread .github/workflows/pixi_tests.yml Resolved
Comment thread doc/devel/development_setup.rst Resolved
Comment thread doc/devel/development_setup.rst Resolved
@jklymak
jklymak force-pushed the dev-add-pixi-toml branch from a40ae3f to 3ba6a65 Compare April 1, 2026 14:27
@tacaswell
tacaswell force-pushed the dev-add-pixi-toml branch from 176bf93 to d2bad08 Compare July 19, 2026 15:40
@github-actions github-actions Bot added CI: Run cibuildwheel Run wheel building tests on a PR and removed status: needs rebase labels Jul 19, 2026
Comment thread .github/workflows/pixi_tests.yml Fixed
Comment thread .github/workflows/pixi_tests.yml Fixed
@jklymak

jklymak commented Nov 26, 2026

Copy link
Copy Markdown
Member Author

@tacaswell feel free to take over ownership of this. I'm satisfying my own needs by just having a pixi.toml in a directory beside where matplotlib lives and installing from there, which I probably should have been doing even before I started using pixi.

I can still see use in using pixi and lock files to track package dependencies as they change.

@tacaswell

Copy link
Copy Markdown
Member

I've made some major changes to this PR. We are now able to use the pixi-build machinery to manage the editable install into the pixi environments (the 🦜 helped here). The workflow is now:

pixi run test
pixi run build-doc

and pixi takes care of everything!

There is a check to make sure we don't accidentally pick up pypi dependencies in them lock file.

We probably need to sort out how to implement a monthly job that runs pixi update to re-generate the pins.

@jklymak sorry for steamrolling you on this!

@timhoffm

Copy link
Copy Markdown
Member

I have a slight preference to keep pixi config in a separate pixi.toml. That reads much cleaner because the files are smaller and separates package configuration (pyproject.toml) from optional dev env configuration (pixi.toml). - At least that's the responsibilities as far as I see we want them now.

Also keys like [tool.pixi.package.build.config] hurt my eyes 😄.

Note: SciPy also maintains a dedicated pixi.toml

@tacaswell

Copy link
Copy Markdown
Member

I have a strong preference for a pixi.toml but opted to leave this as @jklymak set it up, I'm happy to move it.

@timhoffm

Copy link
Copy Markdown
Member

a pixi.toml also better seprates the conda / pypi package worlds. From a pixi.toml you don't get pypi packages unless explicitly state them in [pypi-dependencies]. So I think the check-no-pypi job is not needed with this.

@jklymak

jklymak commented Nov 26, 2026

Copy link
Copy Markdown
Member Author

As below, I'm definitely no expert, so please don't do what I did a few months ago!

My current set up is just to have a pixi.toml in another directory. That works well and including an example pixi.toml here for people to use makes sense to me. If we call itpick.toml or pixi.toml.template is not something I'm sure about.

jklymak and others added 3 commits November 26, 2026 19:44
…ci doc]

Apply suggestions from code review

Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
This as a squash of 30-40 commits from about 4 months of on-and-off work.
Squashed down to reduce the amount of thrashing in the history.  The main
highlights:

 - move all dependencies in the pixi.lock to by conda-only (there is a bug in
   the pypi <-> CF mapping tables for win-64 + py315, see
   https://github.com/prefix-dev/parselmouth#100) and add CI to check the
   pixi.lock is up-to-date and the tests run.
 - add the pixi-build metadata so that we can both use it internally (it does
   editable installs by default!) and so that we can add mpl as a conda-source
   install in other projects.  This eliminates the need for a manual
   build/install step.
 - add environments for all of the versions of Python that we support (except
   win-64 + py315 as noted above)
 - move pixi config -> pixi.toml .  The only remaining changes in the
   pyproject.toml is to sort the dependencies by name.

This is a mix of my work, 🦜 assistance, and work with Ruben Arts in person at
the scipy 2026 sprints.

Assisted-by: opencode:claude-auto
Assisted-by: opencode:claude-sonnet-4-5
Assisted-by: opencode:claude-opus-5-5

Co-authored-by: Ruben Arts <ruben.arts@hotmail.com>
@tacaswell

Copy link
Copy Markdown
Member

I do not understand the svg failures that are happening in the pip-based tests (which also seem to be happening on main). I thought I had fixed it by changing the cache key, but the failure came back.

I downloaded the failed images and the svgs for multi_font are identical other than the mpl version and date so something is clearly going wrong with the new conversion machinery.

@jklymak

jklymak commented Nov 27, 2026

Copy link
Copy Markdown
Member Author

Is it possible the expected svg.pngs are cached? I had that locally.

@timhoffm

Copy link
Copy Markdown
Member

We briefly talked about the SVG failures in the call yesterday. @QuLogic suspected caching as well.

@timhoffm

timhoffm commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

including an example pixi.toml here for people to use makes sense to me. If we call itpick.toml or pixi.toml.template is not something I'm sure about.

Why do we need a template? I haven’t seen the concept of a pixi template anywhere else. In my understanding we just provide a pixi.timl as our recommended way to work with pixi. People can always decide to do something different, but there should be little need, and it’s not something we have to build structure for.

@jklymak

jklymak commented Nov 27, 2026

Copy link
Copy Markdown
Member Author

I think just to differentiate what a developer may want from what we may want for CI runs. But for all I know those are identical.

@timhoffm

Copy link
Copy Markdown
Member

Yes those are typically identical. And if not, pixi supports multiple environments and tasks so that we can have dedicated parts for CI and local development if needed.


.. tab-item:: pixi environment

A `pixi`_ configuration is included in ``pyproject.toml`` that will

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
A `pixi`_ configuration is included in ``pyproject.toml`` that will
A `pixi`_ configuration is included in ``pixi.toml`` that will

Comment on lines +205 to +207
A `pixi`_ configuration is included in ``pyproject.toml`` that will
install the development dependencies and an editable version of
Matplotlib (built from your checkout)::

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
A `pixi`_ configuration is included in ``pyproject.toml`` that will
install the development dependencies and an editable version of
Matplotlib (built from your checkout)::
A `pixi`_ configuration is included in ``pixi.toml`` that provides
a complete development setup.
Optional: Do an explicit install to pre-build the development
environment (if you don't pixi does this as needed):


Compiled extensions are rebuilt automatically when you import
Matplotlib after changing the C++ sources. If you change the build
configuration (``pyproject.toml``, any ``meson.build`` file) ``pixi run``

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
configuration (``pyproject.toml``, any ``meson.build`` file) ``pixi run``
configuration (``pixi.toml``, any ``meson.build`` file) ``pixi run``

Comment on lines +243 to +275
In addition to the default environment, we include a number of specialized
environments and pinned to older versions of Python. Use
``pixi workspace environment list`` to see the full list. For older Pythons
the environment names have ``3XX` appended.

default
Tests and documentation dependencies.

test
Tests dependencies only.

test-extra
Additional dependencies to reduce the number of skipped tests.

doc
The documentation dependencies (but no test dependencies)

typing
Dependencies for running various testing.


For example to run the tests with extra dependencies with Python 3.14 use::

pixi run -e test-extra314 test

.. tip::

If you do not want to use ``pixi run`` in front of every command, run::

pixi shell [-e ENVIRONMENT]

which gives the same behavior as ``conda activate``.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm inclinded to leave this out. Ideally, a developer should not need more than the tasks. And if you are an expert, I think it's bearable that you look for the environments in pixi.toml directly.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI: Run cibuildwheel Run wheel building tests on a PR CI: testing CI configuration and testing Documentation: devdocs files in doc/devel status: needs rebase

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants