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

Python as Scripting language for inline task #204

Closed
wants to merge 5 commits into from

Conversation

saksham2105
Copy link
Contributor

@saksham2105 saksham2105 commented Jul 11, 2024

Pull Request type

  • Bugfix
  • Feature
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • WHOSUSING.md
  • Other (please describe):

NOTE: Please remember to run ./gradlew spotlessApply to fix any format violations.

Changes in this PR

Added Support for Python as scripting language for inline task using Jython library. Along with this there is a restriction for import keywords and various inbuilt functions for safety constraints. Added support for variable replacements for Simple ,Nested JSON types usin $.variable.variable2.... etc. Along with the Script expression in inputs map. We also have to add one more field in map named outputIdentifier: something

Use of outputIdentifier

Sample code :-

def add(a,b):
 return a + b
sum = add(1,2)
sum

In this case we will keep outputIdentifier: "sum" because this is the way we extract result of our Python code from Java using below snippet.

        String outputIdentifier = inputs.get("outputIdentifier").toString();
        PythonInterpreter interpreter = new PythonInterpreter();
        interpreter.exec(script);
        PyObject result = interpreter.get(outputIdentifier);

Roadmap : https://github.com/conductor-oss/conductor/blob/main/ROADMAP.md


Describe the new behavior from this PR, and why it's needed
Issue # New feature in OSS roadmap

Alternatives considered
We can also use GraalPy but it is super complex to setup

Describe alternative implementation you have considered

@saksham2105 saksham2105 deleted the python-as-inline-task branch July 12, 2024 06:01
@izrail-p
Copy link

izrail-p commented Oct 29, 2024

Hi @saksham2105
I’m having trouble returning a dictionary or list from my inline Python code. It works fine when I return a string, though. Any ideas on what might be going wrong?
Getting this error -
Suppressed: com.oracle.truffle.api.TruffleStackTrace$LazyStackTrace

@izrail-p
Copy link

@sauronmesh yes. I am using "evaluatorType": "python".

@saksham2105
Copy link
Contributor Author

Hey @izrail-p no my ques is are you using jython or graal?

@saksham2105
Copy link
Contributor Author

I think right now there is no such thing to support python as inline task

@izrail-p
Copy link

@saksham2105 I am using Jython.

@saksham2105
Copy link
Contributor Author

imo it should be json serialized object and the object can have list or any other collection

@izrail-p
Copy link

if (input instanceof Map<?, ?>) { Map<String, Object> inputs = (Map<String, Object>) input; if (inputs.containsKey("evaluatorType") && inputs.get("evaluatorType").toString().equals("python")) { return evalPython(script, input);
@saksham2105 python is added here as evaluatorType right. I tried returning object as well.

@saksham2105
Copy link
Contributor Author

I am not 100% About how to cast list and other data structure to jython PyObject

@aliakbar-nathani
Copy link

aliakbar-nathani commented Nov 4, 2024

Are you looking into this to support of returning dictionary or a list from the inline python task ? Or is there any roadblock here?, since it is quite common usecase to return a dictionary from the inline script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants