Skip to content

Allow automatically reinstalling path-based PyPI packages when files change #3985

Description

@silversquirl

Problem description

When using pixi to manage the build environment for a pypi package, it is useful to be able to automatically reinstall the package into its own environment whenever source files are updated.
This isn't as important for pure-python packages, which can get by using editable = true, but this isn't sufficient for packages that need complex build steps, like those involving extension modules.

A simple way to solve this problem would be to add a property to pypi packages specifying a list of files to watch for changes, similar to task inputs and uv's cache-keys.

Example:

[pypi-packages]
my-test-package = { path = ".", rebuild-if-changed = ["src/*.cpp"] }

In this example, if any changes were detected in src/*.cpp, the package would be treated as outdated and be reinstalled automatically whenever the environment is checked (eg. before a pixi run or pixi shell command), as if you had run pixi reinstall my-test-package

It is possible to approximate this behaviour today, using a task:

[tasks]
build = { cmd = "pixi reinstall my-test-package", inputs = ["src/*.cpp"] }
test = { cmd = "pytest", depends-on = ["build"] }

However, this has two major problems:

  1. it must be specified explicitly as a dependency of every other task, and doesn't work correctly for things like pixi shell or pixi run python.
  2. in the event of modifications to the pixi.toml, it will rebuild the environment twice - once prior to running the build task, and once when the build task is run.

Another approach is to use activation hooks, however:

  1. this requires writing a separate script, since pixi can't run tasks from activation hooks
  2. this requires writing caching behaviour manually, for the same reason. it's not possible to simply write a script that runs pixi run build, because that recurses infinitely and there doesn't seem to be a way to temporarily disable activation hooks
  3. as with the task-based workaround above, this approach can result in rebuilding the package multiple times

Activity

  1. silversquirl commented on Jun 20, 2025

    @silversquirl
    Author

    I've come up with this workaround for now:

    [tasks]
    test = { cmd = "pytest", depends-on = ["setup-install"] }
    setup-install.cmd = "uv pip install --no-build-isolation -C editable.rebuild=true -C build-dir=build -e ."
    setup-install.inputs = ["pyproject.toml"] # Just need something in here so it caches; scikit-build-core will handle the actual caching

    It's similar to the task-based approach using pixi rebuild above, but it uses uv (pip would work fine too) to build and install the package manually, rather than relying on pixi to do so.
    This only works because of scikit-build-core's automatic rebuild feature, which is still experimental. It'd still be nice to properly support this sort of thing in pixi natively.

  2. lucascolley commented on Jun 21, 2025

    @lucascolley
    Member

    relevant discussion in the particular case of meson-python and uv at astral-sh/uv#10214 and mesonbuild/meson-python#730

  3. tdejager commented on Jul 8, 2025

    @tdejager
    Contributor

    This is a feature we are aiming for with pixi build, however, we could think of something for PyPI at some point as well. The focus would be the pixi build use-case first though :)

  4. cpcloud commented on Sep 15, 2025

    @cpcloud

    I would love to see this. I just hit this issue going between branches with different Cython code and was very surprised to see no rebuild happen.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions