Changeset - 3f7b6eade8d7
[Not reviewed]
0 2 0
Branko Majic (branko) - 5 years ago 2020-12-25 17:51:40
branko@majic.rs
MAR-177: Do not pin pip/setuptools to specific versions when setting up Python virtual environment:

- Provided more details for the pkg-resources workaround.
- Skip installing latest version of pip - it will get installed
automatically via the virtualenv command already.
- Do not pin the setuptools package when installing.
- Updated release notes.
2 files changed with 36 insertions and 10 deletions:
0 comments (0 inline, 0 general)
docs/releasenotes.rst
Show inline comments
 
Release notes
 
=============
 

	
 

	
 
NEXT RELEASE
 
------------
 

	
 
**Bug fixes:**
 

	
 
* ``wsgi_website_`` role
 

	
 
  * When the virtual environment is created, the ``setuptools`` and
 
    ``pip`` packages will not get pinned to any specific version,
 
    allowing roles that are based on ``wsgi_website`` to easily
 
    install preferred versions, and avoid idempotence problems in the
 
    process.
 

	
 

	
 
5.0.0
 
-----
 

	
 
Upgrade to Ansible 2.9.x, dropping support for Debian 8 Jessie,
 
upgrade to Python 3.x, dropping support for Python 2.7. A number of
 
parameters have been made mandatory or deprecated. Security has been
 
slightly improved in a number of roles, and there is plenty of
 
bug-fixes and minor improvements throughout as well.
 

	
 
**Breaking changes:**
 

	
 
* Switched to Ansible 2.9.x, removing support for older versions. All
roles/wsgi_website/tasks/main.yml
Show inline comments
 
@@ -104,52 +104,64 @@
 
  when: "current_python_version.rc == 0 and not current_python_version.stdout.startswith(python_version | string)"
 
  notify:
 
    - Restart WSGI services
 

	
 
- name: Create directory for storing the Python virtual environment
 
  file:
 
    path: "{{ home }}/virtualenv"
 
    state: directory
 
    owner: "{{ admin }}"
 
    group: "{{ user }}"
 
    mode: 02750
 

	
 
# setuptools is excluded on Stretch, because it would pull-in the
 
# pkg-resources package that then messes with pip freeze etc.
 
# @TODO: Get rid of this if possible in Debian Buster.
 
# Do not install setuptools when creating the virtual environment -
 
# otherwise it will also install Debian-specific pkg-resources
 
# package. The pkg-resources package can be removed, but this breaks
 
# the package downloading via pip.
 
#
 
# Install setuptools later on via separate pip invocation.
 
#
 
# The pkg-resources package is also annoying because it shows-up in
 
# the output of the pip freeze command, and also interferes with the
 
# virtual environment management using pip-tools.
 
#
 
# For more details, see:
 
#
 
# - https://github.com/pypa/pip/issues/4022
 
# - https://bugs.launchpad.net/ubuntu/+source/python-pip/+bug/1635463
 
# - https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=871790
 

	
 
- name: Create Python virtual environment
 
  command: '/usr/bin/virtualenv --no-setuptools --python "{{ python_interpreter }}" --prompt "({{ fqdn }})" "{{ home }}/virtualenv"'
 
  args:
 
    creates: "{{ home }}/virtualenv/bin/{{ python_interpreter | basename }}"
 
  become: true
 
  become_user: "{{ admin }}"
 
  tags:
 
    # [ANSIBLE0012] Commands should not change things if nothing needs doing
 
    #   This task will not fire if the virtual environment has already bene
 
    #   created (thanks to 'creates' parameter).
 
    - skip_ansible_lint
 

	
 
- name: Install latest pip and setuptools in virtual environment
 
# @TODO: Park of the pkg-resources described above.
 
- name: Install setuptools in virtual environment
 
  pip:
 
    name:
 
      - "pip>=18.0.0,<19.0.0"
 
      - "setuptools>=40.0.0,<41.0.0"
 
      - "setuptools"
 
    virtualenv: "{{ home }}/virtualenv"
 
  become: true
 
  become_user: "{{ admin }}"
 

	
 
# Workaround for:
 
#
 
# - https://github.com/pypa/pip/issues/4022
 
# - https://bugs.launchpad.net/ubuntu/+source/python-pip/+bug/1635463
 
# - https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=871790
 
# @TODO: Park of the pkg-resources described above.
 
- name: Remove the pkg-resources package from virtual environment (see comments above for details)
 
  pip:
 
    name: pkg-resources
 
    virtualenv: "{{ home }}/virtualenv"
 
    state: absent
 
  become: true
 
  become_user: "{{ admin }}"
 

	
 
- name: Configure project directory for the Python virtual environment
 
  template:
 
    src: "venv_project.j2"
 
    dest: "{{ home }}/virtualenv/.project"
0 comments (0 inline, 0 general)