astral-sh / uv

An extremely fast Python package and project manager, written in Rust.
https://docs.astral.sh/uv
Apache License 2.0
28.1k stars 805 forks source link

Development Dependency Overrides #9258

Open iloveitaly opened 1 week ago

iloveitaly commented 1 week ago

One of the things I've always missed from ruby is development dependency overrides. Here's the situation:

Ruby allows you to do this with:

bundle config set local.rack ~/Work/git/rack

It would be great if uv provided similar sort of functionality.

charliermarsh commented 1 week ago

I believe this is possible today with:

[tool.uv]
override-dependencies = ["dependency @ file:///path/to/dependency"]
ReinforcedKnowledge commented 1 week ago

I think you can also run code with the --with option of uv run command, or --with-requirements if you have many. That won't modify the pyproject.toml and the code will only run in an ephemeral virtual environment.

iloveitaly commented 1 week ago

This is awesome. Will try this out and report back. Thanks for all of the help.

iloveitaly commented 5 days ago

This does not work:

override-dependencies = ["activemodel @ file://./pypi/activemodel"]

And results in the following error:

relative path without a working directory: ./pypi/activemodel

But an absolute path does work. Am I missing some obvious configuration option here?

Also, it looks like the package is not installed as editable. What's the best way to do that? It looks like this syntax should work, but it doesn't:

ReinforcedKnowledge commented 5 days ago

Hi!

I will let the experts say why it didn't work because I don't know.

Relative paths with override-dependencies aren't working for me either, but I generally don't expect relative paths to work in that fashion, they're always a hassle no matter the tool. If you want to avoid hardcoding the path you can use ${PROJECT_ROOT}, like

[tool.uv]
override-dependencies = ["activemodel @ file:///${PROJECT_ROOT}/pypi/activemodel"]

As for the editable install, there is no current way for specifying editable installs in an override-dependencies. But at the same time, I don't think that's what you need here.

Here's how you can use your local package as editable:

[tool.uv.sources]
activemodel = { path = "./pypi/activemodel", editable = true }

Sources in uv will always take precedence over version contraints.

As for why override-dependencies are not what you need, I think, from my modest beginner understanding of the tool, it's something that you'd use to override versions of transitive dependencies, or to force a particular version constraint in a way that no matter the current or the future resolutions of uv (due to a change in uv itself or in your dependencies), that package's version is going to stay the same.

I hope someone more knowledgeable can read this and correct it if I'm wrong.

zanieb commented 5 days ago

There's discussion about this same problem over in https://github.com/astral-sh/uv/issues/8148#issuecomment-2496127365 that may provide some more context.

ReinforcedKnowledge commented 5 days ago

Oh thanks! I'll read through the thread!

iloveitaly commented 5 days ago
[tool.uv.sources]
activemodel = { path = "./pypi/activemodel", editable = true }

This works for local development, but doesn't solve my problem:

  1. When developing locally, I want to use a local copy of the package
  2. In production, I want to reference a production package
  3. I don't want to have to keep a mutated copy of pyproject.toml locally to reference the local package

Ruby does this with:

bundle config set local.rack ~/Work/git/rack

Which does not involve mutating your Gemfile but enables you to easily debug a package with a local development override.

zanieb commented 5 days ago

We want to build a dedicated "patch" workflow, but we haven't designed that yet. Does using uv run --with-editable not work for you?

charliermarsh commented 4 days ago

You can run with --no-sources in production if you want to disable that local path.

iloveitaly commented 3 days ago

I wasn't aware of uv run --with-editable or --no-sources, let me try those out and report back.

iloveitaly commented 2 days ago

Can you specify either of these options with an ENV var?

I'm using nixpacks to build my containers and I'd rather not have to customize the install scripts and instead specify ENV configuration which uv can pick up.