PyCyphal v1.10 supports automatic DSDL compilation via import hooks

Rejoice! Where you used to say this:

import pyuavcan
compiled_dsdl_dir = pathlib.Path(__file__).resolve().parent / ".demo_dsdl_compiled"
sys.path.insert(0, str(compiled_dsdl_dir))
try:
    import sirius_cyber_corp
    import pyuavcan.application
except (ImportError, AttributeError):
    src_dir = pathlib.Path(__file__).resolve().parent
    pyuavcan.dsdl.compile_all(
        [
            src_dir / "custom_data_types/sirius_cyber_corp",
            src_dir / "public_regulated_data_types/uavcan/",
        ],
        output_directory=compiled_dsdl_dir,
    )
    importlib.invalidate_caches()
    import sirius_cyber_corp
    import pyuavcan.application

Now you simply say this:

import pyuavcan.application
import sirius_cyber_corp

DSDL namespaces are now compiled automatically as necessary. The search paths are set via the environment variable CYPHAL_PATH, which works like the standard PATH, listing the directories where DSDL namespaces are looked up from. The generated Python packages are stored in PYCYPHAL_PATH, the default is ~/.pycyphal.

Yakut will soon be upgraded to remove the compile command completely since it is no longer necessary.

This feature was brought to us by @chemicstry, thanks Jurgis!

2 Likes