From 401467c7008462bd01e86875fcd7b5955b6e879f Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Wed, 16 Mar 2022 18:29:33 +0100 Subject: [PATCH] updated scripts and generated detector.cpp --- python/scripts/generate_functions.py | 22 +++++++++++----------- python/scripts/parse.py | 6 ++++++ python/src/detector.cpp | 17 ++++++----------- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/python/scripts/generate_functions.py b/python/scripts/generate_functions.py index 242cd2bb3..bf943330a 100644 --- a/python/scripts/generate_functions.py +++ b/python/scripts/generate_functions.py @@ -11,9 +11,17 @@ manually from clang import cindex import subprocess import argparse +import sys +from parse import system_include_paths, clang_format_version + +required_version = 13 +RED = '\033[91m' +ENDC = '\033[0m' +if (ver := clang_format_version()) != required_version: + print(f'{RED}Clang format version {required_version} required, detected: {ver}. Bye!{ENDC}') + sys.exit(1) -from parse import system_include_paths default_build_path = "/home/l_frojdh/sls/build/" fpath = "../../slsDetectorSoftware/src/Detector.cpp" @@ -66,7 +74,7 @@ def get_arguments_with_default(node): args = [] for arg in node.get_arguments(): tokens = [t.spelling for t in arg.get_tokens()] - print(tokens) + # print(tokens) if '=' in tokens: if arg.type.spelling == "sls::Positions": #TODO! automate args.append("py::arg() = Positions{}") @@ -111,19 +119,11 @@ def visit(node): lines.append( f'.def("{child.spelling}",{fs} &Detector::{child.spelling}{args})' ) + print(f'&Detector::{child.spelling}{args})') cn.append(child) for child in node.get_children(): visit(child) - # .def("setRxHostname", - # (void (Detector::*)(const std::string &, Positions)) & - # Detector::setRxHostname, - # py::arg(), py::arg() = Positions{}) - # .def("setRxHostname", - # (void (Detector::*)(const std::vector &)) & - # Detector::setRxHostname, - # py::arg()) - visit(tu.cursor) diff --git a/python/scripts/parse.py b/python/scripts/parse.py index 310a6af36..19dd8d4d3 100644 --- a/python/scripts/parse.py +++ b/python/scripts/parse.py @@ -5,6 +5,12 @@ import subprocess from subprocess import PIPE import os +def clang_format_version(): + p = subprocess.run(['clang-format', '--version'], capture_output = True) + ver = p.stdout.decode().split()[2] + major = int(ver.split('.')[0]) + return major + def remove_comments(text): def replacer(match): diff --git a/python/src/detector.cpp b/python/src/detector.cpp index 021c26aea..c6cd4927b 100644 --- a/python/src/detector.cpp +++ b/python/src/detector.cpp @@ -1,8 +1,8 @@ -// SPDX-License-Identifier: LGPL-3.0-or-other -// Copyright (C) 2021 Contributors to the SLS Detector Package /* WARINING This file is auto generated any edits might be overwritten without * warning */ +// SPDX-License-Identifier: LGPL-3.0-or-other +// Copyright (C) 2021 Contributors to the SLS Detector Package #include #include #include @@ -178,7 +178,7 @@ void init_det(py::module &m) { Detector::getMaster, py::arg() = Positions{}) .def("setMaster", (void (Detector::*)(bool, int)) & Detector::setMaster, - py::arg(), py::arg() = -1) + py::arg(), py::arg()) .def("isVirtualDetectorServer", (Result(Detector::*)(sls::Positions) const) & Detector::isVirtualDetectorServer, @@ -772,7 +772,7 @@ void init_det(py::module &m) { Detector::getRxLastClientIP, py::arg() = Positions{}) .def("getRxThreadIds", - (Result>(Detector::*)(sls::Positions) const) & + (Result>(Detector::*)(sls::Positions) const) & Detector::getRxThreadIds, py::arg() = Positions{}) .def("getRxArping", @@ -1016,8 +1016,7 @@ void init_det(py::module &m) { Detector::getTop, py::arg() = Positions{}) .def("setTop", - (void (Detector::*)(bool, sls::Positions)) & - Detector::setTop, + (void (Detector::*)(bool, sls::Positions)) & Detector::setTop, py::arg(), py::arg() = Positions{}) .def("getChipVersion", (Result(Detector::*)(sls::Positions) const) & @@ -1277,10 +1276,6 @@ void init_det(py::module &m) { (Result>(Detector::*)(sls::Positions) const) & Detector::getGateDelayForAllGates, py::arg() = Positions{}) - .def("getMaster", - (Result(Detector::*)(sls::Positions) const) & - Detector::getMaster, - py::arg() = Positions{}) .def("getChipStatusRegister", (Result(Detector::*)(sls::Positions) const) & Detector::getChipStatusRegister, @@ -1569,7 +1564,7 @@ void init_det(py::module &m) { Detector::getUpdateMode, py::arg() = Positions{}) .def("setUpdateMode", - (void (Detector::*)(bool, sls::Positions)) & + (void (Detector::*)(const bool, sls::Positions)) & Detector::setUpdateMode, py::arg(), py::arg() = Positions{}) .def("readRegister",