awscli-login icon indicating copy to clipboard operation
awscli-login copied to clipboard

import lxml.etree as ET fails on Linux

Open ddriddle opened this issue 2 years ago • 1 comments

The lxml 4.9.2 fails to import correctly in Github Actions and in a Linux container:

Github Actions log:

bats/bin/bats -r tests
1..5
ok 1 Login with unconfigured awscli
ok 2 Enable plugin in ~/.aws/config
not ok 3 Login and logout
# (from function `setup' in test file tests/common.bash, line 13)
#   `aws login configure <<- EOF  # NOTA BENE: <<- strips tabs' failed with status 255
# *************.aws-login/config**********************
# [plugins]
# login = awscli_login.plugin
# cli_legacy_plugin_path = /home/runner/work/_temp/venv/lib/python3.11/site-packages
# ***************************************************
#
# No module named 'lxml.etree'

I reproduced the error locally in a container using act:

$ # Run tests
$ act --artifact-server-path $HOME/tmp/act
$ # Get container ID of ACT container
$ docker ps
CONTAINER ID   IMAGE                            COMMAND               CREATED       STATUS       PORTS     NAMES
e608832e7791   catthehacker/ubuntu:act-latest   "tail -f /dev/null"   2 hours ago   Up 2 hours             act-CI-CD-awscliv2-test-1
# Exec into container
$ docker exec -it e608832e7791 bash
$ export PATH=$RUNNER_TEMP/bin:$PATH
# Expected error
$ aws

No module named 'lxml.etree'
$ cd $RUNNER_TEMP
$ source venv/bin/activate
(venv) $ pip freeze
awscli-login==0.2b2.dev47+dirty
botocore==1.29.63
certifi==2022.12.7
cffi==1.15.1
charset-normalizer==3.0.1
cryptography==39.0.0
idna==3.4
importlib-metadata==6.0.0
jaraco.classes==3.2.3
jeepney==0.8.0
jmespath==1.0.1
keyring==23.13.1
lxml==4.9.2
more-itertools==9.0.0
pycparser==2.21
python-dateutil==2.8.2
requests==2.28.2
SecretStorage==3.3.3
six==1.16.0
urllib3==1.26.14
zipp==3.12.0
# Not a Python 3.11 issue
(venv) $ python
Python 3.11.1 (main, Dec  8 2022, 07:18:22) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import lxml.etree as ET
(venv) deactivate
# Seems to be an issue with mixing Python 3.10 and Python 3.11 issue...
# lxml is not installed in the system Python
$ cd /
$ python
Python 3.10.6 (main, Nov 14 2022, 16:10:14) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import lxml
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'lxml'
# It is in the venv so let's load it with Python 3.10 for fun and profit...
$ cd $RUNNER_TEMP/venv/lib/python3.11/site-packages/
python
Python 3.10.6 (main, Nov 14 2022, 16:10:14) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import lxml
>>> import lxml.etree as ET
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'lxml.etree'
# Same error aws throws which is running Python 3.9.11
$ rm -rf ~/.aws/
$ aws --version
aws-cli/2.9.20 Python/3.9.11 Linux/5.10.47-linuxkit exe/x86_64.ubuntu.22 prompt/off

Note that I did comment out all of the workflow except awscliv2 to make things manageable.

ddriddle avatar Feb 03 '23 19:02 ddriddle

The issue is that the plugin still has external dependencies. The plugin needs to be completely decoupled from all imports other than botocore and other deps directly used by aws-cli. I added a failing integration test. To test this by hand (which is faster) do the following:

# Change into the source directory were the `awscli_login` modules lives
$ cd src
# Create a clean Python environment
$ python -m venv venv
$ source venv/bin/activate
# Install necessary `aws-cli` deps
$ pip install botocore
# Test plugin
$ python -c 'from awscli_login import plugin'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/ddriddle/src/github.com/techservicesillinois/awscli-login/src/awscli_login/plugin/__init__.py", line 16, in <module>
    from .__main__ import main, logout
  File "/Users/ddriddle/src/github.com/techservicesillinois/awscli-login/src/awscli_login/plugin/__main__.py", line 12, in <module>
    from ..config import ERROR_NONE, ERROR_UNKNOWN, Profile
  File "/Users/ddriddle/src/github.com/techservicesillinois/awscli-login/src/awscli_login/config.py", line 15, in <module>
    from keyring import get_password, set_password
ModuleNotFoundError: No module named 'keyring'

ddriddle avatar Feb 03 '23 20:02 ddriddle

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days.

github-actions[bot] avatar Apr 14 '24 14:04 github-actions[bot]