szaszm commented on code in PR #1727:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1727#discussion_r1532369112


##########
docker/test/integration/cluster/ImageStore.py:
##########
@@ -97,10 +105,21 @@ def __build_minifi_cpp_sql_image(self):
 
         return self.__build_image(dockerfile)
 
-    def __build_minifi_cpp_image_with_nifi_python_processors(self, 
additional_cmd=""):
+    def __build_minifi_cpp_image_with_nifi_python_processors(self, 
python_option):
         parse_document_url = 
"https://raw.githubusercontent.com/apache/nifi/rel/nifi-"; + 
NifiContainer.NIFI_VERSION + 
"/nifi-python-extensions/nifi-text-embeddings-module/src/main/python/ParseDocument.py"
         chunk_document_url = 
"https://raw.githubusercontent.com/apache/nifi/rel/nifi-"; + 
NifiContainer.NIFI_VERSION + 
"/nifi-python-extensions/nifi-text-embeddings-module/src/main/python/ChunkDocument.py"
         pip3_install_command = ""
+        requirements_install_command = ""
+        additional_cmd = ""
+        parse_document_sed_cmd = 'sed -i "54d;55d" 
/opt/minifi/minifi-current/minifi-python/nifi_python_processors/ParseDocument.py
 && \\'
+        chunk_document_sed_cmd = 'sed -i "112d" 
/opt/minifi/minifi-current/minifi-python/nifi_python_processors/ChunkDocument.py
 && \\'
+        if python_option == PythonOptions.SYSTEM_INSTALLED_PACKAGES:
+            additional_cmd = "RUN pip3 install 'langchain<=0.17.0'"
+        elif python_option == PythonOptions.REQUIREMENTS_FILE:
+            requirements_install_command = "echo 'langchain<=0.17.0' > 
/opt/minifi/minifi-current/minifi-python/nifi_python_processors/requirements.txt
 && \\"
+        elif python_option == PythonOptions.INLINE_DEFINED_PACKAGES:
+            parse_document_sed_cmd = parse_document_sed_cmd[:-2] + ' sed -i 
"54 i \\ \\ \\ \\ \\ \\ \\ \\ dependencies = [\\"langchain<=0.17.0\\"]" 
/opt/minifi/minifi-current/minifi-python/nifi_python_processors/ParseDocument.py
 && \\'

Review Comment:
   Shouldn't there be 3 backslashes around the langchain dependency? 2 for a 
single escaped backslash for sed, and a third for escaping the quotation mark, 
so it goes to sed, not the shell.



##########
extensions/python/pythonprocessors/nifi_python_processors/utils/inline_dependency_installer.py:
##########
@@ -0,0 +1,43 @@
+import ast
+import sys
+import subprocess
+import os
+
+
+class Visitor(ast.NodeVisitor):

Review Comment:
   There is a lot of logic and nesting going on here. It would be nice to add a 
code comment describing what this does, and how it's (meant to be) used.



##########
extensions/python/pythonprocessors/nifi_python_processors/utils/inline_dependency_installer.py:
##########
@@ -0,0 +1,43 @@
+import ast
+import sys
+import subprocess
+import os
+
+
+class Visitor(ast.NodeVisitor):
+    def __init__(self, class_name):
+        self.dependencies = []
+        self.class_name = class_name
+
+    def visit_ClassDef(self, node):
+        if node.name != self.class_name:
+            return
+        for child in node.body:
+            if isinstance(child, ast.ClassDef) and child.name == 
'ProcessorDetails':
+                for detail in child.body:
+                    if isinstance(detail, ast.Assign) and detail.targets[0].id 
== 'dependencies':
+                        for elt in detail.value.elts:
+                            if isinstance(elt, ast.Constant):
+                                self.dependencies.append(elt.s)
+                        break
+                break
+
+
+def extract_dependencies(file_path):
+    class_name = file_path.split(os.sep)[-1].split('.')[0]
+    with open(file_path, 'r') as file:
+        code = file.read()
+
+    tree = ast.parse(code)
+    visitor = Visitor(class_name)
+    visitor.visit(tree)
+    return visitor.dependencies
+
+
+if __name__ == '__main__':
+    if len(sys.argv) < 2:
+        sys.exit(1)
+
+    dependencies = extract_dependencies(sys.argv[1])
+    if dependencies:
+        subprocess.check_call([sys.executable, "-m", "pip", "install", 
"--no-cache-dir"] + dependencies)

Review Comment:
   Why is the pip cache disabled here?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@nifi.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to