Impossibility to test for coverage in extensions

I am trying to test the coverage in my extension. This is easily performed by
pytest --cov-report term --cov=Dosimetry4D

However this results in

$ pytest --cov-report term --cov=Dosimetry4D
Failed to import the site module
Traceback (most recent call last):
  File "/usr/src/Slicer-build/python-install/lib/python3.6/site.py", line 553, in <module>
    main()
  File "/usr/src/Slicer-build/python-install/lib/python3.6/site.py", line 539, in main
    known_paths = addusersitepackages(known_paths)
  File "/usr/src/Slicer-build/python-install/lib/python3.6/site.py", line 282, in addusersitepackages
    user_site = getusersitepackages()
  File "/usr/src/Slicer-build/python-install/lib/python3.6/site.py", line 258, in getusersitepackages
    user_base = getuserbase() # this will also set USER_BASE
  File "/usr/src/Slicer-build/python-install/lib/python3.6/site.py", line 248, in getuserbase
    USER_BASE = get_config_var('userbase')
  File "/usr/src/Slicer-build/python-install/lib/python3.6/sysconfig.py", line 601, in get_config_var
    return get_config_vars().get(name)
  File "/usr/src/Slicer-build/python-install/lib/python3.6/sysconfig.py", line 550, in get_config_vars
    _init_posix(_CONFIG_VARS)
  File "/usr/src/Slicer-build/python-install/lib/python3.6/sysconfig.py", line 421, in _init_posix
    _temp = __import__(name, globals(), locals(), ['build_time_vars'], 0)
ModuleNotFoundError: No module named '_sysconfigdata_m_linux_x86_64-linux-gnu'
ERROR: Job failed: exit code 1
FATAL: exit code 1 

I have found this topic addressing the same issue with python 3.6. This bug is not critical but it is annoying and eventually will raise another bug.

Maybe this is the starting point for you to consider to move to python 3.8. :slight_smile:

For me, attempt to start gdb fails with the same error. From the bug report you referenced, it is not clear for me if this is solved in Python 3.8, but Iā€™m not an experienced Linux user. It would be great if you could investigate this further, for example try to build Slicer with Python 3.8 and see if the problem is fixed.

I tried using python 3.8.5, however the build fails at this point

CMake Error at cmake/libpython/CMakeLists.txt:442 (add_executable):
  Cannot find source file:

    /usr/src/Slicer-build/Python-3.8.5/Parser/bitset.c

  Tried extensions .c .C .c++ .cc .cpp .cxx .cu .m .M .mm .h .hh .h++ .hm
  .hpp .hxx .in .txx


CMake Error at /usr/src/Slicer-build/python-build/CMakeBuild/extensions/extension_ctypes-src/CMakeLists.txt:1 (add_library):
  Cannot find source file:

    /usr/src/Slicer-build/Python-3.8.5/Modules/_ctypes/libffi/src/closures.c

  Tried extensions .c .C .c++ .cc .cpp .cxx .cu .m .M .mm .h .hh .h++ .hm
  .hpp .hxx .in .txx


CMake Error at cmake/libpython/CMakeLists.txt:398 (add_executable):
  Cannot find source file:

    /usr/src/Slicer-build/Python-3.8.5/Modules/zipimport.c

  Tried extensions .c .C .c++ .cc .cpp .cxx .cu .m .M .mm .h .hh .h++ .hm
  .hpp .hxx .in .txx


CMake Error at /usr/src/Slicer-build/python-build/CMakeBuild/extensions/extension_ctypes-src/CMakeLists.txt:1 (add_library):
  No SOURCES given to target: extension_ctypes


CMake Error at cmake/libpython/CMakeLists.txt:398 (add_executable):
  No SOURCES given to target: _freeze_importlib


CMake Error at cmake/libpython/CMakeLists.txt:442 (add_executable):
  No SOURCES given to target: pgen


CMake Error at cmake/libpython/CMakeLists.txt:469 (add_library):
  No SOURCES given to target: libpython-shared
Call Stack (most recent call first):
  cmake/libpython/CMakeLists.txt:505 (add_libpython)


-- Build files have been written to: /usr/src/Slicer-build/python-build
make[2]: *** [python-prefix/src/python-stamp/python-configure] Error 1
make[1]: *** [CMakeFiles/python.dir/all] Error 2
make: *** [all] Error 2

I am trying with the freezed 3.6.12 final version as it is the same 3.6 brand with a frozen final version

To support building Slicer against the CPython 3.7 or 3.8, we would need help to finalize this pull request

In the meanwhile, I am testing Slicer with python 3.6.12 and so far the build is ok, when I tested it I will propose a PR to upgrade to 3.6.12 which is harmless and less traumatic.

The version with python 3.6.12 is running ok in ubuntu and docker. But the issue remains

$ pytest --cov-report term --cov=Dosimetry4D
Failed to import the site module
Traceback (most recent call last):
  File "/usr/src/Slicer-build/python-install/lib/python3.6/site.py", line 553, in <module>
    main()
  File "/usr/src/Slicer-build/python-install/lib/python3.6/site.py", line 539, in main
    known_paths = addusersitepackages(known_paths)
  File "/usr/src/Slicer-build/python-install/lib/python3.6/site.py", line 282, in addusersitepackages
    user_site = getusersitepackages()
  File "/usr/src/Slicer-build/python-install/lib/python3.6/site.py", line 258, in getusersitepackages
    user_base = getuserbase() # this will also set USER_BASE
  File "/usr/src/Slicer-build/python-install/lib/python3.6/site.py", line 248, in getuserbase
    USER_BASE = get_config_var('userbase')
  File "/usr/src/Slicer-build/python-install/lib/python3.6/sysconfig.py", line 601, in get_config_var
    return get_config_vars().get(name)
  File "/usr/src/Slicer-build/python-install/lib/python3.6/sysconfig.py", line 550, in get_config_vars
    _init_posix(_CONFIG_VARS)
  File "/usr/src/Slicer-build/python-install/lib/python3.6/sysconfig.py", line 421, in _init_posix
    _temp = __import__(name, globals(), locals(), ['build_time_vars'], 0)
ModuleNotFoundError: No module named '_sysconfigdata_m_linux_x86_64-linux-gnu'
ERROR: Job failed: exit code 1

I will skip coverage for now.
You can use the docker image at: bishopwolf/slicer3d-nightly:0.4.1

1 Like

Thanks for the update. Does gdb work for you with Slicer (for example, can you launch Slicer using gdb)?

Unfortunately not, but the change from 3.6.7 to 3.6.12 is not supposed to add anything new, just bug corrections.

I have detected if you run ccmake for Slicer build that you have a WITH_COVERAGE variable

image

what is this supposed to do?