Open iloveitaly opened 1 week ago
I believe this is possible today with:
[tool.uv]
override-dependencies = ["dependency @ file:///path/to/dependency"]
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.
This is awesome. Will try this out and report back. Thanks for all of the help.
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:
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.
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.
Oh thanks! I'll read through the thread!
[tool.uv.sources]
activemodel = { path = "./pypi/activemodel", editable = true }
This works for local development, but doesn't solve my problem:
pyproject.toml
locally to reference the local packageRuby 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.
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?
You can run with --no-sources
in production if you want to disable that local path.
I wasn't aware of uv run --with-editable
or --no-sources
, let me try those out and report back.
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.
One of the things I've always missed from ruby is development dependency overrides. Here's the situation:
pyproject.toml
Ruby allows you to do this with:
It would be great if uv provided similar sort of functionality.