Skip to content

feat: add a uv backend to setup-env library mode - #4

Open
lkstrp wants to merge 2 commits into
PyPSA:mainfrom
lkstrp:add-a-uv-backend-1
Open

lkstrp wants to merge 2 commits into
PyPSA:mainfrom
lkstrp:add-a-uv-backend-1

Conversation

@lkstrp

@lkstrp lkstrp commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

I don't think it's a good idea to default to pixi everywhere. See comment below.

This PR allows to just follow the upstream package manager. uv for uv repos like PyPSA, pixi for repos like PyPSA-Eur. pixi is not used as second toolchain if not needed/ defined by the importing repository.

PyPSA/PyPSA#2197 (review)

I am quite against this. The overhead is not marginal. And in the evolving world leading to worktrees and sandboxes its a problem for nearly no benefit. See stats below.

Next to that, the CI is here no longer testing the built wheel. Also the master is not testing fresh dependencies anymore. With pixi.toml we have two sources of truth next to pyproject.toml...

My counter proposal is here: #4

| | uv | pixi | Δ |
|---|---|---|---|
| Cold setup (empty cache) | 37.0 s | 46.6 s | +26% |
| Warm setup (per worktree) | 2.1 s | 4.2 s | 2x |
| Re-sync, nothing changed | 113 ms | 212 ms | 2x |
| run overhead | 55 ms | 213 ms | 4x |
| Cache + Python | 1.5 GB | 2.0 GB | +33% |
| Per extra worktree | 6.5 MB | ~130 MB | ~20x |
| 3 worktrees total | ~1.7 GB | ~2.4 GB | +40% |

@codecov

codecov Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (32c3d98) to head (4947bbc).

Additional details and impacted files
@@            Coverage Diff            @@
##              main        #4   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            1         1           
  Lines            2         2           
=========================================
  Hits             2         2           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@brynpickering

Copy link
Copy Markdown
Collaborator

Using pixi even for uv projects ensures we create environments including non-python libs in a consistent way, which covers existing uv backend projects (linopy, atlite, ppm). The overhead w.r.t. worktrees isn't relevant to the CI, although I agree there are performance hits when using it locally (I'm happy to accept them so that I don't have to think about those non-python libs).

Another thing is that the CI workflows are doing things slightly differently. They actively install packages with uv after installing the pixi environment that sets python + non-python libs. So, in theory, you get the best of both worlds...

@lkstrp

lkstrp commented Nov 30, 2026

Copy link
Copy Markdown
Member Author

I would probably say in 6 months time, local dev environments are gone anyway and most of the work is in cloud/ remote/ containerized anyway and therefore you should aim for the lowest possible setup overhead. But if you are that much behind pixi, let's go. Better to have one system everywhere.

PyPSA/PyPSA#2197 has many more problems though, not just the overhead:

  • The build job is gone and every job installs pypsa editable from path, so we stop testing the wheel users get
  • Master and nightly no longer resolve fresh and everything is locked with the cooldown. A breakage from new releases of dependencies, which users notice immediately, will only show up via the monthly lockfile update. We can use that process for pypsa-eur where we only support the lockfile and nothing else, but not for framework libraries (any of them)
  • numpy/ pandas/ scipy come from conda-forge in CI, but from PyPI for users. pixi.toml also adds its own caps (numpy<=2.4.6 etc.) on top of pyproject.toml. Even if we switch to pixi, it should just read from pyproject.toml as the only manifest.

What about

  • pyproject.toml stays the only manifest for all pip based repos, including linopy, atlite...
  • The dev/test/docs extras move to [dependency-groups]. pixi reads those and [project.dependencies] directly and turns the groups into envs
  • A small [tool.pixi] table in pyproject.toml only holds the workspace config, tasks and conda-only binaries (e.g. cairo for the docs). Never python packages and no pins
  • Local dev works both ways from that one file, pixi run -e dev pytest or uv sync --group dev. We can go with pixi as the default in the docs
  • CI tests use a library mode which builds the wheel and installs it with uv, locked on PRs, fresh on master and nightly. Any non-python binaries come from conda via pixi-add. No more brew or whatever anywhere
  • Project mode with the full pixi lockfile stays for pypsa-eur and other models

I think you only lose

  • pixi.lock, there is just a single lock file uv.lock
  • CI tests are not the same as local dev, but the same as what users install (wheel instead of editable)
  • Therefore pixi run ci locally is not exactly what the CI test jobs run. Jobs that don't test the wheel (lint, typecheck, docs) could still call pixi tasks directly if we want

Let me know if this is a good compromise and I should adapt the PR

@brynpickering

Copy link
Copy Markdown
Collaborator

@lkstrp that seems reasonable. If it removes the overhead you've identified then I'm all good with that!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants