Skip to content

Commit bdd5e8e

Browse files
Merge pull request #939 from TheDeanLab/2024-07-13
Refactor plugins_model
2 parents efe8e98 + 6d771eb commit bdd5e8e

File tree

4 files changed

+189
-147
lines changed

4 files changed

+189
-147
lines changed

src/navigate/config/config.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Copyright (c) 2021-2024 The University of Texas Southwestern Medical Center.
22
# All rights reserved.
3-
43
# Redistribution and use in source and binary forms, with or without
54
# modification, are permitted for academic and research use only
65
# (subject to the limitations in the disclaimer below)
@@ -39,12 +38,14 @@
3938
from pathlib import Path
4039
from os.path import isfile
4140
from multiprocessing.managers import ListProxy, DictProxy
41+
import inspect
4242

4343
# Third Party Imports
4444
import yaml
4545

4646
# Local Imports
47-
from navigate.tools.common_functions import build_ref_name
47+
from navigate.tools.common_functions import build_ref_name, load_module_from_file
48+
from navigate.model.features import feature_related_functions
4849

4950

5051
def get_navigate_path():
@@ -1097,3 +1098,23 @@ def verify_configuration(manager, configuration):
10971098
"gui",
10981099
{"channels": {"count": channel_count}},
10991100
)
1101+
1102+
1103+
def set_feature_attributes(plugin_path):
1104+
"""Load feature module and set function attributes.
1105+
1106+
Parameters
1107+
----------
1108+
plugin_path : str
1109+
The path to the plugins folder.
1110+
"""
1111+
features_dir = os.path.join(plugin_path, "model", "features")
1112+
if os.path.exists(features_dir):
1113+
features = os.listdir(features_dir)
1114+
for feature in features:
1115+
feature_file = os.path.join(features_dir, feature)
1116+
if os.path.isfile(feature_file):
1117+
temp = load_module_from_file(feature, feature_file)
1118+
for c in dir(temp):
1119+
if inspect.isclass(getattr(temp, c)):
1120+
setattr(feature_related_functions, c, getattr(temp, c))

src/navigate/controller/sub_controllers/plugins.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2021-2022 The University of Texas Southwestern Medical Center.
1+
# Copyright (c) 2021-2024 The University of Texas Southwestern Medical Center.
22
# All rights reserved.
33

44
# Redistribution and use in source and binary forms, with or without
@@ -33,7 +33,6 @@
3333
# Standard library imports
3434
from pathlib import Path
3535
import os
36-
import inspect
3736
import tkinter as tk
3837
from tkinter import messagebox
3938

@@ -48,6 +47,7 @@
4847
from navigate.model.features import feature_related_functions
4948
from navigate.controller.sub_controllers.gui import GUIController
5049
from navigate.view.popups.plugins_popup import PluginsPopup
50+
from navigate.config import set_feature_attributes
5151

5252

5353
class PluginsController:
@@ -174,18 +174,7 @@ def load_plugins(self):
174174
plugin_name, plugin_frame, plugin_controller
175175
)
176176
# feature
177-
features_dir = os.path.join(plugin_path, "model", "features")
178-
if os.path.exists(features_dir):
179-
features = os.listdir(features_dir)
180-
for feature in features:
181-
feature_file = os.path.join(features_dir, feature)
182-
if os.path.isfile(feature_file):
183-
module = load_module_from_file(feature, feature_file)
184-
for c in dir(module):
185-
if inspect.isclass(getattr(module, c)):
186-
setattr(
187-
feature_related_functions, c, getattr(module, c)
188-
)
177+
set_feature_attributes(plugin_path)
189178

190179
# acquisition mode
191180
acquisition_modes = plugin_config.get("acquisition_modes", [])

0 commit comments

Comments
 (0)