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

Defer finding uv binary to shutil #4576

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

ulucs
Copy link

@ulucs ulucs commented Jun 27, 2024

Summary

Currently the find_uv_binary function searches some amount of pre-defined locations. Finding the binary itself can be achieved in a simpler way by deferring the logic to shutil.which, which does the following for us for free:

  • handle exe extension logic in Windows
  • search user/system-installed paths
  • search virtualenv paths

In addition, leaving the location logic to PATH and shutil.which has the additional advantage of being compatible with tools that expose binaries via PATH (ie Nix), and any other package managers that work in ways we don't expect

Test Plan

No new functions -- previously written tests should cover correctness. Marked as Draft until all tests pass

@ulucs ulucs marked this pull request as ready for review June 27, 2024 09:41
@zanieb
Copy link
Member

zanieb commented Jun 27, 2024

Hi! I don't think we want this behavior - it's only the intent of the script to find the uv binary associated with the Python module not another one on the system. If people want to find any uv binary, yeah which is a good option to call directly. See the discussion at #4451 for more context.

Perhaps we just need to clarify the documentation here instead.

@ulucs
Copy link
Author

ulucs commented Jun 27, 2024

All good! Is there any interest in configuring uv to play well with Nix? One other option is to do something similar to

import os

def up(file_path, times = 1):
    for i in range(times):
        file_path = os.path.dirname(file_path)
    return file_path

os.path.join(up(__file__, 5), "bin", "uv")

in order to target $ROOT/bin/uv from $ROOT/lib/pythonXX/site-packages/uv/__init__.py. The current approach is targeting $ROOT/lib/pythonXX/site-packages/bin/uv which is something I'm not sure exists

@zanieb
Copy link
Member

zanieb commented Jun 27, 2024

It'd be nice to support Nix but I don't think it makes sense for us to scan in arbitrary locations (i.e. up five levels) for the bin. Why doesn't Nix use one of the Python standard locations for the executable?

@ulucs
Copy link
Author

ulucs commented Jun 27, 2024

It does do that, by initializing the library root at nix/store/$(derivation-hash)-$(python+ver)-$(package+ver), putting the binaries at $ROOT/bin and the library files at $ROOT/lib/pythonXX/site-packages

The problems for this case start when Python allows package location declarations via site and PYTHONPATH and disregards the binary paths. The previous version of this file had the same problem with pip install --target too, which was then solved by looking 2 directories up

@ulucs
Copy link
Author

ulucs commented Jul 1, 2024

Hello! Following up.

Is there any interest in supporting the python library being pulled in via PYTHONPATH? Or is that considered to be an unsupported use-case?

@zanieb
Copy link
Member

zanieb commented Jul 3, 2024

Hi! Sorry I'm not entirely understanding what you're proposing now. Can you clarify?

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

Successfully merging this pull request may close these issues.

None yet

2 participants