diff --git a/k4FWCore/CMakeLists.txt b/k4FWCore/CMakeLists.txt index 8b6bb8af..93db9804 100644 --- a/k4FWCore/CMakeLists.txt +++ b/k4FWCore/CMakeLists.txt @@ -54,7 +54,6 @@ install(TARGETS k4FWCore k4FWCorePlugins # Copy python parsing file to genConfDir in Gaudi add_custom_command( TARGET k4FWCore POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy - ${PROJECT_SOURCE_DIR}/k4FWCore/python/k4FWCore/parseArgs.py - ${CMAKE_CURRENT_BINARY_DIR}/genConfDir/k4FWCore/parseArgs.py) - + COMMAND ${CMAKE_COMMAND} -E copy_directory + ${PROJECT_SOURCE_DIR}/k4FWCore/python/k4FWCore + ${CMAKE_CURRENT_BINARY_DIR}/genConfDir/k4FWCore) diff --git a/k4FWCore/python/k4FWCore/utils.py b/k4FWCore/python/k4FWCore/utils.py new file mode 100644 index 00000000..c210e0b0 --- /dev/null +++ b/k4FWCore/python/k4FWCore/utils.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2014-2024 Key4hep-Project. +# +# This file is part of Key4hep. +# See https://key4hep.github.io/key4hep-doc/ for further info. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import os +from io import TextIOWrapper +from typing import Union + + +def load_file(opt_file: Union[TextIOWrapper, os.PathLike]) -> None: + """Load the file content and run it in the current interpreter session""" + if isinstance(opt_file, os.PathLike): + opt_file = open(opt_file, "r") + code = compile(opt_file.read(), opt_file.name, "exec") + exec(code, globals()) diff --git a/k4FWCore/scripts/k4run b/k4FWCore/scripts/k4run index 3e1049d7..40e8df7c 100755 --- a/k4FWCore/scripts/k4run +++ b/k4FWCore/scripts/k4run @@ -6,6 +6,8 @@ import argparse from multiprocessing import cpu_count import logging +from k4FWCore.utils import load_file + # these default properties are filtered as otherwise they will clutter the argument list FILTER_GAUDI_PROPS = [ "ContextService", @@ -55,10 +57,6 @@ seen_files = set() option_db = {} -def load_file(file): - exec(file.read(), {}) - - def add_arguments(parser, app_mgr): # length increases when properties of an algorithm with tools are inspected # see https://github.com/key4hep/k4FWCore/pull/138