brainvisa/brainvisa-cmake

Syntax error in Python makes user image creation fail

Closed this issue · 3 comments

When a Python file has a syntax error, the corresponding *.pyc file is not generated and the install step fails during user image creation. This may be a good behavior for release images but non final user images are used to launch tests. No test at all can be started (in user environment).

I'm looking at this long-forgotten ticket, and it appears that installation of .pyc files is broken anyway in brainvisa-cmake + python3:

  • for pure python components I think nothing is done: either you have run your python modules and the .pyc files are generated "naturally", or they are not here at all. Install will not copy them at all. ex:
    cd /casa/host/build
    make install-capsul BRAINVISA_INSTALL_PREFIX=/casa/host/install
    ls /casa/host/install/python/capsul/pipeline
    
    _init__.py   pipeline.py               pipeline_tools.py     python_export.py     xml.py
    custom_nodes  pipeline_construction.py  pipeline_workflow.py  test
    json_io.py    pipeline_nodes.py         process_iteration.py  topological_sort.py
    
    (no __pycache__ at all)
  • for non-pure-python components, .pyc files are actually generated at their correct location, but install will copy them at the wrong place, that is outside of the __pycache__ directory. If a __pycache__ dir exists, it will be copied as-is in addition to other files, meaning that potentially non-up-to-date .pyc files will get used, and additional, spurious files (like those built for other python versions) will be copied too. ex:
    make install-axon BRAINVISA_INSTALL_PREFIX=/casa/host/install
    ls /casa/host/install/python/brainvisa/axon/
    
    __init__.cpython-310.opt-1.pyc   processes.cpython-310.pyc          processinfo.py
    __init__.cpython-310.pyc         processes.py                       runprocess.cpython-310.opt-1.pyc
    __init__.py                      processinfo.cpython-310.opt-1.pyc  runprocess.cpython-310.pyc
    processes.cpython-310.opt-1.pyc  processinfo.cpython-310.pyc        runprocess.py
    
    (no __pycache__).
  • But in a situation I cannot determine, after install, I have an additional __pycache__ dir which is an exact copy of the one in the build tree.
  • Anyway I don't know how (if it is ever possible) to make a cmake INSTALL() optional... ?

For the last point, the cmake INSTALL() command has an OPTIONAL flag that seem to be what we need :)

Now .pyc files generation is not fatal any longer, thus a project with syntax errors in python files will not prevent all other projects to build or be tested. However this .pyc generation will not be tested, at the end, so it's not always what we want also. But we cannot have both...