From 983d11a11aa7cdd0ef7e20a6bda15d2df2673fb6 Mon Sep 17 00:00:00 2001 From: Michael Prokop Date: Tue, 18 Jul 2023 09:50:22 +0200 Subject: [PATCH] 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 "", line 1, in | 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 --- Makefile | 4 ++-- README.md | 10 +++++----- debian/control | 4 ++-- deploy.yml | 2 +- t/Dockerfile | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 32844c0..598e315 100644 --- a/Makefile +++ b/Makefile @@ -7,12 +7,12 @@ all: .ONESHELL: SHELL = /bin/bash 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 && \ pip3 install -r ./requirements/prod.txt | tee -a install.log 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 && \ pip3 install -r ./requirements/dev.txt | tee -a install.log ################################### diff --git a/README.md b/README.md index 72ec146..3811102 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Run docker containers --------------------- $ 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 ---- @@ -29,16 +29,16 @@ On your desktop, install pre-commit tool [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 * npm install eslint-config-jquery - * mkvirtualenv repos-scritps --python=python3 - * pip3 install pre-commit + * sudo apt install pre-commit || pip3 install pre-commit * pre-commit install virtualenv ---------- -Inside the repoapi-buster container run: + +Inside the repoapi container run: ``` $ make venv_dev diff --git a/debian/control b/debian/control index d6c8960..3f3104b 100644 --- a/debian/control +++ b/debian/control @@ -8,7 +8,7 @@ Build-Depends: libpq-dev, libsasl2-dev, python3-dev, - virtualenv, + python3-venv, Standards-Version: 4.5.1 Section: python @@ -24,10 +24,10 @@ Depends: postgresql, python3, python3-dev, + python3-venv, sipwise-repos-scripts-helpers, uwsgi, uwsgi-plugin-python3, - virtualenv, ${misc:Depends}, Recommends: sipwise-workfront-tools, diff --git a/deploy.yml b/deploy.yml index db4f657..55075dd 100644 --- a/deploy.yml +++ b/deploy.yml @@ -7,7 +7,7 @@ - name: install Debian package requirements apt: name=libyaml-dev state=present apt: name=python3-dev state=present - apt: name=python-virtualenv state=present + apt: name=python3-venv state=present - hosts: all connection: local diff --git a/t/Dockerfile b/t/Dockerfile index 96a0f78..374abdc 100644 --- a/t/Dockerfile +++ b/t/Dockerfile @@ -5,12 +5,12 @@ FROM docker.mgm.sipwise.com/sipwise-bullseye:latest # 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 # 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 \ python3-pytest python3-pytest-pep8 \ 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 # Get pip to download and install requirements: