From eb03bc17d8bac6029d2a05f9c88a14f775bf6ad8 Mon Sep 17 00:00:00 2001 From: Felipe Reyes Date: Fri, 7 Oct 2022 16:49:33 -0300 Subject: [PATCH] Clear environment variables when running apt (#641) * Clear environment variables when running apt When running 'apt' within the snap the environment variables set will make it run with the python version embedded in the snap instead of the system's tools, this will make the package installation fail with the following error: Setting up python3-pkg-resources (45.2.0-1) ... Fatal Python error: init_sys_streams: can't initialize sys standard streams Python runtime state: core initialized Traceback (most recent call last): File "/snap/charm/677/usr/lib/python3.10/io.py", line 54, in ImportError: cannot import name 'text_encoding' from 'io' (unknown location) dpkg: error processing package python3-pkg-resources (--configure): installed python3-pkg-resources package post-installation script subprocess returned error exit status 1 Test case: git clone https://opendev.org/openstack/charm-octavia-dashboard.git cd charm-octavia-dashboard git checkout e1f50a2 tox -e build # use charmcraft 1.5 * Fix typo --- charmtools/build/builder.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/charmtools/build/builder.py b/charmtools/build/builder.py index a0749ec..9eaddbc 100755 --- a/charmtools/build/builder.py +++ b/charmtools/build/builder.py @@ -785,8 +785,8 @@ def workaround_charmcraft_maybe_ensure_build_packages(self): and (os.environ.get('CRAFT_PART_NAME', None) or os.environ.get('CHARMCRAFT_PART_NAME', None))): log.warning('Probably running as root in charmcraft, proactively ' - 'installing the `git` and `virutalenv` packages.') - subprocess.run(('apt', '-y', 'install', 'git', 'virtualenv'), check=True) + 'installing the `git` and `virtualenv` packages.') + subprocess.run(('apt', '-y', 'install', 'git', 'virtualenv'), check=True, env={}) def generate(self): layers = self.fetch()