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

Support for uv.sources #151

Open
bravhek opened this issue Jan 8, 2025 · 11 comments
Open

Support for uv.sources #151

bravhek opened this issue Jan 8, 2025 · 11 comments
Assignees
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@bravhek
Copy link

bravhek commented Jan 8, 2025

What's the problem this feature will solve?

Resolve dependencies from non pypi sources like GitHub repos.

Describe the solution you'd like

Use uv's project dependency resolution. If a dependency has been declared in [tool.uv.project] resolve from that source instead of pypi (name colition)

@bravhek bravhek added the enhancement New feature or request label Jan 8, 2025
@gaborbernat
Copy link
Member

PR welcome... but I don't plan adding this myself.

@gaborbernat gaborbernat added the help wanted Extra attention is needed label Jan 10, 2025
@paveldikov
Copy link
Contributor

I am interested in this feature and am happy to contribute but I think I could use some architectural debate/guidance.

To me it appears that root cause here is that uv.sources only kicks in when a package is being installed direct from pyproject.toml which is not what tox does. Rather it:

  1. builds project (sdist -> wheel)
  2. installs project dependencies
  3. installs built wheel without dependencies

in separate stages, as opposed to doing a singular uv pip install {toxinidir} command.
Therefore uv's handling of sources simply does not kick in.

Coalescing into a single install stage/command would probably be very involved brain-surgery and probably break the tox model. Alternatively we could parse pyproject.toml and try to emulate uv's handling of sources, but that sounds architecturally icky.

Ideally I'd be able to force-feed a pyproject.toml as a configuration item to a uv command (without actually installing it - or having to convert to uv.toml schema) and then the source specification should natively kick in?

cc @charliermarsh in case there is a more elegant way of going about this

@gaborbernat
Copy link
Member

Coalescing into a single install stage/command would probably be very involved brain-surgery and probably break the tox model. Alternatively we could parse pyproject.toml and try to emulate uv's handling of sources, but that sounds architecturally icky.

IMHO this is the path ahead.

@paveldikov
Copy link
Contributor

Assuming you meant the former, this is interesting and I didn't expect that to be your preference!

It does make things easier, but means that there will be lots of no-op stages i.e..pkg and install_package_deps will have to be overridden into no-ops because install_package does it all in one fell swoop.

TBH this isn't unique to uv as pip install . does the same isolated-build-then-install dance in modern versions of pip. Maybe that could be a more general architectural simplification in tox although it is a much bigger bite than I can chew ATM!

@gaborbernat
Copy link
Member

Overriding those steps with no-ops is fine and the expected decision.

@mrmathematica
Copy link

I give this a try: tox install dependencies at the very begining of venv creation, at https://github.com/tox-dev/tox/blob/main/src/tox/tox_env/python/runner.py#L97-L115 . install_package_deps and install_package happens very late in the process, around https://github.com/tox-dev/tox/blob/main/src/tox/tox_env/python/pip/pip_install.py#L219-L225.

So for now I can only think of calling uv pip install at the very begining, by override PythonRun._setup_env()`. Otherwise I will definitely get dependency not meet error. And I can turn all the later stages into no-op, or should leave some along?

@gaborbernat
Copy link
Member

You're looking in the wrong codebase. All the uv stuff is in this repository.

@mrmathematica
Copy link

Right. I only referenced tox because most metheds here is not orerrided in tox-ux. Anyway I created mrmathematica@2adbc00 that aims to demo doing a singular uv pip install {toxinidir} command. Not complete code. Could you please advice on whether this is the correct direction? Also I find it trick to render .pkg no-op, as that seems to break things.

@gaborbernat
Copy link
Member

gaborbernat commented Feb 7, 2025

Well depends, the lock run environment doesn't inherit from Python e.g. https://github.com/tox-dev/tox-uv/blob/main/src/tox_uv/_run_lock.py#L19 so does not apply. For the non lock variant while we do extend from the Python https://github.com/tox-dev/tox-uv/blob/main/src/tox_uv/_run.py#L15, we do override the installer https://github.com/tox-dev/tox-uv/blob/main/src/tox_uv/_venv.py#L110 so the pip installer does not apply in either case that you linked.

Not sure what you're trying to do in that commit, makes no sense to me 🤔 Perhaps take a step back and first explain what problem you are trying to solve, what functionality change you're proposing for it, before you start implementation.

@mrmathematica
Copy link

OK. I debug a few tox run and see that

https://github.com/tox-dev/tox/blob/main/src/tox/tox_env/python/runner.py#L99-L100 these two function calls install package dependencies and dependency_groups at venv creation.

https://github.com/tox-dev/tox/blob/main/src/tox/tox_env/python/pip/pip_install.py#L227 this function is actually called to execute pip or uv pip where of_type tells the stage.

Neither function is overrided in tox-uv.

So I was trying to call uv pip install at the very first stage.

@gaborbernat
Copy link
Member

Not sure what you're trying to do in that commit, makes no sense to me 🤔 Perhaps take a step back and first explain what problem you are trying to solve, what functionality change you're proposing for it, before you start implementation.

This. Step away from the code and focus on high level functionality first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants