Skip to content

Conversation

@muhammad-ammar
Copy link
Member

@muhammad-ammar muhammad-ammar commented Oct 23, 2025

Description: Changes in this PR have been copied from #269, #270 and #272


Make sure that the following steps are done before merging:

  • Have a Site Reliability Engineer review the PR if you don't own all of the services impacted.
  • If you are adding any new default values that need to be overridden when this change goes live, update internal repos and add an entry to the top of the CHANGELOG.
  • Performed the appropriate testing.

Copilot AI review requested due to automatic review settings October 23, 2025 06:48
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR modifies the analytics API role to install Python 3.11 from vendored packages on Ubuntu Focal instead of using the standard repository installation. This is necessary because Ubuntu Focal (20.04) is out of support and Python 3.11 is not available in its default repositories.

Key changes:

  • Switches from system Python 3.11 installation to vendored package installation controlled by a feature flag
  • Adds tasks to download and install Python 3.11 packages from a vendored GitHub repository
  • Disables the default Python 3.11 installation in the edx_django_service dependency

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
playbooks/roles/analytics_api/tasks/main.yml Adds new tasks to conditionally install either standard or vendored Python 3.11 packages
playbooks/roles/analytics_api/meta/main.yml Disables Python 3.11 installation in the edx_django_service role dependency
playbooks/roles/analytics_api/defaults/main.yml Defines configuration variables for vendored Python 3.11 package installation including URLs, build versions, and dependencies

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

#

- name: install python3.11
when: not use_vendored_py311
Copy link

Copilot AI Oct 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition logic is inverted. When use_vendored_py311 is true, the standard Python 3.11 installation task should be skipped, but this condition will execute the standard installation when vendored packages are being used. Change to when: not use_vendored_py311 | default(false) or verify the intended logic.

Suggested change
when: not use_vendored_py311
when: not use_vendored_py311 | default(false)

Copilot uses AI. Check for mistakes.
# Build string that's present in the deb file names. (Just used to make the
# names below easier to read.)
vendored_py311_build: "3.11.13-15-g8adac492d4-1+focal1"
# These must be kept topologically sorted, dependant packages last, as they
Copy link

Copilot AI Oct 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected spelling of 'dependant' to 'dependent'.

Suggested change
# These must be kept topologically sorted, dependant packages last, as they
# These must be kept topologically sorted, dependent packages last, as they

Copilot uses AI. Check for mistakes.

- name: "Install vendored Python 3.11 packages"
when: use_vendored_py311
command: dpkg -i "/tmp/vendored_python_{{ vendored_py311_build }}/{{ item }}"
Copy link

Copilot AI Oct 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using command module with dpkg -i will always report as 'changed' even if packages are already installed. Consider using the apt module with deb parameter or add creates parameter to make the task idempotent and prevent unnecessary reinstallations on subsequent runs.

Suggested change
command: dpkg -i "/tmp/vendored_python_{{ vendored_py311_build }}/{{ item }}"
apt:
deb: "/tmp/vendored_python_{{ vendored_py311_build }}/{{ item }}"

Copilot uses AI. Check for mistakes.
dependencies:
- role: edx_django_service
edx_django_service_use_python311: true
edx_django_service_use_python311: false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the edx_django_service role is what's installing Python 3.11 in the first place, you'll probably need to make these changes there instead of in the analytics_api role.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK yeah, looking further at edx_django_service, the changes definitely need to be there instead -- it then proceeds to make a venv, install Python dependencies, etc.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the edx_django_service role is what's installing Python 3.11 in the first place, you'll probably need to make these changes there instead of in the analytics_api role.

edx_django_service role is being used by almost all the roles, is it safe to make the changes there?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, if you add a similar use_vendored_py311 toggle. But also remember that a lot of those roles are no longer used -- most services have been switched to Docker and Kubernetes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@timmc-edx In edx_django_service, the edx_django_service_use_python311 flag is only used in the two tasks pasted below. I think if we copy/paste these tasks into analytics_api, then we are good to go. Please share your thoughts. I have also updated the PR.

- name: install python3.11
  apt:
    pkg:
      - python3.11-dev
      - python3.11-distutils
    update_cache: yes
  register: install_pkgs
  until: install_pkgs is success
  retries: 10
  delay: 5
  when: edx_django_service_use_python311 and not edx_django_service_enable_experimental_docker_shim
  tags:
    - install
    - install:system-requirements
    
- name: build virtualenv with python3.11
  command: "virtualenv --python=python3.11 {{ edx_django_service_venv_dir }}"
  args:
    creates: "{{ edx_django_service_venv_dir }}/bin/pip"
  become_user: "{{ edx_django_service_user }}"
  when: edx_django_service_use_python311 and not edx_django_service_enable_experimental_docker_shim
  tags:
    - install
    - install:system-requirements

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that will work, for the reasons I mentioned above.

@muhammad-ammar muhammad-ammar force-pushed the ammar/use-focal-py branch 2 times, most recently from 7bf1a02 to 6317524 Compare October 27, 2025 06:44
Copilot AI review requested due to automatic review settings October 27, 2025 18:13
@muhammad-ammar muhammad-ammar force-pushed the ammar/use-focal-py branch 3 times, most recently from 5ab33b5 to 6f068ff Compare October 27, 2025 18:16
@muhammad-ammar
Copy link
Member Author

@timmc-edx Please review now. I have removed the changes from the analytics_api role and moved them inside edx_django_service

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@muhammad-ammar
Copy link
Member Author

@timmc-edx Please review the new changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants