fpgmaas / cookiecutter-poetry

A modern cookiecutter template for Python projects that use Poetry for dependency management
https://fpgmaas.github.io/cookiecutter-poetry/
MIT License
380 stars 62 forks source link

How to avoid tox failing to import modules during GitHub actions? #84

Closed ariffjeff closed 1 year ago

ariffjeff commented 1 year ago

Question

During GitHub Actions tests after pushing to main branch, Tox for some reason can't import modules I've added with poetry add and imported into my source files. I always get this error: ImportError: libEGL.so.1: cannot open shared object file: No such file or directory I'm not sure if I need to add something to tox.ini or change how I'm importing in my python files, or both to fix this. Also, when creating my project with ccp, I accepted all the options except for docker. I'm not sure if that's playing a role here.

For example...

/my-project
  /my_project
    /main.py
  /tests
    /test_main.py

If I do poetry add pyside6 then add something like from PySide6.QtWidgets import QApplication, QWidget to /my_project/main.py then import said source file to /tests/test_main.py file with from my_project.main import main, I will get the following error from GitHub actions when pushing to the remote main branch...

 ==================================== ERRORS ====================================
  _____________________ ERROR collecting tests/test_main.py ______________________
  tests/test_main.py:3: in <module>
      from my_project.main import main
  my_project/main.py:4: in <module>
      from PySide6.QtWidgets import QApplication, QWidget
  E   ImportError: libEGL.so.1: cannot open shared object file: No such file or directory

What's the proper way to fix tox not able to import properly? All config files are at their defaults when they were created from ccp and I haven't run any special commands to change anything.

fpgmaas commented 1 year ago

Hi @ariffjeff. Thanks for raising the issue. It seems this is not an issue caused by cookiecutter-poetry, but rather an issue caused by the specific package you are using. It is expecting to find a library, which you currently do not have. To test this, try to remove the libraries you mentioned, and simply install and import e.g. pandas.

With regards to your specific issue; try adding the installation of the required libraries link to the GitHub actions workflows in the .github directory.

ariffjeff commented 1 year ago

@fpgmaas Looks like you are correct. Turns out PySide6 doesn't load it's Qt modules the traditional way for some weird technical reason as described in it's init.py file.

I removed the package and tried to just use pandas and got it to work successfully with tox. so yeah the problem is definitely tox not being able to get PySide6's Qt modules.

I added the following to main.yml to make sure the sub modules get installed before the tox testing, and gh actions says they do indeed get installed.

- name: Manually install PySide6 modules
  run: |
    python -m pip uninstall pyside6 shiboken6 PySide6-Essentials PySide6-Addons
    python -m pip cache purge
    python -m pip install pyside6

But I still get the same error. It appears the github action is still trying to reach the sub modules through PySide6 instead of directly when it looks at the imports like from PySide6.QtWidgets import QApplication. And I can't seem to figure out how to tell it to just do that directly. I'll go ask stack overflow.