From a5091cd52614e01e1a8acf0e77cf4185baa5dd3d Mon Sep 17 00:00:00 2001 From: Samuel O'Brien Date: Thu, 6 Aug 2020 14:05:36 -0500 Subject: sim: Support Out of Tree Sources and Sinks This commit adds the ability to specify a path to an arbitrary python file in a simulator config file, which will be imported and used to construct a SampleSink or SampleSource for use with data streaming. Signed-off-by: Samuel O'Brien --- mpm/python/usrp_mpm/simulator/sample_source.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'mpm/python/usrp_mpm/simulator/sample_source.py') diff --git a/mpm/python/usrp_mpm/simulator/sample_source.py b/mpm/python/usrp_mpm/simulator/sample_source.py index 36278efd8..98fc6ff0b 100644 --- a/mpm/python/usrp_mpm/simulator/sample_source.py +++ b/mpm/python/usrp_mpm/simulator/sample_source.py @@ -7,6 +7,7 @@ This module contains the interface for providing data to a simulator stream and receiving data from a simulator stream. """ +import importlib.util sources = {} sinks = {} @@ -21,6 +22,22 @@ def cli_sink(cls): sinks[cls.__name__] = cls return cls +name_index = 0 +module_lookup = {} +def from_import_path(class_name, import_path): + global name_index + global module_lookup + module = None + if import_path in module_lookup: + module = module_lookup[import_path] + else: + spec = importlib.util.spec_from_file_location("simsample." + str(name_index), import_path) + name_index =+ 1 + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + module_lookup[import_path] = module + return getattr(module, class_name) + class SampleSource: """This class defines the interface of a SampleSource. It provides samples to the simulator which are then sent over the -- cgit v1.2.3