This is an automated email from the ASF dual-hosted git repository.

zhoujieguang pushed a commit to branch main
in repository 
https://gitbox.apache.org/repos/asf/dolphinscheduler-sdk-python.git


The following commit(s) were added to refs/heads/main by this push:
     new 428d717  fix: Solve task python dependency with stmdency (#72)
428d717 is described below

commit 428d717ba7de095f2e91503c20c1ec49cc514bb0
Author: Jay Chung <[email protected]>
AuthorDate: Sun Feb 12 21:22:39 2023 +0800

    fix: Solve task python dependency with stmdency (#72)
---
 src/pydolphinscheduler/tasks/python.py | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/pydolphinscheduler/tasks/python.py 
b/src/pydolphinscheduler/tasks/python.py
index 818f1fb..c1b2558 100644
--- a/src/pydolphinscheduler/tasks/python.py
+++ b/src/pydolphinscheduler/tasks/python.py
@@ -17,12 +17,14 @@
 
 """Task Python."""
 
-import inspect
 import logging
 import re
 import types
+from pathlib import Path
 from typing import Union
 
+from stmdency.extractor import Extractor
+
 from pydolphinscheduler.constants import TaskType
 from pydolphinscheduler.core.task import Task
 from pydolphinscheduler.exceptions import PyDSParamException
@@ -74,8 +76,10 @@ class Python(Task):
         """
         definition = getattr(self, "definition")
         if isinstance(definition, types.FunctionType):
-            py_function = inspect.getsource(definition)
-            func_str = f"{py_function}{definition.__name__}()"
+            loc = definition.__code__.co_filename
+            extractor = Extractor(Path(loc).open("r").read())
+            stm = extractor.get_code(definition.__name__)
+            func_str = f"{stm}{definition.__name__}()"
         else:
             pattern = re.compile("^def (\\w+)\\(")
             find = pattern.findall(definition)

Reply via email to