From 94c79db867759075b1c59d02d8fca4ee68b8f443 Mon Sep 17 00:00:00 2001 From: Danyal-Faheem Date: Tue, 21 May 2024 21:00:53 +0500 Subject: [PATCH] fix: allow running tox with different python versions tox would enforce python3.8 without this change Now we install tox in that specific python and then run tox from it --- .github/workflows/ci.yml | 19 ++++++++++++++++--- Makefile | 5 +++-- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3be3d55..b0a3e33 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,18 +30,31 @@ jobs: - name: Build Docker run: | docker compose -f .github/docker-compose-ci.yml up -d - docker exec ecomworker bash -c "sudo apt-get update -y; sudo apt-get install python${{ matrix.python-version }} python${{ matrix.python-version }}-dev -y;" - + docker exec ecomworker bash -c " + sudo apt-get update -y && + sudo apt-get install python${{ matrix.python-version }} \ + python${{ matrix.python-version }}-dev \ + python${{ matrix.python-version }}-distutils -y && + curl -sS https://bootstrap.pypa.io/get-pip.py | python${{ matrix.python-version }};" + # Need to install pip from source here^ otherwise some packages don't get installed - name: Format Python Version run: | PYTHON_VERSION=${{ matrix.python-version }} FORMATTED_VERSION=${PYTHON_VERSION/3./py3} echo "PYTHON_VERSION=$FORMATTED_VERSION" >> $GITHUB_ENV + - name: Install dependencies + run: | + docker exec -t ecomworker bash -c " + cd /edx/app/ecomworker/ecomworker && + python${{ matrix.python-version }} -m pip install tox + " - name: Run Tests env: TARGETS: ${{ matrix.test-target }} run: | - docker exec ecomworker bash -c "cd /edx/app/ecomworker/ecomworker && PYTHON_VERSION=$PYTHON_VERSION make $TARGETS" + docker exec ecomworker bash -c " + cd /edx/app/ecomworker/ecomworker && + PYTHON_VERSION=${{ matrix.python-version }} PYTHON_ENV=$PYTHON_VERSION make $TARGETS" - name: Run Coverage if: matrix.test-target == 'test' && matrix.python-version == '3.8' diff --git a/Makefile b/Makefile index 3ffe97d..b02207e 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,6 @@ PACKAGE = ecommerce_worker -PYTHON_VERSION_VAR=$(if $(PYTHON_VERSION),$(PYTHON_VERSION),py312) +PYTHON_VERSION_VAR=$(if $(PYTHON_VERSION),$(PYTHON_VERSION),3.12) +PYTHON_ENV_VAR=$(if $(PYTHON_ENV),$(PYTHON_ENV),py312) help: ## display this help message @echo "Please use \`make ' where is one of" @@ -15,7 +16,7 @@ worker: ## start the Celery worker process celery -A ecommerce_worker worker --app=$(PACKAGE).celery_app:app --loglevel=info --queue=fulfillment,email_marketing test: requirements_tox ## run unit tests and report on coverage - tox -e ${PYTHON_VERSION_VAR} + python${PYTHON_VERSION_VAR} -m tox -e ${PYTHON_ENV_VAR} quality: requirements_tox ## run pep8 and pylint tox -e quality