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

How to Use uv for Publishing a Package to Private GitLab and Install from It #8352

Closed
the-korean-coder opened this issue Oct 19, 2024 · 5 comments
Labels
question Asking for clarification or support

Comments

@the-korean-coder
Copy link

Hi,

I'm looking for guidance on how to:

  • Publish a Python package to a private GitLab repo using uv.
  • Install the package from the private GitLab repo in another project.
    Thanks!
@FishAlchemist
Copy link
Contributor

FishAlchemist commented Oct 19, 2024

Q1: Publish a Python package to a private GitLab repo using uv.

After I created the deploy tokens, setting UV_PUBLISH_URLUV_PUBLISH_USERNAME and UV_PUBLISH_PASSWORD, then uv publish
https://docs.gitlab.com/ee/user/project/deploy_tokens/
https://docs.astral.sh/uv/guides/publish/#publishing-your-package

Q2: Install the package from the private GitLab repo in another project.

For Q2, you should be able to find the answer in the GitLab documentation.
https://docs.gitlab.com/ee/user/packages/pypi_repository/

As for Q1, you can refer to it as well since they are quite similar.

Note: Currently, UV does not support .pypirc. #7676

Uploading packages locally is done this way for me, but it seems unnecessary to apply for Deploy tokens when uploading packages from GitLab CI/CD.

@the-korean-coder
Copy link
Author

Thanks, i was able to publish my packages.
Now, how do I add this package to an uv project using uv add? What would the exact syntax or command be for that?

@FishAlchemist
Copy link
Contributor

Thanks, i was able to publish my packages. Now, how do I add this package to an uv project using uv add? What would the exact syntax or command be for that?

I haven't used any PyPI packages that require authentication. However, UV usually implements PEPs (Python Enhancement Proposals) and doesn't always introduce non-standard behaviors. Therefore, formats that pip can parse often only require minor modifications to work with UV.

@zanieb zanieb added the question Asking for clarification or support label Oct 24, 2024
@konstin
Copy link
Member

konstin commented Nov 3, 2024

I think this has been sufficiently answered.

@konstin konstin closed this as completed Nov 3, 2024
@timotk
Copy link

timotk commented Dec 18, 2024

I had the same issue (with publishing), and it still took me some time to figure it out. So I wrote a blog post about it.

Basically it boils down to the following .gitlab-ci.yml:

stages:  
  - publish  

variables:  
  PYTHON_VERSION: "3.13"  
  UV_VERSION: "0.5.5"
  UV_PUBLISH_URL: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/pypi"  
  UV_PUBLISH_USERNAME: "gitlab-ci-token"  
  UV_PUBLISH_PASSWORD: "${CI_JOB_TOKEN}"  

before_script:  
  - pip install uv==${UV_VERSION}

publish:  
  stage: publish  
  image: python:${PYTHON_VERSION}
  script:  
    # Set the version in pyproject.toml to the current git tag  
    - VERSION=$(git describe --exact-match --tags)  
    - uvx --from=toml-cli toml set --toml-path=pyproject.toml project.version $VERSION  
    # Build and publish the package  
    - uv build  
    - uv publish dist/*.whl  
  only:
    - tags
  • Gitlab provides the current Gitlab instance url (${CI_API_V4_URL}) and a token (${CI_JOB_TOKEN}).
  • uv picks up the environment variables and uses those as credentials. This is a little bit easier to read then putting them in the command itself.
  • I had to apply this trick for versioning since uv does not do dynamic versioning (yet).

Hope this helps.

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

No branches or pull requests

5 participants