Skip to content

Commit

Permalink
Clear environment variables when running apt (#641)
Browse files Browse the repository at this point in the history
* 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 <module>
    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
  • Loading branch information
freyes authored Oct 7, 2022
1 parent 49a6541 commit eb03bc1
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions charmtools/build/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit eb03bc1

Please sign in to comment.