Bootstrap FreeKB - GitLab - Test Python pip requirements
GitLab - Test Python pip requirements

Updated:   |  GitLab articles

Let's say you have a Python requirements file that perhaps contains a few packages, perhaps something like this. In GitLab, at Code > Repository create a requirements.txt file that contains the packages you want to test.

SQLAlchemy-Utils==0.41.1
Flask-SQLAlchemy==3.0.5
Flask-Login==0.6.2
requests==2.31.0

 

Then in Build > Pipeline editor, update your .gitlab-ci.yml file to contain something like this.

test_pip_install:
  image: python:3.11
  script:
    - pip install --requirement requirements.txt

 

The pipline job output should return something like this. In this example, the job passed, meaning the image (python:3.11) in this example is able to install the packages listed in requirements.txt.

Running with gitlab-runner 16.1.0~beta.59.g83c66823 (83c66823)
  on blue-1.shared.runners-manager.gitlab.com/default j1aLDqxS, system ID: s_b437a71a38f9
  feature flags: FF_USE_IMPROVED_URL_MASKING:true
Preparing the "docker+machine" executor
00:19
Using Docker executor with image python:3.11 ...
Pulling docker image python:3.11 ...
Using docker image sha256:09b1cac8826b0a713710c5aa6f905325dd06a10104fd47594fb091e6b134f5c3 for python:3.11 with digest python@sha256:2dd2f9000021839e8fba0debd8a2308c7e26f95fdfbc0c728eeb0b5b9a8c6a39 ...
Preparing environment
00:05
Running on runner-j1aldqxs-project-46323147-concurrent-0 via runner-j1aldqxs-shared-1687522758-0c8e4002...
Getting source from Git repository
00:01
Fetching changes with git depth set to 20...
Initialized empty Git repository in /builds/JeremyCanfield/freekb-vault/.git/
Created fresh repository.
Checking out 31bae4a2 as detached HEAD (ref is main)...
Skipping Git submodules setup
$ git remote set-url origin "${CI_REPOSITORY_URL}"
Executing "step_script" stage of the job script
00:06
Using docker image sha256:09b1cac8826b0a713710c5aa6f905325dd06a10104fd47594fb091e6b134f5c3 for python:3.11 with digest python@sha256:2dd2f9000021839e8fba0debd8a2308c7e26f95fdfbc0c728eeb0b5b9a8c6a39 ...
$ pip install --requirement requirements.txt
Collecting SQLAlchemy-Utils==0.41.1 (from -r requirements.txt (line 1))
  Downloading SQLAlchemy_Utils-0.41.1-py3-none-any.whl (92 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 92.6/92.6 kB 3.4 MB/s eta 0:00:00
Collecting Flask-SQLAlchemy==3.0.5 (from -r requirements.txt (line 2))
  Downloading flask_sqlalchemy-3.0.5-py3-none-any.whl (24 kB)
Collecting Flask-Login==0.6.2 (from -r requirements.txt (line 3))
  Downloading Flask_Login-0.6.2-py3-none-any.whl (17 kB)
Collecting requests==2.31.0 (from -r requirements.txt (line 4))
  Downloading requests-2.31.0-py3-none-any.whl (62 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 62.6/62.6 kB 6.2 MB/s eta 0:00:00
Collecting SQLAlchemy>=1.3 (from SQLAlchemy-Utils==0.41.1->-r requirements.txt (line 1))
  Downloading SQLAlchemy-2.0.16-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.8 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.8/2.8 MB 10.6 MB/s eta 0:00:00
Collecting flask>=2.2.5 (from Flask-SQLAlchemy==3.0.5->-r requirements.txt (line 2))
  Downloading Flask-2.3.2-py3-none-any.whl (96 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 96.9/96.9 kB 18.7 MB/s eta 0:00:00
Collecting Werkzeug>=1.0.1 (from Flask-Login==0.6.2->-r requirements.txt (line 3))
  Downloading Werkzeug-2.3.6-py3-none-any.whl (242 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 242.5/242.5 kB 13.8 MB/s eta 0:00:00
Collecting charset-normalizer<4,>=2 (from requests==2.31.0->-r requirements.txt (line 4))
  Downloading charset_normalizer-3.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (197 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 197.3/197.3 kB 18.6 MB/s eta 0:00:00
Collecting idna<4,>=2.5 (from requests==2.31.0->-r requirements.txt (line 4))
  Downloading idna-3.4-py3-none-any.whl (61 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 61.5/61.5 kB 13.0 MB/s eta 0:00:00
Collecting urllib3<3,>=1.21.1 (from requests==2.31.0->-r requirements.txt (line 4))
  Downloading urllib3-2.0.3-py3-none-any.whl (123 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 123.6/123.6 kB 18.5 MB/s eta 0:00:00
Collecting certifi>=2017.4.17 (from requests==2.31.0->-r requirements.txt (line 4))
  Downloading certifi-2023.5.7-py3-none-any.whl (156 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 157.0/157.0 kB 17.7 MB/s eta 0:00:00
Collecting Jinja2>=3.1.2 (from flask>=2.2.5->Flask-SQLAlchemy==3.0.5->-r requirements.txt (line 2))
  Downloading Jinja2-3.1.2-py3-none-any.whl (133 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 133.1/133.1 kB 17.6 MB/s eta 0:00:00
Collecting itsdangerous>=2.1.2 (from flask>=2.2.5->Flask-SQLAlchemy==3.0.5->-r requirements.txt (line 2))
  Downloading itsdangerous-2.1.2-py3-none-any.whl (15 kB)
Collecting click>=8.1.3 (from flask>=2.2.5->Flask-SQLAlchemy==3.0.5->-r requirements.txt (line 2))
  Downloading click-8.1.3-py3-none-any.whl (96 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 96.6/96.6 kB 16.3 MB/s eta 0:00:00
Collecting blinker>=1.6.2 (from flask>=2.2.5->Flask-SQLAlchemy==3.0.5->-r requirements.txt (line 2))
  Downloading blinker-1.6.2-py3-none-any.whl (13 kB)
Collecting typing-extensions>=4.2.0 (from SQLAlchemy>=1.3->SQLAlchemy-Utils==0.41.1->-r requirements.txt (line 1))
  Downloading typing_extensions-4.6.3-py3-none-any.whl (31 kB)
Collecting greenlet!=0.4.17 (from SQLAlchemy>=1.3->SQLAlchemy-Utils==0.41.1->-r requirements.txt (line 1))
  Downloading greenlet-2.0.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (618 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 618.8/618.8 kB 16.8 MB/s eta 0:00:00
Collecting MarkupSafe>=2.1.1 (from Werkzeug>=1.0.1->Flask-Login==0.6.2->-r requirements.txt (line 3))
  Downloading MarkupSafe-2.1.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (28 kB)
Installing collected packages: urllib3, typing-extensions, MarkupSafe, itsdangerous, idna, greenlet, click, charset-normalizer, certifi, blinker, Werkzeug, SQLAlchemy, requests, Jinja2, SQLAlchemy-Utils, flask, Flask-SQLAlchemy, Flask-Login
Successfully installed Flask-Login-0.6.2 Flask-SQLAlchemy-3.0.5 Jinja2-3.1.2 MarkupSafe-2.1.3 SQLAlchemy-2.0.16 SQLAlchemy-Utils-0.41.1 Werkzeug-2.3.6 blinker-1.6.2 certifi-2023.5.7 charset-normalizer-3.1.0 click-8.1.3 flask-2.3.2 greenlet-2.0.2 idna-3.4 itsdangerous-2.1.2 requests-2.31.0 typing-extensions-4.6.3 urllib3-2.0.3
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
Cleaning up project directory and file based variables
00:01
Job succeeded

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 3d85b3 in the box below so that we can be sure you are a human.