Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python testsuite fails: cannot import name '_gtar' from partially initialized module 'gtar' #29

Closed
yurivict opened this issue Jun 27, 2022 · 4 comments

Comments

@yurivict
Copy link

===>  Testing for py39-libgetar-1.1.3
===>   py39-libgetar-1.1.3 depends on package: py39-pytest>=7,1 - found
===>   py39-libgetar-1.1.3 depends on file: /usr/local/bin/python3.9 - found
cd /disk-samsung/freebsd-ports/science/py-libgetar/work-py39/libgetar-1.1.3 && /usr/bin/env XDG_DATA_HOME=/disk-samsung/freebsd-ports/science/py-libgetar/work-py39  XDG_CONFIG_HOME=/disk-samsung/freebsd-ports/science/py-libgetar/work-py39  XDG_CACHE_HOME=/disk-samsung/freebsd-ports/science/py-libgetar/work-py39/.cache  HOME=/disk-samsung/freebsd-ports/science/py-libgetar/work-py39 PATH=/disk-samsung/freebsd-ports/science/py-libgetar/work-py39/.bin:/home/yuri/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin NO_PIE=yes MK_DEBUG_FILES=no MK_KERNEL_SYMBOLS=no SHELL=/bin/sh NO_LINT=YES LDSHARED="cc -shared" PYTHONDONTWRITEBYTECODE= PYTHONOPTIMIZE= PREFIX=/usr/local  LOCALBASE=/usr/local  CC="cc" CFLAGS="-O2 -pipe -fno-omit-frame-pointer  -fstack-protector-strong -fno-strict-aliasing "  CPP="cpp" CPPFLAGS="-fno-omit-frame-pointer"  LDFLAGS=" -fstack-protector-strong " LIBS=""  CXX="c++" CXXFLAGS="-O2 -pipe -fno-omit-frame-pointer -fstack-protector-strong -fno-strict-aliasing -fno-omit-frame-pointer  "  MANPREFIX="/usr/local" 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=/disk-samsung/freebsd-ports/science/py-libgetar/work-py39/stage/usr/local/lib/python3.9/site-packages /usr/local/bin/python3.9 -m pytest -k '' -rs -v -o addopts= 
==================================================================================== test session starts =====================================================================================
platform freebsd13 -- Python 3.9.13, pytest-7.1.2, pluggy-1.0.0 -- /usr/local/bin/python3.9
cachedir: .pytest_cache
rootdir: /disk-samsung/freebsd-ports/science/py-libgetar/work-py39/libgetar-1.1.3
plugins: typeguard-2.13.3
collected 0 items / 3 errors                                                                                                                                                                 

=========================================================================================== ERRORS ===========================================================================================
_____________________________________________________________________________ ERROR collecting test/test_gtar.py _____________________________________________________________________________
ImportError while importing test module '/disk-samsung/freebsd-ports/science/py-libgetar/work-py39/libgetar-1.1.3/test/test_gtar.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)
test/test_gtar.py:4: in <module>
    import gtar
gtar/__init__.py:2: in <module>
    from . import _gtar
E   ImportError: cannot import name '_gtar' from partially initialized module 'gtar' (most likely due to a circular import) (/disk-samsung/freebsd-ports/science/py-libgetar/work-py39/libgetar-1.1.3/gtar/__init__.py)
____________________________________________________________________________ ERROR collecting test/test_record.py ____________________________________________________________________________
ImportError while importing test module '/disk-samsung/freebsd-ports/science/py-libgetar/work-py39/libgetar-1.1.3/test/test_record.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)
test/test_record.py:3: in <module>
    import gtar
gtar/__init__.py:2: in <module>
    from . import _gtar
E   ImportError: cannot import name '_gtar' from partially initialized module 'gtar' (most likely due to a circular import) (/disk-samsung/freebsd-ports/science/py-libgetar/work-py39/libgetar-1.1.3/gtar/__init__.py)
____________________________________________________________________________ ERROR collecting test/test_widths.py ____________________________________________________________________________
ImportError while importing test module '/disk-samsung/freebsd-ports/science/py-libgetar/work-py39/libgetar-1.1.3/test/test_widths.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)
test/test_widths.py:2: in <module>
    import gtar
gtar/__init__.py:2: in <module>
    from . import _gtar
E   ImportError: cannot import name '_gtar' from partially initialized module 'gtar' (most likely due to a circular import) (/disk-samsung/freebsd-ports/science/py-libgetar/work-py39/libgetar-1.1.3/gtar/__init__.py)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 3 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
===================================================================================== 3 errors in 0.67s ======================================================================================
*** Error code 2
@klarh
Copy link
Collaborator

klarh commented Jun 27, 2022

This looks like the source directory is trying to be directly imported as the library. Since this library uses a python C extension for most of the heavy lifting, the extension needs to be compiled (typically by just using pip or, alternatively, the setup.py directly). Assuming this is the case, could you try installing the library first?

@yurivict
Copy link
Author

Is testing done simply with python -c 'import gtar' or is there a testsuit?

@klarh
Copy link
Collaborator

klarh commented Jun 27, 2022

You can run the tests with python -m unittest discover from the test directory. As a side note, to potentially help with this issue for future users, I've added a section to the documentation at https://libgetar.readthedocs.io/en/latest/issues.html#importerror-cannot-import-name-gtar-from-partially-initialized-module-gtar (since commit 3a46585).

@yurivict
Copy link
Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants