explosion / preshed

💥 Cython hash tables that assume keys are pre-hashed
MIT License
82 stars 19 forks source link

Tests fail to run: No module named 'preshed.bloom' #45

Closed yurivict closed 1 year ago

yurivict commented 1 year ago
cd /usr/ports/devel/py-preshed/work-py39/preshed-4.0.0 && /usr/bin/env XDG_DATA_HOME=/usr/ports/devel/py-preshed/work-py39  XDG_CONFIG_HOME=/usr/ports/devel/py-preshed/work-py39  XDG_CACHE_HOME=/usr/ports/devel/py-preshed/work-py39/.cache  HOME=/usr/ports/devel/py-preshed/work-py39 PATH=/usr/local/libexec/ccache:/usr/ports/devel/py-preshed/work-py39/.bin:/home/yuri/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin PKG_CONFIG_LIBDIR=/usr/ports/devel/py-preshed/work-py39/.pkgconfig:/usr/local/libdata/pkgconfig:/usr/local/share/pkgconfig:/usr/libdata/pkgconfig MK_DEBUG_FILES=no MK_KERNEL_SYMBOLS=no SHELL=/bin/sh NO_LINT=YES PREFIX=/usr/local  LOCALBASE=/usr/local  CC="cc" CFLAGS="-O2 -pipe  -fstack-protector-strong -fno-strict-aliasing "  CPP="cpp" CPPFLAGS=""  LDFLAGS=" -fstack-protector-strong " LIBS=""  CXX="c++" CXXFLAGS="-O2 -pipe -fstack-protector-strong -fno-strict-aliasing  "  MANPREFIX="/usr/local" CCACHE_DIR="/tmp/.ccache" BSD_INSTALL_PROGRAM="install  -s -m 555"  BSD_INSTALL_LIB="install  -s -m 0644"  BSD_INSTALL_SCRIPT="install  -m 555"  BSD_INSTALL_DATA="install  -m 0644"  BSD_INSTALL_MAN="install  -m 444" PYTHONPATH=/usr/ports/devel/py-preshed/work-py39/stage/usr/local/lib/python3.9/site-packages /usr/local/bin/python3.9 -m pytest
========================================================================================== test session starts ==========================================================================================
platform freebsd13 -- Python 3.9.16, pytest-7.2.2, pluggy-1.0.0
Using --randomly-seed=2340475823
rootdir: /usr/ports/devel/py-preshed/work-py39/preshed-4.0.0
plugins: forked-1.6.0, hypothesis-6.72.0, cov-2.9.0, mypy-plugins-1.10.1, randomly-3.12.0, timeout-2.1.0, rerunfailures-11.1.2, flaky-3.7.0, xdist-2.5.0, env-0.6.2, mock-3.10.0
collected 0 items / 4 errors                                                                                                                                                                            

================================================================================================ ERRORS =================================================================================================
_____________________________________________________________________________ ERROR collecting preshed/tests/test_bloom.py ______________________________________________________________________________
ImportError while importing test module '/usr/ports/devel/py-preshed/work-py39/preshed-4.0.0/preshed/tests/test_bloom.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/local/lib/python3.9/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
preshed/tests/test_bloom.py:5: in <module>
    from preshed.bloom import BloomFilter
E   ModuleNotFoundError: No module named 'preshed.bloom'
____________________________________________________________________________ ERROR collecting preshed/tests/test_counter.py _____________________________________________________________________________
ImportError while importing test module '/usr/ports/devel/py-preshed/work-py39/preshed-4.0.0/preshed/tests/test_counter.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/local/lib/python3.9/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
preshed/tests/test_counter.py:4: in <module>
    from preshed.counter import PreshCounter
E   ModuleNotFoundError: No module named 'preshed.counter'
____________________________________________________________________________ ERROR collecting preshed/tests/test_hashing.py _____________________________________________________________________________
ImportError while importing test module '/usr/ports/devel/py-preshed/work-py39/preshed-4.0.0/preshed/tests/test_hashing.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/local/lib/python3.9/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
preshed/tests/test_hashing.py:3: in <module>
    from preshed.maps import PreshMap
E   ModuleNotFoundError: No module named 'preshed.maps'
______________________________________________________________________________ ERROR collecting preshed/tests/test_pop.py _______________________________________________________________________________
ImportError while importing test module '/usr/ports/devel/py-preshed/work-py39/preshed-4.0.0/preshed/tests/test_pop.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/local/lib/python3.9/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
preshed/tests/test_pop.py:1: in <module>
    from ..maps import PreshMap
E   ModuleNotFoundError: No module named 'preshed.maps'
======================================================================================== short test summary info ========================================================================================
ERROR preshed/tests/test_bloom.py
ERROR preshed/tests/test_counter.py
ERROR preshed/tests/test_hashing.py
ERROR preshed/tests/test_pop.py
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 4 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
=========================================================================================== 4 errors in 0.32s ===========================================================================================
*** Error code 2

Python-3.9 FreeBSD 13.2

adrianeboyd commented 1 year ago

How did you compile/install preshed? python -m pytest in the source directory will only work with an editable install.

Otherwise, you can cd into another directory and run python -m pytest --pyargs preshed to run the tests from the installed module.

yurivict commented 1 year ago

python -m pytest --pyargs works.

What's "editable install"?

adrianeboyd commented 1 year ago

Please search for "pip editable install".

yurivict commented 1 year ago

I don't use pip at all. The package is installed into a stage directory, which is added to PYTHONPATH: PYTHONPATH=/usr/ports/devel/py-preshed/work-py39/stage/usr/local/lib/python3.9/site-packages

adrianeboyd commented 1 year ago

For our packages that have compiled C/C++ extension modules (so not just pure python; for preshed you have to compile the cython modules) you can only run pytest in a directory where the package has been installed, so I think it would work from /usr/ports/devel/py-preshed/work-py39/stage/usr/local/lib/python3.9/site-packages/preshed in your example.

If you're in the original/unmodified source directory, python tries to import the local directory named preshed instead of the installed preshed module and it fails because this isn't a full install. If you do an editable install (with pip or another tool that supports this), then you would have the compiled modules within this directory and you can run pytest preshed/tests.

We provide all our tests with our python packages so that you can run pytest --pyargs package_name without needing to have the original source directory available.

Maybe it would help if you clarify how you're installing preshed and why you're trying to run the tests from within the source directory? (I don't understand what you're actually trying to do in the end with your preshed install?)

adrianeboyd commented 1 year ago

I'll close this for now because I don't think there's a bug to address in preshed. (You can certainly discuss the advantages of using a src/ layout instead.)