diff --git a/src/Mod/CAM/CAMTests/TestPathPost.py b/src/Mod/CAM/CAMTests/TestPathPost.py index 02a53cb5e4..65ae363723 100644 --- a/src/Mod/CAM/CAMTests/TestPathPost.py +++ b/src/Mod/CAM/CAMTests/TestPathPost.py @@ -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]) diff --git a/src/Mod/CAM/Path/Post/Processor.py b/src/Mod/CAM/Path/Post/Processor.py index a643acfd75..9d52b5a0ed 100644 --- a/src/Mod/CAM/Path/Post/Processor.py +++ b/src/Mod/CAM/Path/Post/Processor.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- # *************************************************************************** # * Copyright (c) 2014 Yorik van Havre * +# * Copyright (c) 2024 Larry Woestman * # * * # * 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: