Skip to content

Commit

Permalink
Bindings for dai::Path (#557)
Browse files Browse the repository at this point in the history
* Added pytest to CI

* Added a simple test for UTF-8 path support

* Added bindings and changes required for dai::Path
  • Loading branch information
themarpe committed Apr 12, 2022
1 parent eeede59 commit 2affdb3
Show file tree
Hide file tree
Showing 11 changed files with 141 additions and 47 deletions.
54 changes: 53 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,58 @@ jobs:
path: docstrings/
retention-days: 1


# Build and test bindings
pytest:
needs: build-docstrings
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Print home directory
run: echo Home directory inside container $HOME
- uses: actions/checkout@v2
with:
submodules: 'recursive'

- uses: actions/download-artifact@v2
with:
name: 'docstrings'
path: docstrings
- name: Specify docstring to use while building the wheel
run: echo "DEPTHAI_PYTHON_DOCSTRINGS_INPUT=$PWD/docstrings/depthai_python_docstring.hpp" >> $GITHUB_ENV

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: "3.10"

- name: Install dependencies (Ubuntu)
if: matrix.os == 'ubuntu-latest'
run: |
python -m pip install --upgrade pip
sudo apt install libusb-1.0-0-dev
- name: Install dependencies (MacOS)
if: matrix.os == 'macos-latest'
run: |
python -m pip install --upgrade pip
brew install libusb
- name: Install pytest
run: |
python -m pip install pytest numpy
- name: Compile
run: |
cmake -S . -B build -D CMAKE_BUILD_TYPE=Release -D DEPTHAI_PYTHON_DOCSTRINGS_INPUT=$PWD/docstrings/depthai_python_docstring.hpp -D DEPTHAI_PYTHON_ENABLE_TESTS=ON
cmake --build build --parallel 4
- name: Test
run: |
cmake --build build --target pytest
# This job builds wheels for armhf arch (RPi)
build-linux-armhf:
needs: build-docstrings
Expand Down Expand Up @@ -338,7 +390,7 @@ jobs:

release:
if: startsWith(github.ref, 'refs/tags/v')
needs: [build-linux-armhf, build-windows-x86_64, build-macos-x86_64, build-linux-x86_64, build-linux-arm64]
needs: [pytest, build-linux-armhf, build-windows-x86_64, build-macos-x86_64, build-linux-x86_64, build-linux-arm64]
runs-on: ubuntu-latest

steps:
Expand Down
2 changes: 1 addition & 1 deletion depthai-core
4 changes: 2 additions & 2 deletions src/CalibrationHandlerBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ void CalibrationHandlerBindings::bind(pybind11::module& m, void* pCallstack){
// Bindings
calibrationHandler
.def(py::init<>(), DOC(dai, CalibrationHandler, CalibrationHandler))
.def(py::init<std::string>(), DOC(dai, CalibrationHandler, CalibrationHandler, 2))
.def(py::init<std::string, std::string>(), DOC(dai, CalibrationHandler, CalibrationHandler, 3))
.def(py::init<dai::Path>(), DOC(dai, CalibrationHandler, CalibrationHandler, 2))
.def(py::init<dai::Path, dai::Path>(), DOC(dai, CalibrationHandler, CalibrationHandler, 3))
.def(py::init<EepromData>(), DOC(dai, CalibrationHandler, CalibrationHandler, 4))

.def("getEepromData", &CalibrationHandler::getEepromData, DOC(dai, CalibrationHandler, getEepromData))
Expand Down
32 changes: 16 additions & 16 deletions src/DeviceBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,66 +115,66 @@ static void bindConstructors(ARG& arg){
py::gil_scoped_release release;
return std::make_unique<D>(pipeline, dev, maxUsbSpeed);
}), py::arg("pipeline"), py::arg("maxUsbSpeed"), DOC(dai, DeviceBase, DeviceBase, 3))
.def(py::init([](const Pipeline& pipeline, const std::string& pathToCmd){
.def(py::init([](const Pipeline& pipeline, const dai::Path& pathToCmd){
auto dev = deviceSearchHelper<D>();
py::gil_scoped_release release;
return std::make_unique<D>(pipeline, dev, pathToCmd);
}), py::arg("pipeline"), py::arg("pathToCmd"), DOC(dai, DeviceBase, DeviceBase, 4))
.def(py::init([](const Pipeline& pipeline, const DeviceInfo& deviceInfo, bool usb2Mode){
py::gil_scoped_release release;
return std::make_unique<D>(pipeline, deviceInfo, usb2Mode);
}), py::arg("pipeline"), py::arg("devInfo"), py::arg("usb2Mode") = false, DOC(dai, DeviceBase, DeviceBase, 7))
}), py::arg("pipeline"), py::arg("devInfo"), py::arg("usb2Mode") = false, DOC(dai, DeviceBase, DeviceBase, 6))
.def(py::init([](const Pipeline& pipeline, const DeviceInfo& deviceInfo, UsbSpeed maxUsbSpeed){
py::gil_scoped_release release;
return std::make_unique<D>(pipeline, deviceInfo, maxUsbSpeed);
}), py::arg("pipeline"), py::arg("deviceInfo"), py::arg("maxUsbSpeed"), DOC(dai, DeviceBase, DeviceBase, 8))
.def(py::init([](const Pipeline& pipeline, const DeviceInfo& deviceInfo, std::string pathToCmd){
}), py::arg("pipeline"), py::arg("deviceInfo"), py::arg("maxUsbSpeed"), DOC(dai, DeviceBase, DeviceBase, 7))
.def(py::init([](const Pipeline& pipeline, const DeviceInfo& deviceInfo, dai::Path pathToCmd){
py::gil_scoped_release release;
return std::make_unique<D>(pipeline, deviceInfo, pathToCmd);
}), py::arg("pipeline"), py::arg("devInfo"), py::arg("pathToCmd"), DOC(dai, DeviceBase, DeviceBase, 9))
}), py::arg("pipeline"), py::arg("devInfo"), py::arg("pathToCmd"), DOC(dai, DeviceBase, DeviceBase, 8))

