Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin Import Fix; Keep List of ServiceAPIs #63

Open
wants to merge 3 commits into
base: implement-plugin-system
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion pfdl_scheduler/model/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from pfdl_scheduler.model.array import Array


@dataclass
class Service:
"""Represents a Service or Service Call in the PFDL.

Expand Down
2 changes: 2 additions & 0 deletions pfdl_scheduler/petri_net/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ def __init__(
self.tree = None
self.file_name = file_name
self.pfdl_base_classes = pfdl_base_classes
self.service_apis: list[ServiceAPI] = []

def add_callback(self, transition_uuid: str, callback_function: Callable, *args: Any) -> None:
"""Registers the given callback function in the transition_dict.
Expand Down Expand Up @@ -288,6 +289,7 @@ def generate_service(
service_api = self.pfdl_base_classes.get_class("ServiceAPI")(
service, task_context, in_loop=in_loop
)
self.service_apis.append(service_api)

service_started_uuid = create_place(service.name + " started", self.net, service_node)
service_finished_uuid = create_place(service.name + " finished", self.net, service_node)
Expand Down
25 changes: 13 additions & 12 deletions pfdl_scheduler/plugins/plugin_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@
import sys
import inspect
from typing import List
from pathlib import Path

from pfdl_scheduler.pfdl_base_classes import PFDLBaseClasses

base_classes_registry = {}

PLUGIN_FOLDER_PATH = "./pfdl_scheduler/plugins"


def base_class(existing_class_name):
"""A Decorator to mark a class that will extend an existing class.
Expand Down Expand Up @@ -160,16 +159,18 @@ def load_plugin_modules(self, module_name, module_path):
def load_plugins(self, plugins: List[str]):
"""Recursively load all Python files from plugin folders."""
for plugin_folder in plugins:
plugin_path = os.path.join(PLUGIN_FOLDER_PATH, plugin_folder)

if os.path.isdir(plugin_path):
# Walk through all files in the plugin folder
for root, _, files in os.walk(plugin_path):
for file in files:
if file.endswith(".py"):
module_name = f"{plugin_folder}.{file[:-3]}" # Plugin folder + filename without .py
module_path = os.path.join(root, file)
self.load_plugin_modules(module_name, module_path)
plugin_path = Path(__file__).parent / plugin_folder

if not plugin_path.is_dir():
raise ValueError("given plugin could not be found")

# Walk through all files in the plugin folder
for root, _, files in os.walk(plugin_path):
for file in files:
if file.endswith(".py"):
module_name = f"{plugin_folder}.{file[:-3]}" # Plugin folder + filename without .py
module_path = os.path.join(root, file)
self.load_plugin_modules(module_name, module_path)

def get_final_classes(self):
"""Return a dictionary of final classes after applying plugins."""
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

setup(
name="pfdl_scheduler",
version="0.9.0",
version="0.9.2",
description="Parser and Scheduler for Production Flow Description Language (PFDL) files.",
long_description=long_description,
long_description_content_type='text/markdown',
Expand Down
4 changes: 3 additions & 1 deletion tests/unit_test/model/test_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ def test_init(self):
context = ParserRuleContext()
condition = Condition({"a": 1}, [Service("service")], [TaskCall("task")], context=context)
self.assertEqual(condition.expression, {"a": 1})
self.assertEqual(condition.passed_stmts, [Service("service")])
self.assertEqual(1, len(condition.passed_stmts))
self.assertIsInstance(condition.passed_stmts[0], Service)
self.assertEqual("service", condition.passed_stmts[0].name)
self.assertEqual(condition.failed_stmts, [TaskCall("task")])
self.assertEqual(condition.context, context)
self.assertEqual(condition.context_dict, {})
4 changes: 2 additions & 2 deletions tests/unit_test/model/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ def test_init(self):
)
self.assertEqual(task.name, "task1")
self.assertEqual(len(task.statements), 4)
self.assertEqual(task.statements[0], Service())
self.assertIsInstance(task.statements[0], Service)
self.assertEqual(task.statements[1], CountingLoop())
self.assertEqual(task.statements[2], CountingLoop())
self.assertEqual(task.statements[3], Service())
self.assertIsInstance(task.statements[3], Service)
self.assertEqual(task.variables, {"var1": "val1", "var2": "val2"})
self.assertEqual(task.input_parameters, {"in1": "val4", "in2": "val5"})
self.assertEqual(task.output_parameters, ["out1", "out2"])
Expand Down