pythondependency-managementpyproject.tomluv

How can I use a local Python package during development while keeping a Git dependency in pyproject.toml?


I'm developing two Python projects:

In yyy's pyproject.toml, I declare the dependency as:

[tool.uv.sources]
xxx = { git = "git+https://github.com/myuser/xxx.git" }

This works well for others who clone yyy — they get the correct version of xxx from GitHub. However during development, I want to use a local copy of xxx (e.g., ~/xxx) so I can test changes in yyy without pushing to GitHub each time.

I'd like a solution that:

Is there a clean way to override the Git-based dependency locally (perhaps with a .gitignored file or config), while keeping pyproject.toml untouched?

I'm using uv as my Python package manager.

Any best practices or workflows for this setup?


Solution

  • I think uv's --with-editable would help here.

    Let's assume you have xxx and yyy both cloned locally, to ~/xxx and ~/yyy respectively. Within ~/yyy you should find that:

    uv run --with-editable ../xxx python -c "import xxx; print(xxx)"
    

    will run in an environment in which your local clone of xxx is used. It won't touch yyy's pyproject.toml or uv.lock.

    This also works with longer dependency chains too; so if you have zzz depending on yyy depending on xxx, you can use --with-editable when running commands in zzz to test your local changes in xxx.

    Note that this isn't "sticky", in the sense that if you subsequently do a bare uv run python ... then you'll use the "proper" version of xxx rather than the local version again.