rhozzy
rhozzy

Reputation: 352

Share Environment with uv that has private git dependencies

I am trying out the uv package in python for the first time. One of the key issues I'm concerned with is being able to share my virtual environment to other colleagues. So, up to this point I can successfully do the following via the CLI:

uv init <project name> --python 3.12
cd <project name>
uv add pandas numpy scikit-learn <etc. etc.>

Then, I can successfully create a new project (via uv init <new project name>) and add in the same dependencies from the original project via uv add ..\<original project name>. So far, so good.

The problem I'm running into is when I want packages that I add using uv that come directly from a private Github or Bitbucket repo. In this case, to add the package(s) to my virtual environment, I need to provide a username and token (e.g., uv add git+https://<username>:<token>@bitbucket.org/<repo>). But, when I then try to share this virtual environment with a new project (or, in reality, a colleague who would need to use their own credentials) using uv add ..\<original project name>, uv is unable to download and build the private repo package. I'm getting the following error:

Updating https://bitbucket.org/<repo> (HEAD)
error: Failed to download and build: `<repo name> @ git+https://bitbucket.org/<repo>`
Caused by: Git operation failed
Caused by: failed to fetch into: C:\Users\<username>\AppData\Local\uv\<other path info>
Caused by: process didn't exit successfully: `git fetch --force --update-head-ok https://bitbucket.org/<repo> +HEAD:refs/remotes/origin/HEAD` (exit code: 128)
--- stderr
fatal: ArgumentException encountered.
Illegal characters in path.
bash: /dev/tty: No such device or address
error: failed to execute prompt script (exit code 1)
fatal: could not read Username for 'https://bitbucket.org': No such file or directory

So, is this just an issue of having the credentials stored and accessible somehow for when uv attempts to build such a repo, or does this sort of package sharing via uv just not work right now? Thanks in advance.

Upvotes: 0

Views: 985

Answers (1)

julienla
julienla

Reputation: 23

I was encountering the same problem. I want to dockerize some python app that uses uv. This app is using another package from our private company GitLab repo.

This issue put me on the right track: https://github.com/astral-sh/uv/issues/7453

The current answer of uv's authors is:

We intentionally do not store any credentials in plaintext files by default. You should be able to re-add them to the pyproject.toml if you actually want them to be persisted in plaintext.

So adding them afterwards manually works.

I tested it on my side and it worked fine.

As the storing of credentials is by design a bad practice, my current approach is to replace them on the fly using sed and environment variables while building my Docker image.

Upvotes: 0

Related Questions