// DeviceBase constructor - OpenVINO version
.def(py::init([](OpenVINO::Version version){
auto dev = deviceSearchHelper<D>();
py::gil_scoped_release release;
return std::make_unique<D>(version, dev);
}), py::arg("version") = OpenVINO::DEFAULT_VERSION, DOC(dai, DeviceBase, DeviceBase, 11))
}), py::arg("version") = OpenVINO::DEFAULT_VERSION, DOC(dai, DeviceBase, DeviceBase, 10))
.def(py::init([](OpenVINO::Version version, bool usb2Mode){
auto dev = deviceSearchHelper<D>();
py::gil_scoped_release release;
return std::make_unique<D>(version, dev, usb2Mode);
}), py::arg("version"), py::arg("usb2Mode") = false, DOC(dai, DeviceBase, DeviceBase, 13))
}), py::arg("version"), py::arg("usb2Mode") = false, DOC(dai, DeviceBase, DeviceBase, 11))
.def(py::init([](OpenVINO::Version version, UsbSpeed maxUsbSpeed){
auto dev = deviceSearchHelper<D>();
py::gil_scoped_release release;
return std::make_unique<D>(version, dev, maxUsbSpeed);
}), py::arg("version"), py::arg("maxUsbSpeed"), DOC(dai, DeviceBase, DeviceBase, 14))
.def(py::init([](OpenVINO::Version version, const std::string& pathToCmd){
}), py::arg("version"), py::arg("maxUsbSpeed"), DOC(dai, DeviceBase, DeviceBase, 12))
.def(py::init([](OpenVINO::Version version, const dai::Path& pathToCmd){
auto dev = deviceSearchHelper<D>();
py::gil_scoped_release release;
return std::make_unique<D>(version, dev, pathToCmd);
}), py::arg("version"), py::arg("pathToCmd"), DOC(dai, DeviceBase, DeviceBase, 15))
}), py::arg("version"), py::arg("pathToCmd"), DOC(dai, DeviceBase, DeviceBase, 13))
.def(py::init([](OpenVINO::Version version, const DeviceInfo& deviceInfo, bool usb2Mode){
py::gil_scoped_release release;
return std::make_unique<D>(version, deviceInfo, usb2Mode);
}), py::arg("version"), py::arg("deviceDesc"), py::arg("usb2Mode") = false, DOC(dai, DeviceBase, DeviceBase, 18))
}), py::arg("version"), py::arg("deviceDesc"), py::arg("usb2Mode") = false, DOC(dai, DeviceBase, DeviceBase, 15))
.def(py::init([](OpenVINO::Version version, const DeviceInfo& deviceInfo, UsbSpeed maxUsbSpeed){
py::gil_scoped_release release;
return std::make_unique<D>(version, deviceInfo, maxUsbSpeed);
}), py::arg("version"), py::arg("deviceInfo"), py::arg("maxUsbSpeed"), DOC(dai, DeviceBase, DeviceBase, 19))
.def(py::init([](OpenVINO::Version version, const DeviceInfo& deviceInfo, std::string pathToCmd){
}), py::arg("version"), py::arg("deviceInfo"), py::arg("maxUsbSpeed"), DOC(dai, DeviceBase, DeviceBase, 16))
.def(py::init([](OpenVINO::Version version, const DeviceInfo& deviceInfo, dai::Path pathToCmd){
py::gil_scoped_release release;
return std::make_unique<D>(version, deviceInfo, pathToCmd);
}), py::arg("version"), py::arg("deviceDesc"), py::arg("pathToCmd"), DOC(dai, DeviceBase, DeviceBase, 20))
}), py::arg("version"), py::arg("deviceDesc"), py::arg("pathToCmd"), DOC(dai, DeviceBase, DeviceBase, 17))
.def(py::init([](typename D::Config config){
auto dev = deviceSearchHelper<D>();
py::gil_scoped_release release;
return std::make_unique<D>(config, dev);
}), py::arg("config"), DOC(dai, DeviceBase, DeviceBase, 22))
}), py::arg("config"), DOC(dai, DeviceBase, DeviceBase, 18))
.def(py::init([](typename D::Config config, const DeviceInfo& deviceInfo){
py::gil_scoped_release release;
return std::make_unique<D>(config, deviceInfo);
}), py::arg("config"), py::arg("deviceInfo"), DOC(dai, DeviceBase, DeviceBase, 23))
}), py::arg("config"), py::arg("deviceInfo"), DOC(dai, DeviceBase, DeviceBase, 19))
;

}
Expand Down
14 changes: 7 additions & 7 deletions src/DeviceBootloaderBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,25 +116,25 @@ void DeviceBootloaderBindings::bind(pybind11::module& m, void* pCallstack){

.def_static("getFirstAvailableDevice", &DeviceBootloader::getFirstAvailableDevice, DOC(dai, DeviceBootloader, getFirstAvailableDevice))
.def_static("getAllAvailableDevices", &DeviceBootloader::getAllAvailableDevices, DOC(dai, DeviceBootloader, getAllAvailableDevices))
.def_static("saveDepthaiApplicationPackage", py::overload_cast<std::string, const Pipeline&, std::string, bool>(&DeviceBootloader::saveDepthaiApplicationPackage), py::arg("path"), py::arg("pipeline"), py::arg("pathToCmd") = "", py::arg("compress") = false, DOC(dai, DeviceBootloader, saveDepthaiApplicationPackage))
.def_static("saveDepthaiApplicationPackage", py::overload_cast<std::string, const Pipeline&, bool>(&DeviceBootloader::saveDepthaiApplicationPackage), py::arg("path"), py::arg("pipeline"), py::arg("compress"), DOC(dai, DeviceBootloader, saveDepthaiApplicationPackage, 2))
.def_static("createDepthaiApplicationPackage", py::overload_cast<const Pipeline&, std::string, bool>(&DeviceBootloader::createDepthaiApplicationPackage), py::arg("pipeline"), py::arg("pathToCmd") = "", py::arg("compress") = false, DOC(dai, DeviceBootloader, createDepthaiApplicationPackage))
.def_static("saveDepthaiApplicationPackage", py::overload_cast<const Path&, const Pipeline&, const Path&, bool>(&DeviceBootloader::saveDepthaiApplicationPackage), py::arg("path"), py::arg("pipeline"), py::arg("pathToCmd") = Path{}, py::arg("compress") = false, DOC(dai, DeviceBootloader, saveDepthaiApplicationPackage))
.def_static("saveDepthaiApplicationPackage", py::overload_cast<const Path&, const Pipeline&, bool>(&DeviceBootloader::saveDepthaiApplicationPackage), py::arg("path"), py::arg("pipeline"), py::arg("compress"), DOC(dai, DeviceBootloader, saveDepthaiApplicationPackage, 2))
.def_static("createDepthaiApplicationPackage", py::overload_cast<const Pipeline&, const Path&, bool>(&DeviceBootloader::createDepthaiApplicationPackage), py::arg("pipeline"), py::arg("pathToCmd") = Path{}, py::arg("compress") = false, DOC(dai, DeviceBootloader, createDepthaiApplicationPackage))
.def_static("createDepthaiApplicationPackage", py::overload_cast<const Pipeline&, bool>(&DeviceBootloader::createDepthaiApplicationPackage), py::arg("pipeline"), py::arg("compress"), DOC(dai, DeviceBootloader, createDepthaiApplicationPackage, 2))
.def_static("getEmbeddedBootloaderVersion", &DeviceBootloader::getEmbeddedBootloaderVersion, DOC(dai, DeviceBootloader, getEmbeddedBootloaderVersion))
.def_static("getEmbeddedBootloaderBinary", &DeviceBootloader::getEmbeddedBootloaderBinary, DOC(dai, DeviceBootloader, getEmbeddedBootloaderBinary))

.def(py::init<const DeviceInfo&, bool>(), py::arg("devInfo"), py::arg("allowFlashingBootloader") = false, DOC(dai, DeviceBootloader, DeviceBootloader))
.def(py::init<const DeviceInfo&, std::string, bool>(), py::arg("devInfo"), py::arg("pathToCmd"), py::arg("allowFlashingBootloader") = false, DOC(dai, DeviceBootloader, DeviceBootloader, 2))
.def(py::init<const DeviceInfo&, const Path&, bool>(), py::arg("devInfo"), py::arg("pathToCmd"), py::arg("allowFlashingBootloader") = false, DOC(dai, DeviceBootloader, DeviceBootloader, 2))
.def("flash", [](DeviceBootloader& db, std::function<void(float)> progressCallback, const Pipeline& pipeline, bool compress) { py::gil_scoped_release release; return db.flash(progressCallback, pipeline, compress); }, py::arg("progressCallback"), py::arg("pipeline"), py::arg("compress") = false, DOC(dai, DeviceBootloader, flash))
.def("flash", [](DeviceBootloader& db, const Pipeline& pipeline, bool compress) { py::gil_scoped_release release; return db.flash(pipeline, compress); }, py::arg("pipeline"), py::arg("compress") = false, DOC(dai, DeviceBootloader, flash, 2))
.def("flashDepthaiApplicationPackage", [](DeviceBootloader& db, std::function<void(float)> progressCallback, std::vector<uint8_t> package) { py::gil_scoped_release release; return db.flashDepthaiApplicationPackage(progressCallback, package); }, py::arg("progressCallback"), py::arg("package"), DOC(dai, DeviceBootloader, flashDepthaiApplicationPackage))
.def("flashDepthaiApplicationPackage", [](DeviceBootloader& db, std::vector<uint8_t> package) { py::gil_scoped_release release; return db.flashDepthaiApplicationPackage(package); }, py::arg("package"), DOC(dai, DeviceBootloader, flashDepthaiApplicationPackage, 2))
.def("flashBootloader", [](DeviceBootloader& db, std::function<void(float)> progressCallback, std::string path) { py::gil_scoped_release release; return db.flashBootloader(progressCallback, path); }, py::arg("progressCallback"), py::arg("path") = "", DOC(dai, DeviceBootloader, flashBootloader))
.def("flashBootloader", [](DeviceBootloader& db, DeviceBootloader::Memory memory, DeviceBootloader::Type type, std::function<void(float)> progressCallback, std::string path) { py::gil_scoped_release release; return db.flashBootloader(memory, type, progressCallback, path); }, py::arg("memory"), py::arg("type"), py::arg("progressCallback"), py::arg("path") = "", DOC(dai, DeviceBootloader, flashBootloader, 2))
.def("flashBootloader", [](DeviceBootloader& db, std::function<void(float)> progressCallback, const Path& path) { py::gil_scoped_release release; return db.flashBootloader(progressCallback, path); }, py::arg("progressCallback"), py::arg("path") = "", DOC(dai, DeviceBootloader, flashBootloader))
.def("flashBootloader", [](DeviceBootloader& db, DeviceBootloader::Memory memory, DeviceBootloader::Type type, std::function<void(float)> progressCallback, dai::Path path) { py::gil_scoped_release release; return db.flashBootloader(memory, type, progressCallback, path); }, py::arg("memory"), py::arg("type"), py::arg("progressCallback"), py::arg("path") = "", DOC(dai, DeviceBootloader, flashBootloader, 2))

.def("readConfigData", [](DeviceBootloader& db, DeviceBootloader::Memory memory, DeviceBootloader::Type type) { py::gil_scoped_release release; return db.readConfigData(memory, type); }, py::arg("memory") = DeviceBootloader::Memory::AUTO, py::arg("type") = DeviceBootloader::Type::AUTO, DOC(dai, DeviceBootloader, readConfigData))
.def("flashConfigData", [](DeviceBootloader& db, nlohmann::json configData, DeviceBootloader::Memory memory, DeviceBootloader::Type type) { py::gil_scoped_release release; return db.flashConfigData(configData, memory, type); }, py::arg("configData"), py::arg("memory") = DeviceBootloader::Memory::AUTO, py::arg("type") = DeviceBootloader::Type::AUTO, DOC(dai, DeviceBootloader, flashConfigData))
.def("flashConfigFile", [](DeviceBootloader& db, std::string configPath, DeviceBootloader::Memory memory, DeviceBootloader::Type type) { py::gil_scoped_release release; return db.flashConfigFile(configPath, memory, type); }, py::arg("configData"), py::arg("memory") = DeviceBootloader::Memory::AUTO, py::arg("type") = DeviceBootloader::Type::AUTO, DOC(dai, DeviceBootloader, flashConfigFile))
.def("flashConfigFile", [](DeviceBootloader& db, dai::Path configPath, DeviceBootloader::Memory memory, DeviceBootloader::Type type) { py::gil_scoped_release release; return db.flashConfigFile(configPath, memory, type); }, py::arg("configData"), py::arg("memory") = DeviceBootloader::Memory::AUTO, py::arg("type") = DeviceBootloader::Type::AUTO, DOC(dai, DeviceBootloader, flashConfigFile))
.def("flashConfigClear", [](DeviceBootloader& db, DeviceBootloader::Memory memory, DeviceBootloader::Type type) { py::gil_scoped_release release; return db.flashConfigClear(memory, type); }, py::arg("memory") = DeviceBootloader::Memory::AUTO, py::arg("type") = DeviceBootloader::Type::AUTO, DOC(dai, DeviceBootloader, flashConfigClear))
.def("readConfig", [](DeviceBootloader& db, DeviceBootloader::Memory memory, DeviceBootloader::Type type) { py::gil_scoped_release release; return db.readConfig(memory, type); }, py::arg("memory") = DeviceBootloader::Memory::AUTO, py::arg("type") = DeviceBootloader::Type::AUTO, DOC(dai, DeviceBootloader, readConfig))
.def("flashConfig", [](DeviceBootloader& db, const DeviceBootloader::Config& config, DeviceBootloader::Memory memory, DeviceBootloader::Type type) { py::gil_scoped_release release; return db.flashConfig(config, memory, type); }, py::arg("config"), py::arg("memory") = DeviceBootloader::Memory::AUTO, py::arg("type") = DeviceBootloader::Type::AUTO, DOC(dai, DeviceBootloader, flashConfig))
Expand Down
2 changes: 1 addition & 1 deletion src/openvino/OpenVINOBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void OpenVINOBindings::bind(pybind11::module& m, void* pCallstack){
// Bind OpenVINO::Blob
openvinoBlob
.def(py::init<std::vector<uint8_t>>(), DOC(dai, OpenVINO, Blob, Blob))
.def(py::init<std::string>(), DOC(dai, OpenVINO, Blob, Blob, 2))
.def(py::init<dai::Path>(), DOC(dai, OpenVINO, Blob, Blob, 2))
.def_readwrite("version", &OpenVINO::Blob::version, DOC(dai, OpenVINO, Blob, version))
.def_readwrite("networkInputs", &OpenVINO::Blob::networkInputs, DOC(dai, OpenVINO, Blob, networkInputs))
.def_readwrite("networkOutputs", &OpenVINO::Blob::networkOutputs, DOC(dai, OpenVINO, Blob, networkOutputs))
Expand Down
2 changes: 1 addition & 1 deletion src/pipeline/AssetManagerBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void AssetManagerBindings::bind(pybind11::module& m, void* pCallstack){
.def("addExisting", &AssetManager::addExisting, py::arg("assets"), DOC(dai, AssetManager, addExisting))
.def("set", static_cast<std::shared_ptr<dai::Asset> (AssetManager::*)(Asset)>(&AssetManager::set), py::arg("asset"), DOC(dai, AssetManager, set))
.def("set", static_cast<std::shared_ptr<dai::Asset> (AssetManager::*)(const std::string&, Asset)>(&AssetManager::set), py::arg("key"), py::arg("asset"), DOC(dai, AssetManager, set, 2))
.def("set", static_cast<std::shared_ptr<dai::Asset> (AssetManager::*)(const std::string& key, const std::string& path, int alignment)>(&AssetManager::set), py::arg("key"), py::arg("path"), py::arg("alignment") = 64, DOC(dai, AssetManager, set, 3))
.def("set", static_cast<std::shared_ptr<dai::Asset> (AssetManager::*)(const std::string& key, const dai::Path& path, int alignment)>(&AssetManager::set), py::arg("key"), py::arg("path"), py::arg("alignment") = 64, DOC(dai, AssetManager, set, 3))
.def("set", static_cast<std::shared_ptr<dai::Asset> (AssetManager::*)(const std::string& key, const std::vector<std::uint8_t>& data, int alignment)>(&AssetManager::set), py::arg("key"), py::arg("data"), py::arg("alignment") = 64, DOC(dai, AssetManager, set, 4))
.def("get", static_cast<std::shared_ptr<const Asset> (AssetManager::*)(const std::string&) const>(&AssetManager::get), py::arg("key"), DOC(dai, AssetManager, get))
.def("get", static_cast<std::shared_ptr<Asset> (AssetManager::*)(const std::string&)>(&AssetManager::get), py::arg("key"), DOC(dai, AssetManager, get, 2))
Expand Down
Loading

0 comments on commit 2affdb3

Please sign in to comment.