1

In a Gitlab CI pipeline, I want to check that the package that was just uploaded to a registry is there and works well. What I do is basically:

[…]

stages:
  - […]
  - deploy
  - deploytest

pip-upload:
  stage: deploy
  rules:
    - if: '$CI_COMMIT_TAG && $CI_COMMIT_TAG =~ /v[1-9].+/'
  script:
    - python3 setup.py sdist
    - python3 -m twine upload --repository-url […] dist/*

test-pip:
  stage: deploytest
  rules:
    - if: '$CI_COMMIT_TAG && $CI_COMMIT_TAG =~ /v[1-9].+/'
  script:
    - python3 -m pip install --extra-index-url […] --upgrade --pre "mypackage==$PACKAGE_VERSION"
    - cd /tmp
    - python3 -m pytest --pyargs mypackage

This however requires the creation of the Python version from the git tag on the command line. I use setuptools_scm in my package. I there a way to call this package in a way that it returns the version corresponding to a particular git tag?

sytech
  • 29,298
  • 3
  • 45
  • 86
olebole
  • 521
  • 4
  • 17
  • It seems like what you have works? Or do you want to test your package before uploading it to the package registry? – sytech Sep 16 '22 at 00:19
  • I want a final test that the package that I uploaded to the registry is working correctly, by downloading/installing that specific version from the registry and running its tests. For this, I need to extract the version number and give it as an argument to the pip installer. – olebole Sep 16 '22 at 13:19

1 Answers1

0

You can run python -m setuptools_scm to get the version. See python -m setuptools_scm --help for additional options.

You can also run python setup.py --version to get the version (assuming setuptools-scm is installed).

sytech
  • 29,298
  • 3
  • 45
  • 86