CAM: Fixed script-style postprocessors getting the wrong __name__
Also added a test that the __name__ of the postprocessor is correct
This commit is contained in:
committed by
Yorik van Havre
parent
d3ffef0df7
commit
77a05049d5
@@ -360,6 +360,11 @@ class TestPostProcessorFactory(unittest.TestCase):
|
||||
self.assertTrue(post is not None)
|
||||
self.assertTrue(hasattr(post, "_buildPostList"))
|
||||
|
||||
def test040(self):
|
||||
"""Test that the __name__ of the postprocessor is correct."""
|
||||
post = PostProcessorFactory.get_post_processor(self.job, "linuxcnc")
|
||||
self.assertEqual(post.script_module.__name__, "linuxcnc_post")
|
||||
|
||||
|
||||
class TestPostProcessorClass(unittest.TestCase):
|
||||
"""Test new post structure objects."""
|
||||
@@ -383,21 +388,21 @@ class TestPostProcessorClass(unittest.TestCase):
|
||||
|
||||
def test010(self):
|
||||
"""Test the export function."""
|
||||
post = PostProcessorFactory.get_post_processor(job, "linuxcnc")
|
||||
post = PostProcessorFactory.get_post_processor(self.job, "linuxcnc")
|
||||
sections = post.export()
|
||||
for sec in sections:
|
||||
print(sec[0])
|
||||
|
||||
def test020(self):
|
||||
"""Test the export function with splitting."""
|
||||
post = PostProcessorFactory.get_post_processor(job, "linuxcnc")
|
||||
post = PostProcessorFactory.get_post_processor(self.job, "linuxcnc")
|
||||
sections = post.export()
|
||||
for sec in sections:
|
||||
print(sec[0])
|
||||
|
||||
def test030(self):
|
||||
"""Test the export function with splitting."""
|
||||
post = PostProcessorFactory.get_post_processor(job, "generic")
|
||||
post = PostProcessorFactory.get_post_processor(self.job, "generic")
|
||||
sections = post.export()
|
||||
for sec in sections:
|
||||
print(sec[0])
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# ***************************************************************************
|
||||
# * Copyright (c) 2014 Yorik van Havre <yorik@uncreated.net> *
|
||||
# * Copyright (c) 2024 Larry Woestman <LarryWoestman2@gmail.com> *
|
||||
# * *
|
||||
# * This program is free software; you can redistribute it and/or modify *
|
||||
# * it under the terms of the GNU Lesser General Public License (LGPL) *
|
||||
@@ -58,7 +59,6 @@ class PostProcessorFactory:
|
||||
Path.Log.debug("PostProcessorFactory.get_post_processor()")
|
||||
|
||||
# Posts have to be in a place we can find them
|
||||
syspath = sys.path
|
||||
paths = Path.Preferences.searchPathsPost()
|
||||
paths.extend(sys.path)
|
||||
|
||||
@@ -85,7 +85,7 @@ class PostProcessorFactory:
|
||||
except AttributeError:
|
||||
# Return an instance of WrapperPost if no valid module is found
|
||||
Path.Log.debug(f"Post processor {postname} is a script")
|
||||
return WrapperPost(job, module_path)
|
||||
return WrapperPost(job, module_path, module_name)
|
||||
|
||||
|
||||
class PostProcessor:
|
||||
@@ -283,16 +283,17 @@ class PostProcessor:
|
||||
class WrapperPost(PostProcessor):
|
||||
"""Wrapper class for old post processors that are scripts."""
|
||||
|
||||
def __init__(self, job, script_path, *args, **kwargs):
|
||||
def __init__(self, job, script_path, module_name, *args, **kwargs):
|
||||
super().__init__(job, tooltip=None, tooltipargs=None, units=None, *args, **kwargs)
|
||||
self.script_path = script_path
|
||||
self.module_name = module_name
|
||||
Path.Log.debug(f"WrapperPost.__init__({script_path})")
|
||||
self.load_script()
|
||||
|
||||
def load_script(self):
|
||||
"""Dynamically load the script as a module."""
|
||||
try:
|
||||
spec = importlib.util.spec_from_file_location("script_module", self.script_path)
|
||||
spec = importlib.util.spec_from_file_location(self.module_name, self.script_path)
|
||||
self.script_module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(self.script_module)
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user