ee_utilities icon indicating copy to clipboard operation
ee_utilities copied to clipboard

Allow Specific Versions of Packages from `pip freeze` in venv

Open jandiorio opened this issue 2 years ago • 1 comments

The current solution compares the package names in the venv to the base image only resulting in the derived image losing the version specified in the venv.

The assumption is that most packages with specific versions required are packages in addition to what's installed by the base Ansible requirements in support of other modules, roles, and collections.

  1. Gather pip freeze from the base image and each venv
  2. Split the output on == in each line and build a new dictionary
  3. Loop over venv keys (package name)
  4. If venv package name is not in base package keys() add to new var (packages_to_install)

Essentially, perform the comparison at a name level, but install a specific version if the package doesn't exist in the base already.

Sample Solution Code

    
    - name: VENV PACKAGES AND VERSIONS SPLIT
      ansible.builtin.set_fact:
        venv_package_details: "{{ venv_package_details | default({}) | combine({item.split('==')[0]: item.split('==')[1]}) }}"
      loop: "{{ venv_packages }}"

    - name: BASE PACKAGES AND VERSIONS SPLIT
      ansible.builtin.set_fact:
        base_package_details: "{{ base_package_details | default({}) | combine({item.split('==')[0]: item.split('==')[1]}) }}"
      loop: "{{ base_packages }}"

    - name: CREATE NEW WITH VERSION
      ansible.builtin.set_fact:
        packages_to_install: "{{ packages_to_install | default([]) + [item.key + '==' + item.value] }}"
      loop: "{{ venv_package_details | dict2items }}"
      when:
        - item.key not in base_package_details.keys()
        - not item.key is search('ansible')

...working on integrating similar code into the existing role and PR...

jandiorio avatar May 31 '22 16:05 jandiorio