bug: pypirc file does not get the environment variables parsed correctly as mentioned in docs
I had asked @sabrams here (#202012 (comment 573155029)) about this. The documentation phrasing currently stands as
You can also use
CI_JOB_TOKENin a~/.pypircfile that you check into GitLab:[distutils] index-servers = gitlab [gitlab] repository = https://gitlab.com/api/v4/projects/${env.CI_PROJECT_ID}/packages/pypi username = gitlab-ci-token password = ${env.CI_JOB_TOKEN}
I tried to commit a .pypirc file to the top-level of the repository, but the CI job would fail with
$ python -m twine upload --config-file .pypirc --repository gitlab dist/*
Uploading distributions to https://gitlab.cern.ch/api/v4/projects/${env.CI_PROJECT_ID}/packages/pypi
Uploading labRemote-1.1.dev356+g656b25c-cp36-cp36m-manylinux2010_i686.whl
100%|██████████| 2.07M/2.07M [00:00<00:00, 26.6MB/s]
NOTE: Try --verbose to see response content.
HTTPError: 404 Not Found from https://gitlab.cern.ch/api/v4/projects/$%7Benv.CI_PROJECT_ID%7D/packages/pypi
Not Found
which of course I guess is expected if the environment variables aren't being substituted in (although I'm not sure how GitLab CI was intended to be used to make this happen). This job can be viewed here: https://gitlab.cern.ch/scipp/pixels/labRemote/-/jobs/13795035 .
I wonder if I'm not reading the documentation correctly, or perhaps the docs need to be updated. I ended up doing it this way:
deploy-python:
image: python:3.8
stage: deploy
only:
refs:
- main
- devel
- tags
variables:
TWINE_PASSWORD: '${CI_JOB_TOKEN}'
TWINE_USERNAME: 'gitlab-ci-token'
TWINE_REPOSITORY_URL: 'https://gitlab.cern.ch/api/v4/projects/${CI_PROJECT_ID}/packages/pypi'
script:
- python -m pip install --upgrade pip setuptools wheel
- python -m pip install twine
- ls -lavh dist/
- python -m twine check dist/*
- python -m twine upload dist/*
which I think is probably better suited in my case.