μHAL (v2.8.22)
Part of the IPbus software repository
Loading...
Searching...
No Matches
version.cpp
Go to the documentation of this file.
2
3#include "pybind11/stl.h" // Automatically adds converters for STL collection/map classes
4#include "pybind11/pybind11.h"
5
6#include "uhal/version.hpp"
7
8
9// Define `boost::variant` type caster, for C++ to Python conversion.
10// Copied from pybind11 docs - https://pybind11.readthedocs.io/en/stable/advanced/cast/stl.html
11namespace PYBIND11_NAMESPACE { namespace detail {
12 template <typename... Ts>
13 struct type_caster<boost::variant<Ts...>> : variant_caster<boost::variant<Ts...>> {};
14
15 // Specifies the function used to visit the variant -- `apply_visitor` instead of `visit`
16 template <>
17 struct visit_helper<boost::variant> {
18 template <typename... Args>
19 static auto call(Args &&...args) -> decltype(boost::apply_visitor(args...)) {
20 return boost::apply_visitor(args...);
21 }
22 };
23}} // namespace PYBIND11_NAMESPACE::detail
24
25// Define optional-type type_caster for boost::optional
26namespace pybind11 {
27namespace detail {
28template <typename T>
29struct type_caster<boost::optional<T>> : optional_caster<boost::optional<T>> {};
30}
31}
32
33
34namespace py = pybind11;
35
36void pycohal::wrap_version_and_build_info(pybind11::module_& aModule)
37{
39
40 auto packageInfoClass = py::class_<PackageInfo>(aModule, "PackageInfo");
41
42 py::class_<PackageInfo::Version>(packageInfoClass, "Version")
43 .def_readonly("major", &PackageInfo::Version::major)
44 .def_readonly("minor", &PackageInfo::Version::minor)
45 .def_readonly("patch", &PackageInfo::Version::patch)
46 .def_readonly("prerelease", &PackageInfo::Version::prerelease);
47
48 auto gitInfoClass = py::class_<PackageInfo::Git>(packageInfoClass, "Git");
49 py::enum_<PackageInfo::Git::RefType>(gitInfoClass, "RefType")
50 .value("Tag", PackageInfo::Git::kTag)
51 .value("Branch", PackageInfo::Git::kBranch)
52 .export_values();
53
54 gitInfoClass
55 .def_readonly("sha", &PackageInfo::Git::sha)
56 .def_readonly("clean", &PackageInfo::Git::clean)
57 .def_readonly("ref", &PackageInfo::Git::ref);
58
59 py::class_<PackageInfo::LocalBuild>(packageInfoClass, "LocalBuild")
60 .def_readonly("_epochTime", &PackageInfo::LocalBuild::epochTime)
61 .def_readonly("hostname", &PackageInfo::LocalBuild::hostname)
62 .def_readonly("username", &PackageInfo::LocalBuild::username);
63
64 py::class_<PackageInfo::GitLabBuild>(packageInfoClass, "GitLabBuild")
65 .def_readonly("_epochTime", &PackageInfo::GitLabBuild::epochTime)
66 .def_readonly("serverURL", &PackageInfo::GitLabBuild::serverURL)
67 .def_readonly("projectPath", &PackageInfo::GitLabBuild::projectPath)
68 .def_readonly("projectID", &PackageInfo::GitLabBuild::projectID)
69 .def_readonly("pipelineID", &PackageInfo::GitLabBuild::pipelineID)
70 .def_readonly("jobID", &PackageInfo::GitLabBuild::jobID);
71
72 packageInfoClass
73 .def_readonly("version", &PackageInfo::version)
74 .def_readonly("vcs", &PackageInfo::vcs)
75 .def_readonly("build", &PackageInfo::build);
76
77 aModule.def("getVersion", &uhal::getVersion);
78 aModule.def("getPackageInfo", &uhal::getPackageInfo);
79}
Definition: pytypes.h:1776
void wrap_version_and_build_info(pybind11::module_ &)
Definition: version.cpp:36
const PackageInfo & getPackageInfo()
Definition: version.cpp:64
const PackageInfo::Version & getVersion()
Definition: version.cpp:58
static auto call(Args &&...args) -> decltype(boost::apply_visitor(args...))
Definition: version.cpp:19
Generic variant caster.
Definition: stl.h:365
Helper class which abstracts away variant's visit function.
Definition: stl.h:356