Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development Dependency Overrides #9258

Open
iloveitaly opened this issue Nov 20, 2024 · 16 comments
Open

Development Dependency Overrides #9258

iloveitaly opened this issue Nov 20, 2024 · 16 comments
Labels
question Asking for clarification or support

Comments

@iloveitaly
Copy link

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

  • You have a dependency in one of your projects that is published on pypi
  • Something is broken in it. You clone it with hopes of fixing it locally before getting the patch merged upstream.
  • You want to temporarily override the pypi reference to point to a path on your local filesystem without modifying pyproject.toml

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
Copy link
Member

I believe this is possible today with:

[tool.uv]
override-dependencies = ["dependency @ file:///path/to/dependency"]

@charliermarsh charliermarsh added the question Asking for clarification or support label Nov 20, 2024
@ReinforcedKnowledge
Copy link
Contributor

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
Copy link
Author

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

@iloveitaly
Copy link
Author

iloveitaly commented Nov 25, 2024

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
Copy link
Contributor

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
Copy link
Member

zanieb commented Nov 26, 2024

There's discussion about this same problem over in #8148 (comment) that may provide some more context.

@ReinforcedKnowledge
Copy link
Contributor

Oh thanks! I'll read through the thread!

@iloveitaly
Copy link
Author

iloveitaly commented Nov 26, 2024

[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
Copy link
Member

zanieb commented Nov 26, 2024

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
Copy link
Member

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

@iloveitaly
Copy link
Author

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

@iloveitaly
Copy link
Author

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.

@rpmcginty
Copy link

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?

@zanieb is there an issue tracking this, or is it too early?

@zanieb
Copy link
Member

zanieb commented Jan 13, 2025

It's sort of tracked in #7454

I'm doing some roadmap work and will post here / there if I create a dedicated issue.

@iloveitaly
Copy link
Author

I've been iterating on a script which is working well for me:

https://github.com/iloveitaly/uv-development-toggle

@Avasam
Copy link
Contributor

Avasam commented Mar 7, 2025

I'd like to keep as much as possible compatible with pip, the following doesn't solve the problem I outlined in #9683 (comment)

[dependency-groups]
dev = [
    "ts_utils @ file:lib", # pip compatible
]

[tool.uv]
override-dependencies = [
  "ts_utils @ file:${PROJECT_ROOT}/lib", # uv won't accept relative paths
]
  × Failed to build `typeshed @ file:///E:/Users/Avasam/Documents/Git/typeshed`
  ├─▶ Failed to parse entry in group `dev`: `ts_utils @ file:lib`
  ╰─▶ relative path without a working directory: lib
      ts_utils @ file:lib

uv 0.6.5 (bcbcd0a1e 2025-03-06)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Asking for clarification or support
Projects
None yet
Development

No branches or pull requests

6 participants