MT#57855 venv deployments: use venv instead of virtualenv

When invoking `virtualenv --python=python3 virtualenv` to deploy the
virtual environment, installing the python-debian wheel, and then
re-executing `virtualenv --python=python3 virtualenv` once again, we
might end up without the virtualenv/lib/python*/site-packages/debian
directory, resulting in:

| Traceback (most recent call last):
|   File "<string>", line 1, in <module>
| ModuleNotFoundError: No module named 'debian'

This is a bug in setuptools >=51.3.3-1, see
https://bugs.debian.org/1041091 for the details, so currently affecting
all systems with Debian/bookworm.

By excluding installation of setuptools (via --no-setuptools), we would
be able to work around this bootstrapping problem itself, though then
installation of django-jsonify (which we depend on) fails with:

| ModuleNotFoundError: No module named 'setuptools'

Let's take this as a chance to switch from virtualenv to the more
lightweight venv, quoting https://docs.python.org/3/library/venv.html:

| Changed in version 3.5: The use of venv is now recommended for creating virtual environments.

Change-Id: Iad06bf8c49abd96441ab04bb9b7e3917acd1ee59
master
Michael Prokop 2 years ago
parent b50fb86bcf
commit 983d11a11a

@ -7,12 +7,12 @@ all:
.ONESHELL: .ONESHELL:
SHELL = /bin/bash SHELL = /bin/bash
venv_prod: requirements/prod.txt venv_prod: requirements/prod.txt
virtualenv --python=python3 $(VAR_DIR)/venv_prod python3 -m venv $(VAR_DIR)/venv_prod
source $(VAR_DIR)/venv_prod/bin/activate && \ source $(VAR_DIR)/venv_prod/bin/activate && \
pip3 install -r ./requirements/prod.txt | tee -a install.log pip3 install -r ./requirements/prod.txt | tee -a install.log
venv_dev: requirements/dev.txt venv_dev: requirements/dev.txt
virtualenv --python=python3 $(VAR_DIR)/venv_dev python3 -m venv $(VAR_DIR)/venv_dev
source $(VAR_DIR)/venv_dev/bin/activate && \ source $(VAR_DIR)/venv_dev/bin/activate && \
pip3 install -r ./requirements/dev.txt | tee -a install.log pip3 install -r ./requirements/dev.txt | tee -a install.log
################################### ###################################

@ -9,7 +9,7 @@ Run docker containers
--------------------- ---------------------
$ docker run -d --rm --hostname repoapi-rabbit --name repoapi-rabbit rabbitmq:3 $ docker run -d --rm --hostname repoapi-rabbit --name repoapi-rabbit rabbitmq:3
$ docker run --rm -i -t --link repoapi-rabbit:rabbit -v $(pwd):/code:rw docker.mgm.sipwise.com/repoapi-buster:latest bash $ docker run --rm -i -t --link repoapi-rabbit:rabbit -v $(pwd):/code:rw docker.mgm.sipwise.com/repoapi-bullseye:latest bash
Tmux Tmux
---- ----
@ -29,16 +29,16 @@ On your desktop, install pre-commit tool
[pre-commit](https://pre-commit.com/) [pre-commit](https://pre-commit.com/)
------------------------------------- -------------------------------------
* sudo apt install build-essential python3-dev python3-virtualenvwrapper virtualenvwrapper npm * sudo apt install build-essential python3-dev npm
* sudo npm install -g eslint * sudo npm install -g eslint
* npm install eslint-config-jquery * npm install eslint-config-jquery
* mkvirtualenv repos-scritps --python=python3 * sudo apt install pre-commit || pip3 install pre-commit
* pip3 install pre-commit
* pre-commit install * pre-commit install
virtualenv virtualenv
---------- ----------
Inside the repoapi-buster container run:
Inside the repoapi container run:
``` ```
$ make venv_dev $ make venv_dev

4
debian/control vendored

@ -8,7 +8,7 @@ Build-Depends:
libpq-dev, libpq-dev,
libsasl2-dev, libsasl2-dev,
python3-dev, python3-dev,
virtualenv, python3-venv,
Standards-Version: 4.5.1 Standards-Version: 4.5.1
Section: python Section: python
@ -24,10 +24,10 @@ Depends:
postgresql, postgresql,
python3, python3,
python3-dev, python3-dev,
python3-venv,
sipwise-repos-scripts-helpers, sipwise-repos-scripts-helpers,
uwsgi, uwsgi,
uwsgi-plugin-python3, uwsgi-plugin-python3,
virtualenv,
${misc:Depends}, ${misc:Depends},
Recommends: Recommends:
sipwise-workfront-tools, sipwise-workfront-tools,

@ -7,7 +7,7 @@
- name: install Debian package requirements - name: install Debian package requirements
apt: name=libyaml-dev state=present apt: name=libyaml-dev state=present
apt: name=python3-dev state=present apt: name=python3-dev state=present
apt: name=python-virtualenv state=present apt: name=python3-venv state=present
- hosts: all - hosts: all
connection: local connection: local

@ -5,12 +5,12 @@ FROM docker.mgm.sipwise.com/sipwise-bullseye:latest
# is updated with the current date. It will force refresh of all # is updated with the current date. It will force refresh of all
# of the base images and things like `apt-get update` won't be using # of the base images and things like `apt-get update` won't be using
# old cached versions when the Dockerfile is built. # old cached versions when the Dockerfile is built.
ENV REFRESHED_AT 2023-03-15 ENV REFRESHED_AT 2023-07-18
RUN apt-get update && apt-get install --assume-yes python3 python3-dev \ RUN apt-get update && apt-get install --assume-yes python3 python3-dev \
python3-pytest python3-pytest-pep8 \ python3-pytest python3-pytest-pep8 \
python3-pytest-pylint python3-pytest-cov python3-junitxml \ python3-pytest-pylint python3-pytest-cov python3-junitxml \
python3-pip python3-virtualenv virtualenv sqlite3 git tmux \ python3-pip python3-venv sqlite3 git tmux \
&& apt-get clean && apt-get clean
# Get pip to download and install requirements: # Get pip to download and install requirements:

Loading…
Cancel
Save