diff --git a/generate_stubs.py b/generate_stubs.py index 3c21e1287..66386b4c9 100644 --- a/generate_stubs.py +++ b/generate_stubs.py @@ -47,7 +47,9 @@ ) import typing - import json + json = dict + from pathlib import Path + from typing import Set ''') + contents # Create 'create' overloads @@ -59,20 +61,46 @@ # Writeout changes file.seek(0) + file.truncate(0) + file.write(final_stubs) + + # node fixes + with open(f'{DIRECTORY}/depthai/node.pyi' ,'r+') as file: + # Read + contents = file.read() + + # Add imports + stubs_import = textwrap.dedent(''' + from pathlib import Path + from typing import Set + ''') + contents + + # Remove import depthai.* + final_stubs = re.sub(r"import depthai\.\S*", "", stubs_import) + + # Writeout changes + file.seek(0) + file.truncate(0) file.write(final_stubs) # Flush previous stdout sys.stdout.flush() - # Check syntax + # Check syntax (Mypy and later Pylance/Pyright) # Windows limitation - another process cannot normally read temporary file that is opened by this process # Close first and delete manually afterwards - config = tempfile.NamedTemporaryFile(mode='w', delete=False) - config.write('[mypy]\nignore_errors = True\n') - config.close() - print(f'Mypy config file: {config.name}') - subprocess.check_call([sys.executable, '-m' 'mypy', f'{DIRECTORY}/{MODULE_NAME}', f'--config-file={config.name}'], env=env) - os.unlink(config.name) + try: + config = tempfile.NamedTemporaryFile(mode='w', delete=False) + config.write('[mypy]\nignore_errors = True\n') + config.close() + print(f'Mypy config file: {config.name}') + # Mypy check + subprocess.check_call([sys.executable, '-m' 'mypy', f'{DIRECTORY}/{MODULE_NAME}', f'--config-file={config.name}'], env=env) + finally: + os.unlink(config.name) + + # # TODO(thamarpe) - Pylance / Pyright check + # subprocess.check_call([sys.executable, '-m' 'pyright', f'{DIRECTORY}/{MODULE_NAME}'], env=env) except subprocess.CalledProcessError as err: exit(err.returncode) diff --git a/src/XLinkBindings.cpp b/src/XLinkBindings.cpp index 7e8caaedc..080a0deb8 100644 --- a/src/XLinkBindings.cpp +++ b/src/XLinkBindings.cpp @@ -20,6 +20,7 @@ void XLinkBindings::bind(pybind11::module &m, void *pCallstack) py::enum_ xLinkDeviceState(m, "XLinkDeviceState"); py::enum_ xLinkProtocol(m, "XLinkProtocol"); py::enum_ xLinkPlatform(m, "XLinkPlatform"); + py::enum_ xLinkError(m, "XLinkError_t"); py::class_ > xLinkConnection(m, "XLinkConnection", DOC(dai, XLinkConnection)); // pybind11 limitation of having actual classes as exceptions @@ -138,6 +139,26 @@ void XLinkBindings::bind(pybind11::module &m, void *pCallstack) .def_static("bootBootloader", &XLinkConnection::bootBootloader, py::arg("devInfo")) ; + xLinkError + .value("X_LINK_SUCCESS", X_LINK_SUCCESS) + .value("X_LINK_ALREADY_OPEN", X_LINK_ALREADY_OPEN) + .value("X_LINK_COMMUNICATION_NOT_OPEN", X_LINK_COMMUNICATION_NOT_OPEN) + .value("X_LINK_COMMUNICATION_FAIL", X_LINK_COMMUNICATION_FAIL) + .value("X_LINK_COMMUNICATION_UNKNOWN_ERROR", X_LINK_COMMUNICATION_UNKNOWN_ERROR) + .value("X_LINK_DEVICE_NOT_FOUND", X_LINK_DEVICE_NOT_FOUND) + .value("X_LINK_TIMEOUT", X_LINK_TIMEOUT) + .value("X_LINK_ERROR", X_LINK_ERROR) + .value("X_LINK_OUT_OF_MEMORY", X_LINK_OUT_OF_MEMORY) + .value("X_LINK_INSUFFICIENT_PERMISSIONS", X_LINK_INSUFFICIENT_PERMISSIONS) + .value("X_LINK_DEVICE_ALREADY_IN_USE", X_LINK_DEVICE_ALREADY_IN_USE) + .value("X_LINK_NOT_IMPLEMENTED", X_LINK_NOT_IMPLEMENTED) + .value("X_LINK_INIT_USB_ERROR", X_LINK_INIT_USB_ERROR) + .value("X_LINK_INIT_TCP_IP_ERROR", X_LINK_INIT_TCP_IP_ERROR) + .value("X_LINK_INIT_PCIE_ERROR", X_LINK_INIT_PCIE_ERROR) + .export_values() + ; + + //// Exceptions // Applicable if above pybind11 limitation is removed