astral-sh / uv

An extremely fast Python package and project manager, written in Rust.
https://docs.astral.sh/uv
Apache License 2.0
24.77k stars 715 forks source link

Remove (or ensure) git system requirement #4847

Open wyattscarpenter opened 3 months ago

wyattscarpenter commented 3 months ago

As far as I can tell, Git is required to be installed on the host system in order for pip git sources to work. This is bad, from a software engineering perspective, because a program should not require other programs in order to work. It is also bad because when you install uv using pip, you do not get git as well (which would be another way of avoiding the dependency failure).

This behavior is understandable, because pip also works like this, but unless using the git executable as pip would is crucial for compatibility reasons, I think uv should just support the git operations itself (and also, I guess, the Mercurial, Subversion, and Bazaar operations, detailed on https://pip.pypa.io/en/stable/topics/vcs-support/). As I understand it, the required operations are basically just downloading and unpacking the repo, so it shouldn't be that hard™.

Example

$ pip install -U uv #this doesn't install git or anything.
# (I've omitted the output of this command for brevity.)

$ uv --version
uv 0.2.21 (ebfe6d8fc 2024-07-03)

$ echo "mypy\nblack @ git+https://github.com/psf/black" >requirements.txt

$ uv venv && uv pip install -r requirements.txt
Using Python 3.12.3 interpreter at: [redacted]
Creating virtualenv at: .venv
Activate with: .venv\Scripts\activate
Updating https://github.com/psf/black (HEAD)                                                                            error: Failed to download and build: `black @ git+https://github.com/psf/black`
  Caused by: Git operation failed
  Caused by: could not execute process `git init` (never executed)
  Caused by: program not found

$ uv venv && uv pip install -r requirements.txt #switching to a machine where git is installed and on the path, for comparison, and it works fine
Using Python 3.10.12 interpreter at: /usr/bin/python3
Creating virtualenv at: .venv
Activate with: source .venv/bin/activate
 Updated https://github.com/psf/black (7e2afc9)                                                                                                                                                                                              Resolved 9 packages in 29.34s
   Built black @ git+https://github.com/psf/black@7e2afc9bfdc4ec4bc3297aaa16a62d575249a5e0                                                                                                                                                   Downloaded 1 package in 7.92s
Installed 9 packages in 1m 40s
 + black==24.4.3.dev23+g7e2afc9 (from git+https://github.com/psf/black@7e2afc9bfdc4ec4bc3297aaa16a62d575249a5e0)
 + click==8.1.7
 + mypy==1.10.1
 + mypy-extensions==1.0.0
 + packaging==24.1
 + pathspec==0.12.1
 + platformdirs==4.2.2
 + tomli==2.0.1
 + typing-extensions==4.12.2
FishAlchemist commented 3 months ago

I was under the impression that this PR(https://github.com/astral-sh/uv/pull/3833) remove embedded Git support. You should be able to understand the Git issue from the description of that PR.

charliermarsh commented 3 months ago

We may eventually move to gitoxide if it grows to fit our needs, but otherwise this is sort of a non-goal right now.

zanieb commented 3 months ago

Our git operations are definitely non-trivial too as we need to support resolving all sorts of references, various authentication schemes, and optimizations like sparse checkouts. Once a suitable library is available we could consider support again but the system git client gives the most complete set of functionality.

Henkhogan commented 2 weeks ago

I am confused about the README of uv saying

uv's Git implementation is based on Cargo.

and then cargo's README

Optional system libraries:

The build will automatically use vendored versions of the following libraries. However, if they are provided by the system and can be found with pkg-config, then the system libraries will be used instead:

libcurl — Used for network transfers. libgit2 — Used for fetching git dependencies. libssh2 — Used for SSH access to git repositories. libz (aka zlib) — Used for data compression. It is recommended to use the vendored versions as they are the versions that are tested to work with Cargo.

Thus I expected there would be no need to have git installed

zanieb commented 2 weeks ago

We don't use libgit2 anymore, it doesn't support enough functionality. Originally, we copied much of Cargo's implementation though — Cargo can fallback to git if you ask it to.