ERROR: Could not find a version that satisfies the requirement PACKAGE (from versions: none)
I have created a PyPI job in my CICD pipeline that uses build
and twine
to do the building and publishing of the package to a private repository (hosted by the same GitLab instance the pipeline and repo are part of).
First I had to find out that the integrated git
support is somewhat lacking when it comes to support for submodules. The documentation is also rather vague. After doing some research online and experimenting I came up with the following solution:
.git_vars:
variables:
# Manually handle the submodule strategy (see build-pypi-pkg)
GIT_SUBMODULE_STRATEGY: none
GIT_STRATEGY: clone
stages:
- build
build-pypi-pkg:
stage: build
image: python:latest
variables: !reference [.git_vars, variables]
before_script:
- git config --global credential.helper store
- echo "https://${CI_REGISTRY_USER}:${CI_JOB_TOKEN}@gitlab.example.com" > ~/.git-credentials
- echo Synchronizing and updating submodules
- git submodule sync --recursive
- git submodule update --init --recursive
script:
- echo Installing Twine for publishing PyPI package
- pip install build twine
- echo Building PyPI packages
- |
#!/bin/bash
for i in `git submodule foreach --quiet 'echo "$name"'`
do
echo "Building PyPI package for submodule '$i'"
python -m build "components/$i"
done
- echo Publishing packages in ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/pypi
- |
#!/bin/bash
for i in `git submodule foreach --quiet 'echo "$name"'`
do
echo "Publishing PyPI package '$i'"
TWINE_PASSWORD=${CI_JOB_TOKEN} TWINE_USERNAME=gitlab-ci-token python -m twine upload --verbose --repository-url ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/pypi "components/$i/dist/*"
done
The gitlab-ci.yml
is part of a repo that adds CICD-driven automatic packaging by simply adding the different repos (each with its own setup.py
) and packaging them separately.
Everything builds fine and one can download e.g. the .whl
file for each submodule from the registry and use pip to install it. H
However, I have a problem using pip install
with the --index-url
that is also given in the package description inside the registry. The following call
pip install my-package --index-url https://__token__:XXXXXXXXXXXXXXX@gitlab.example.com/api/v4/projects/46960/packages/pypi/simple
results in the following error:
Looking in indexes: https://__token__:****@gitlab.example.com/api/v4/projects/46960/packages/pypi/simple
ERROR: Could not find a version that satisfies the requirement my-package (from versions: none)
ERROR: No matching distribution found for my-package
The access token I am using is a valid personal access token (my guess is that if the above command was executed inside a job I could also use gitlab-ci-token
/CI_JOB_TOKEN
as a username/password) and the error does not indicated a credentials issue at all.
The version is available inside the setup.py
(each repo is using the same tools, here setuptools.setup
to define the package). I also tried specifying a version for the package (here my-package==0.5.2
), which can also be seen in the package repository entry for this package.