diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..9d6dfc5 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 4.2) +project(j7s_diagnostics_py) + +find_package(ament_cmake REQUIRED) + +add_custom_target(build_info ALL) +add_custom_command(TARGET build_info + POST_BUILD + COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/build.py --install-path ${CMAKE_INSTALL_PREFIX} --build-dir ${PROJECT_BINARY_DIR} --src-dir ${CMAKE_CURRENT_SOURCE_DIR} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} +) + +ament_package() diff --git a/build.py b/build.py new file mode 100755 index 0000000..5632bac --- /dev/null +++ b/build.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python3 +# +# Copyright 2026 James Pace +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at https://mozilla.org/MPL/2.0/. +# +# This Source Code Form is "Incompatible With Secondary Licenses", as +# defined by the Mozilla Public License, v. 2.0. +# +import argparse +import subprocess +import venv +from pathlib import Path + +# The build for this is a little funky. +# Maturin only plays nice with pyproject.toml style configs. +# ROS2 is the opposite. +# So... We setup an venv, pip install into it (which plays nice with pyproject.toml). +# Then we copy the result to the right place for ament/ros2. + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("--src-dir", type=str) + parser.add_argument("--build-dir", type=str) + parser.add_argument("--install-path", type=str) + args = parser.parse_args() + + build(args.src_dir, args.build_dir, args.install_path) + +def build(source_directory, build_directory, install_directory): + # Make a venv in the build_directory. + builder = venv.EnvBuilder(system_site_packages=True, with_pip=True, prompt="") + venv_directory = Path(build_directory) / "venv" + builder.create(venv_directory) + + # activate it and call pip install. + command = f". {venv_directory}/bin/activate && pip install {source_directory}" + subprocess.run(command, shell=True) + + # copy the result to the install directory. + command = f"cp -r {venv_directory}/lib {install_directory}" + subprocess.run(command, shell=True) + + +if __name__ == "__main__": + main() diff --git a/package.xml b/package.xml new file mode 100644 index 0000000..cd254e8 --- /dev/null +++ b/package.xml @@ -0,0 +1,16 @@ + + + + j7s_diagnostics_py + 0.0.1 + TODO + MPL 2.0 + James Pace + James Pace + + ament_cmake + + + ament_cmake + + diff --git a/src/lib.rs b/src/lib.rs index 3dc7c5f..754e496 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,7 +3,6 @@ use pyo3::prelude::*; use pyo3::types::{PyDict, PyString}; use std::collections::BTreeMap; -/// A Python module implemented in Rust. #[pymodule] mod j7s_diagnostics_py { #[pymodule_export]