pyinstaller / pyinstaller-hooks-contrib

Community maintained hooks for PyInstaller.
Other
96 stars 126 forks source link

ImportError on test_trame.py #801

Closed davetapley closed 2 months ago

davetapley commented 2 months ago

Describe the bug

Getting error follow I want to help guide.

Tried clean pyenv, and I've contributed before using same machine / environment.

To Reproduce

In terminal:

 pyenv shell 3.12.2
 pyenv virtualenv hooks-contrib-3.12.2
 python -m pip install -e .
 python -m pip install -r requirements-test.txt
 python -m pip install flake8 pyinstaller\n
 pytest

Error:

====================================== test session starts =======================================
platform darwin -- Python 3.12.2, pytest-8.3.3, pluggy-1.5.0 -- /Users/dave/.pyenv/versions/3.12.2/bin/python
cachedir: .pytest_cache
rootdir: /Users/dave/code/pyinstaller-hooks-contrib
configfile: setup.cfg
plugins: drop-dup-tests-1.0.0, anyio-4.4.0, timeout-2.3.1, xdist-3.6.1
collected 490 items / 1 error / 488 deselected / 2 selected                                      

============================================= ERRORS =============================================
______________________________ ERROR collecting tests/test_trame.py ______________________________
ImportError while importing test module '/Users/dave/code/pyinstaller-hooks-contrib/tests/test_trame.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
../../.pyenv/versions/3.12.2/lib/python3.12/importlib/__init__.py:90: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
tests/test_trame.py:16: in <module>
    from PyInstaller.utils.hooks import check_requirement
E   ImportError: cannot import name 'check_requirement' from 'PyInstaller.utils.hooks' (/Users/dave/.pyenv/versions/3.12.2/lib/python3.12/site-packages/PyInstaller/utils/hooks/__init__.py)
======================================== warnings summary ========================================
../../.pyenv/versions/3.12.2/lib/python3.12/site-packages/PyInstaller/lib/modulegraph/modulegraph.py:16
  /Users/dave/.pyenv/versions/3.12.2/lib/python3.12/site-packages/PyInstaller/lib/modulegraph/modulegraph.py:16: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
    import pkg_resources

../../.pyenv/versions/3.12.2/lib/python3.12/site-packages/setuptools/_distutils/ccompiler.py:855
  /Users/dave/.pyenv/versions/3.12.2/lib/python3.12/site-packages/setuptools/_distutils/ccompiler.py:855: DeprecationWarning: includes is deprecated
    warnings.warn("includes is deprecated", DeprecationWarning)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
==================================== short test summary info =====================================
ERROR tests/test_trame.py
!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
========================== 488 deselected, 2 warnings, 1 error in 1.01s ==========================

Expected behavior

master always works in clean env.

Desktop (please complete the following information):

Additional context

test_trame.py came in just after my last contribution.

rokm commented 2 months ago

That's because test_trame.py tries to use PyInstaller.utils.hooks.check_requirement, which was introduced in PyInstaller 6.0.

davetapley commented 2 months ago

@rokm yep, that's it!

Could we put required PyInstaller version in e.g. setup.cfg so pip install -e . will check (I think)?

Alternatively update I want to help to also include explicit pip install pyinstaller==6?

bwoodsend commented 2 months ago

We don't really have any reason to keep the tests compatible with old PyInstaller versions.

rokm commented 2 months ago

Actually, I think we should switch that check_requirement with is_module_satisfies (which exists in 5.x, while in 6.x is compatibility alias for check_requirement). If nothing else, for the sake of consistency (we use is_module_satisfies pretty much everywhere else). But I also occasionally test with 5.x, although typically against a specific test file (that was never test_trame.py, so this went unnoticed).

bwoodsend commented 2 months ago

Could we put required PyInstaller version in e.g. setup.cfg so pip install -e . will check (I think)?

That would create a circular import which we really want to avoid.

Alternatively update I want to help to also include explicit pip install pyinstaller==6?

Of course that advice will age quickly but I wouldn't mind a generic please use the latest PyInstaller advice.

rokm commented 2 months ago

But I wouldn't mind a generic please use the latest PyInstaller advice, either.