From 42cd9aedca5834577d122a6f2eba3dcd0730c7d6 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Wed, 18 Oct 2023 16:06:09 -0400 Subject: [PATCH] initial implementation --- CMakeLists.txt | 43 +++++++++++++++++++++++++++++++ EXAMPLES | 9 +++++++ cmake/xo_pywebutilConfig.cmake.in | 4 +++ include/README.md | 1 + src/pywebutil/CMakeLists.txt | 7 +++++ src/pywebutil/pywebutil.cpp | 34 ++++++++++++++++++++++++ src/pywebutil/pywebutil.hpp.in | 25 ++++++++++++++++++ 7 files changed, 123 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 EXAMPLES create mode 100644 cmake/xo_pywebutilConfig.cmake.in create mode 100644 include/README.md create mode 100644 src/pywebutil/CMakeLists.txt create mode 100644 src/pywebutil/pywebutil.cpp create mode 100644 src/pywebutil/pywebutil.hpp.in diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..ed35dc91 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,43 @@ +# xo-pywebutil/CMakeLists.txt + +cmake_minimum_required(VERSION 3.10) + +project(xo_pywebutil VERSION 0.1) +enable_language(CXX) + +# common XO cmake macros (see github.com:Rconybea/xo-cmake) +include(xo_macros/xo_cxx) +include(xo_macros/code-coverage) + +# ---------------------------------------------------------------- +# unit test setup + +enable_testing() +# activate code coverage for all executables + libraries (when configured with -DCODE_COVERAGE=ON) +add_code_coverage() +# 1. assuming that /nix/store/ prefixes .hpp files belonging to gcc, catch2 etc. +# we're not interested in code coverage for these sources. +# 2. exclude the utest/ subdir, we don't need coverage on the unit tests themselves; +# rather, want coverage on the code that the unit tests exercise. +# +# NOTE: this seems to work only with the 'ccov-all' target. In particular, doesn't seem to do anything with the 'ccov' target +# +add_code_coverage_all_targets(EXCLUDE /nix/store/* ${PROJECT_SOURCE_DIR}/utest/* ${PROJECT_BINARY_DIR}/local/* ${PROJECT_SOURCE_DIR}/repo/*) + +# ---------------------------------------------------------------- +# c++ settings (usually temporary) + +set(PROJECT_CXX_FLAGS "") +add_definitions(${PROJECT_CXX_FLAGS}) + +xo_toplevel_compile_options() + +# ---------------------------------------------------------------- +# sources + +add_subdirectory(src/pywebutil) + +# ---------------------------------------------------------------- +# provide find_package() support + +xo_export_cmake_config(${PROJECT_NAME} ${PROJECT_VERSION} ${PROJECT_NAME}Targets) diff --git a/EXAMPLES b/EXAMPLES new file mode 100644 index 00000000..a495d316 --- /dev/null +++ b/EXAMPLES @@ -0,0 +1,9 @@ +Creating this pybind11 library to hold low-dependency wrappers +used for interaction between {websock/, pywebsock/} and other subsystems. + +1. This library needs to be a (runtime) dependency of pyxxx libraries that + use reactor::EventStore, for example pyprocess/, to supply wrappers + for EndpointDescr and Alist. + +2. If we chose to put this code in pywebsock/, then pywebsock + libwebsocket + would become runtime dependencies of libraries like pyprocess/. diff --git a/cmake/xo_pywebutilConfig.cmake.in b/cmake/xo_pywebutilConfig.cmake.in new file mode 100644 index 00000000..9c15f36a --- /dev/null +++ b/cmake/xo_pywebutilConfig.cmake.in @@ -0,0 +1,4 @@ +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") +check_required_components("@PROJECT_NAME@") diff --git a/include/README.md b/include/README.md new file mode 100644 index 00000000..3df846f2 --- /dev/null +++ b/include/README.md @@ -0,0 +1 @@ +placeholder for future pywebutil #include files diff --git a/src/pywebutil/CMakeLists.txt b/src/pywebutil/CMakeLists.txt new file mode 100644 index 00000000..0a8dc225 --- /dev/null +++ b/src/pywebutil/CMakeLists.txt @@ -0,0 +1,7 @@ +# xo-pywebutil/src/pywebutil/CMakeLists.txt + +set(SELF_LIB pywebutil) +set(SELF_SRCS pywebutil.cpp) + +xo_pybind11_library(${SELF_LIB} ${PROJECT_NAME}Targets ${SELF_SRCS}) +xo_pybind11_dependency(${SELF_LIB} webutil) diff --git a/src/pywebutil/pywebutil.cpp b/src/pywebutil/pywebutil.cpp new file mode 100644 index 00000000..dbaa8ef6 --- /dev/null +++ b/src/pywebutil/pywebutil.cpp @@ -0,0 +1,34 @@ +/* @file pywebutil.cpp */ + +#include "pywebutil.hpp" +#include "xo/webutil/HttpEndpointDescr.hpp" +#include "xo/webutil/StreamEndpointDescr.hpp" +#include "xo/pyutil/pyutil.hpp" +#include + +namespace xo { + //using xo::web::Alist; + using xo::web::HttpEndpointDescr; + using xo::ref::rp; + //using xo::time::utc_nanos; + namespace py = pybind11; + + namespace web { + PYBIND11_MODULE(PYWEBUTIL_MODULE_NAME(), m) { + //PYxxx_IMPORT_MODULE(); + + /* module docstring */ + m.doc() = "pybind11 plugin for xo.web_util"; + + py::class_(m, "EndpointDescr") + .def_property_readonly("uri_pattern", &HttpEndpointDescr::uri_pattern) + .def("__repr__", &HttpEndpointDescr::display_string); + + py::class_(m, "StreamEndpointDescr") + .def_property_readonly("uri_pattern", &StreamEndpointDescr::uri_pattern) + .def("__repr__", &StreamEndpointDescr::display_string); + } /*web*/ + } /*namespace web*/ +} /*namespace xo*/ + +/* end pywebutil.cpp */ diff --git a/src/pywebutil/pywebutil.hpp.in b/src/pywebutil/pywebutil.hpp.in new file mode 100644 index 00000000..086701c1 --- /dev/null +++ b/src/pywebutil/pywebutil.hpp.in @@ -0,0 +1,25 @@ +/* @file pywebutil.hpp + * + * automatically generated from src/pywebutil/pywebutil.hpp.in + * see src/pywebutil/CMakeLists.txt + */ + +/* python requires module name = library name + * example: + * PYBIND11_MODULE(PYWEBUTIL_MODULE_NAME(), m) { ... } + */ +#define PYWEBUTIL_MODULE_NAME() @SELF_LIB@ + +/* example: + * py::module_::import(PYWEBUTIL_MODULE_NAME_STR) + */ +#define PYWEBUTIL_MODULE_NAME_STR "@SELF_LIB@" + +/* example: + * PYWEBUTIL_IMPORT_MODULE() + * replaces + * py::module_::import("pywebutil") + */ +#define PYWEBUTIL_IMPORT_MODULE() py::module_::import("@SELF_LIB@") + +/* end pywebutil.hpp */