@@ -2,7 +2,18 @@ GitLab Package Registry
22=======================
33
44You can also publish your distribution packages in the package registry of your
5- GitLab project and use them with both :term: `Pip ` and :term: `twine `.
5+ GitLab project. However, the following conditions must be met:
6+
7+ * You must `authenticate
8+ <https://docs.gitlab.com/ee/user/packages/pypi_repository/?tab=With+a+deploy+token#authenticate-with-the-gitlab-package-registry> `_
9+ yourself when registering the package.
10+ * Your `version information
11+ <https://docs.gitlab.com/ee/user/packages/pypi_repository/?tab=With+a+deploy+token#use-valid-version-strings> `_
12+ must be valid.
13+ * The package must be smaller than 5 GB and the description must not be longer than 4000 characters.
14+ * The package has not yet been published in the package registry. Attempting to publish the same version of a package will return ``400 Bad Request ``.
15+
16+ You can then use the package with both :term: `pip ` and :term: `uv `.
617
718.. seealso ::
819 `PyPI packages in the Package Registry
@@ -14,6 +25,53 @@ Authentication
1425To authenticate to the GitLab Package Registry, you can use one of the following
1526methods:
1627
28+ * a `personal access token
29+ <https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html> `_ with
30+ the scope ``api ``.
31+ * a `deploy token
32+ <https://docs.gitlab.com/ee/user/project/deploy_tokens/index.html> `_ with the
33+ scopes ``read_package_registry ``, ``write_package_registry `` or both.
34+ * a `CI job token <https://docs.gitlab.com/ee/ci/jobs/ci_job_token.html >`_.
35+
36+ .. tab :: personal access token
37+
38+ .. code-block :: yaml
39+ :caption : .gitlab-ci.yml
40+ :emphasize-lines : 5-6
41+
42+ variables :
43+ UV_VERSION : 0.5
44+ PYTHON_VERSION : 3.12
45+ BASE_LAYER : bookworm-slim
46+ UV_PUBLISH_USERNAME : <personal_access_token_name>
47+ UV_PUBLISH_PASSWORD : <personal_access_token>
48+
49+ .. tab :: deploy token
50+
51+ .. code-block :: yaml
52+ :caption : .gitlab-ci.yml
53+ :emphasize-lines : 5-6
54+
55+ variables :
56+ UV_VERSION : 0.5
57+ PYTHON_VERSION : 3.12
58+ BASE_LAYER : bookworm-slim
59+ UV_PUBLISH_USERNAME : <deploy_token_username>
60+ UV_PUBLISH_PASSWORD : <deploy_token>
61+
62+ .. tab :: job token
63+
64+ .. code-block :: yaml
65+ :caption : .gitlab-ci.yml
66+ :emphasize-lines : 5-6
67+
68+ variables :
69+ UV_VERSION : 0.5
70+ PYTHON_VERSION : 3.12
71+ BASE_LAYER : bookworm-slim
72+ UV_PUBLISH_USERNAME : <gitlab-ci-token>
73+ UV_PUBLISH_PASSWORD : $CI_JOB_TOKEN
74+
1775 * A :ref: `personal access token <personal-access-tokens >` with the scope
1876 ``api ``.
1977* A :ref: `deploy token <deploy-tokens >` with the scopes
@@ -85,16 +143,30 @@ Use the :samp:`{GROUP_URL}` instead of the :samp:`{PROJECT_ID}`.
85143Publishing the distribution package
86144-----------------------------------
87145
88- You can publish your package with the help of :term: ` twine ` :
146+ Now you can publish your package on GitLab with :
89147
90- .. code-block :: console
91-
92- $ uv run twine upload -r gitlab dist/*
148+ .. code-block :: yaml
149+ :caption : .gitlab-ci.yml
150+
151+ …
152+ stages :
153+ - publish
154+ uv :
155+ stage : publish
156+ image : ghcr.io/astral-sh/uv:$UV_VERSION-python$PYTHON_VERSION-$BASE_LAYER
157+ script :
158+ - uv build
159+ - uv publish --publish-url ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/pypi dist/*
160+
161+ .. tip ::
162+ If necessary, you can use ``RUST_LOG=uv=trace `` to obtain further information
163+ on the authentication attempts, for example with ``RUST_LOG=uv=trace uv
164+ --verbose publish --publish-url
165+ ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/pypi dist/* ``.
93166
94- .. note ::
95- If you try to publish a package that already exists with the same name and
96- version, you will get the error ``400 Bad Request ``; you will have to delete
97- the existing package first.
167+ .. seealso ::
168+ In :ref: `uv-gitlab ` you will find further instructions on how to configure
169+ the :file: `.gitlab-ci.yml ` file.
98170
99171Installing the package
100172----------------------
@@ -103,13 +175,13 @@ You can install the latest version of your package for example with
103175
104176.. code-block :: console
105177
106- uv add -i https://{NAME}:{PERSONAL_ACCESS_TOKEN}@ce.cusy.io/api/v4/projects/{PROJECT_ID}/packages/pypi/simple --no-deps {PACKAGE_NAME}
178+ $ uv add -i https://{NAME}:{PERSONAL_ACCESS_TOKEN}@ce.cusy.io/api/v4/projects/{PROJECT_ID}/packages/pypi/simple --no-deps {PACKAGE_NAME}
107179
108180 … or from the group level with
109181
110182.. code-block :: console
111183
112- uv add -i https://{NAME}:{PERSONAL_ACCESS_TOKEN}@ce.cusy.io/api/v4/groups/{GROUP_ID}/-/packages/pypi/simple --no-deps {PACKAGE_NAME}
184+ $ uv add -i https://{NAME}:{PERSONAL_ACCESS_TOKEN}@ce.cusy.io/api/v4/groups/{GROUP_ID}/-/packages/pypi/simple --no-deps {PACKAGE_NAME}
113185
114186 … or in the :file: `pyproject.toml ` file with
115187
0 commit comments