From 32f0263e65cd325ed15746c93ec5d20d336dc065 Mon Sep 17 00:00:00 2001 From: Muhammad Soban Javed Date: Wed, 11 Sep 2024 18:50:20 +0500 Subject: [PATCH] build: add support for python 3.12 (#3) --- .github/docker-compose-github.yml | 8 +++++++- .github/workflows/ci.yml | 27 +++++++++++++++++++++------ Dockerfile | 18 +++++++++++++----- requirements/base.txt | 3 ++- requirements/constraints.txt | 3 +++ requirements/doc.txt | 3 ++- requirements/local.txt | 4 ++-- requirements/production.txt | 3 ++- requirements/test.txt | 3 ++- tox.ini | 2 +- 10 files changed, 55 insertions(+), 19 deletions(-) diff --git a/.github/docker-compose-github.yml b/.github/docker-compose-github.yml index 315536551..88496643d 100644 --- a/.github/docker-compose-github.yml +++ b/.github/docker-compose-github.yml @@ -12,7 +12,13 @@ services: ELASTICSEARCH_LEARNERS_UPDATE_INDEX: 'index_update' command: /edx/app/analytics_api/venvs/analytics_api/bin/python /edx/app/analytics_api/analytics_api/manage.py runserver 0.0.0.0:80 --settings analyticsdataserver.settings.local insights: - image: edxops/insights:latest + # Use this image once the Python version upgrade is complete + # image: edxops/insights:latest + build: + context: ../. + target: dev + args: + PYTHON_VERSION: "${PYTHON_VERSION}" container_name: insights_testing volumes: - ..:/edx/app/insights/edx_analytics_dashboard diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 74648add3..c3e58e95b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,7 +10,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - python-version: ["3.8"] + python-version: ["3.8", "3.12"] os: [ubuntu-20.04] toxenv: [django42] node: [16] @@ -21,11 +21,26 @@ jobs: uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} + - name: Format Python Version + id: format_python_version + shell: bash + run: | + # Replace the dot in the Python version and remove 'py' + FORMATTED_VERSION=${{ matrix.python-version }} # e.g., 3.12 + FORMATTED_VERSION=${FORMATTED_VERSION//./} # becomes 312 + + # Set environment variables + echo "FORMATTED_PYTHON_VERSION=py${FORMATTED_VERSION}" >> $GITHUB_ENV + + # Output formatted version for use in subsequent steps + echo "Formatted Python Version: py${FORMATTED_VERSION}" - name: Checkout uses: actions/checkout@v2 with: fetch-depth: 0 - name: start container + env: + PYTHON_VERSION: ${{ matrix.python-version }} run: docker compose -f .github/docker-compose-github.yml up -d - name: setup analytics-api run: | @@ -41,21 +56,21 @@ jobs: env: TESTNAME: quality TARGETS: "quality" - TOXENV: ${{ matrix.toxenv }} + TOXENV: ${{ env.FORMATTED_PYTHON_VERSION }}-${{ matrix.toxenv }} - name: test js run: ./.github/scripts/testing-js.sh shell: bash env: TESTNAME: js NODE: ${{ matrix.node }} - TOXENV: ${{ matrix.toxenv }} + TOXENV: ${{ env.FORMATTED_PYTHON_VERSION }}-${{ matrix.toxenv }} TARGETS: "requirements.js validate_js" - name: test i18n run: ./.github/scripts/testing.sh shell: bash env: TESTNAME: test-i18n - TOXENV: ${{ matrix.toxenv }} + TOXENV: ${{ env.FORMATTED_PYTHON_VERSION }}-${{ matrix.toxenv }} TARGETS: "generate_fake_translations" - name: test acceptance run: ./.github/scripts/testing-js.sh @@ -63,7 +78,7 @@ jobs: env: TESTNAME: acceptance NODE: ${{ matrix.node }} - TOXENV: ${{ matrix.toxenv }} + TOXENV: ${{ env.FORMATTED_PYTHON_VERSION }}-${{ matrix.toxenv }} TARGETS: "requirements.a11y migrate requirements.js static accept" - name: test python run: ./.github/scripts/testing-js.sh @@ -71,7 +86,7 @@ jobs: env: TESTNAME: test-python NODE: ${{ matrix.node }} - TOXENV: ${{ matrix.toxenv }} + TOXENV: ${{ env.FORMATTED_PYTHON_VERSION }}-${{ matrix.toxenv }} TARGETS: "requirements.js static test_python" - name: Run coverage if: matrix.python-version == '3.8' && matrix.toxenv == 'django42' diff --git a/Dockerfile b/Dockerfile index 7aa280219..ac1de13a6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,16 +2,20 @@ FROM ubuntu:focal as app ENV DEBIAN_FRONTEND noninteractive +ARG PYTHON_VERSION=3.8 + # Packages installed: # pkg-config; mysqlclient>=2.2.0 requires pkg-config (https://github.com/PyMySQL/mysqlclient/issues/620) -RUN apt-get update && apt-get install --no-install-recommends -qy \ +RUN apt-get update && \ + apt-get install -y software-properties-common && \ + apt-add-repository -y ppa:deadsnakes/ppa && \ + apt-get install --no-install-recommends -qy \ language-pack-en \ build-essential \ - python3.8-dev \ - python3-virtualenv \ - python3.8-distutils \ + python${PYTHON_VERSION}-dev \ + python${PYTHON_VERSION}-distutils \ libmysqlclient-dev \ pkg-config \ libssl-dev \ @@ -42,9 +46,13 @@ ARG INSIGHTS_NODEENV_DIR="${COMMON_APP_DIR}/insights/nodeenvs/insights" ENV PATH "${INSIGHTS_VENV_DIR}/bin:${INSIGHTS_NODEENV_DIR}/bin:$PATH" ENV INSIGHTS_APP_DIR ${INSIGHTS_APP_DIR} ENV THEME_SCSS "sass/themes/open-edx.scss" +ENV PYTHON_VERSION "${PYTHON_VERSION}" + +RUN curl -sS https://bootstrap.pypa.io/get-pip.py | python${PYTHON_VERSION} +RUN pip install virtualenv # No need to activate insights virtualenv as it is already activated by putting in the path -RUN virtualenv -p python3.8 --always-copy ${INSIGHTS_VENV_DIR} +RUN virtualenv -p python${PYTHON_VERSION} --always-copy ${INSIGHTS_VENV_DIR} COPY requirements ${INSIGHTS_CODE_DIR}/requirements diff --git a/requirements/base.txt b/requirements/base.txt index 680170235..9aa91700e 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -10,8 +10,9 @@ asgiref==3.8.1 # via # django # django-countries -backports-zoneinfo==0.2.1 +backports-zoneinfo==0.2.1 ; python_version < "3.9" # via + # -c requirements/constraints.txt # django # djangorestframework certifi==2024.7.4 diff --git a/requirements/constraints.txt b/requirements/constraints.txt index 3bd16e635..ae853e846 100644 --- a/requirements/constraints.txt +++ b/requirements/constraints.txt @@ -10,6 +10,9 @@ -c common_constraints.txt +# Temporary to Support the python 3.12 Upgrade +backports.zoneinfo;python_version<"3.9" # Newer versions have zoneinfo available in the standard library + # Newer version of django-webpack-loader is not compatible with npm webpack-bundle-tracker > 0.4.3 django-webpack-loader==0.7.0 diff --git a/requirements/doc.txt b/requirements/doc.txt index bab442db2..6d00294bc 100644 --- a/requirements/doc.txt +++ b/requirements/doc.txt @@ -19,8 +19,9 @@ babel==2.16.0 # via # pydata-sphinx-theme # sphinx -backports-zoneinfo==0.2.1 +backports-zoneinfo==0.2.1 ; python_version < "3.9" # via + # -c requirements/constraints.txt # -r requirements/base.txt # django # djangorestframework diff --git a/requirements/local.txt b/requirements/local.txt index c5f27b5ef..e585be31c 100644 --- a/requirements/local.txt +++ b/requirements/local.txt @@ -16,8 +16,9 @@ astroid==3.2.4 # -r requirements/test.txt # pylint # pylint-celery -backports-zoneinfo==0.2.1 +backports-zoneinfo==0.2.1 ; python_version < "3.9" # via + # -c requirements/constraints.txt # -r requirements/test.txt # django # djangorestframework @@ -96,7 +97,6 @@ django==4.2.15 # via # -c requirements/common_constraints.txt # -c requirements/constraints.txt - # -r requirements/test.txt # django-appconf # django-braces # django-crispy-forms diff --git a/requirements/production.txt b/requirements/production.txt index a4917aee1..944fe86d0 100644 --- a/requirements/production.txt +++ b/requirements/production.txt @@ -11,8 +11,9 @@ asgiref==3.8.1 # -r requirements/base.txt # django # django-countries -backports-zoneinfo==0.2.1 +backports-zoneinfo==0.2.1 ; python_version < "3.9" # via + # -c requirements/constraints.txt # -r requirements/base.txt # django # djangorestframework diff --git a/requirements/test.txt b/requirements/test.txt index d0aa7bf8b..7df8ddb3a 100644 --- a/requirements/test.txt +++ b/requirements/test.txt @@ -16,8 +16,9 @@ astroid==3.2.4 # -r requirements/test.in # pylint # pylint-celery -backports-zoneinfo==0.2.1 +backports-zoneinfo==0.2.1 ; python_version < "3.9" # via + # -c requirements/constraints.txt # -r requirements/base.txt # django # djangorestframework diff --git a/tox.ini b/tox.ini index 8b74dba97..6386cb72a 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py38-django{42} +envlist = py{38, 312}-django{42} skipsdist = true [pytest]