potiuk commented on code in PR #25780:
URL: https://github.com/apache/airflow/pull/25780#discussion_r948536905


##########
airflow/operators/python.py:
##########
@@ -441,89 +531,122 @@ def execute_callable(self):
             with open(requirements_file_name, 'w') as file:
                 file.write(requirements_file_contents)
 
-            if self.templates_dict:
-                self.op_kwargs['templates_dict'] = self.templates_dict
-
-            input_filename = os.path.join(tmp_dir, 'script.in')
-            output_filename = os.path.join(tmp_dir, 'script.out')
-            string_args_filename = os.path.join(tmp_dir, 'string_args.txt')
-            script_filename = os.path.join(tmp_dir, 'script.py')
-
             prepare_virtualenv(
                 venv_directory=tmp_dir,
                 python_bin=f'python{self.python_version}' if 
self.python_version else None,
                 system_site_packages=self.system_site_packages,
                 requirements_file_path=requirements_file_name,
                 pip_install_options=self.pip_install_options,
             )
+            python_path = tmp_path / "bin" / "python"
 
-            self._write_args(input_filename)
-            self._write_string_args(string_args_filename)
-            write_python_script(
-                jinja_context=dict(
-                    op_args=self.op_args,
-                    op_kwargs=self.op_kwargs,
-                    pickling_library=self.pickling_library.__name__,
-                    python_callable=self.python_callable.__name__,
-                    python_callable_source=self.get_python_source(),
-                ),
-                filename=script_filename,
-                
render_template_as_native_obj=self.dag.render_template_as_native_obj,
-            )
-
-            execute_in_subprocess(
-                cmd=[
-                    f'{tmp_dir}/bin/python',
-                    script_filename,
-                    input_filename,
-                    output_filename,
-                    string_args_filename,
-                ]
-            )
-
-            return self._read_result(output_filename)
-
-    def get_python_source(self):
-        """
-        Returns the source of self.python_callable
-        @return:
-        """
-        return dedent(inspect.getsource(self.python_callable))
-
-    def _write_args(self, filename):
-        if self.op_args or self.op_kwargs:
-            with open(filename, 'wb') as file:
-                self.pickling_library.dump({'args': self.op_args, 'kwargs': 
self.op_kwargs}, file)
+            return self._execute_python_callable_in_subprocess(python_path, 
tmp_path)
 
     def _iter_serializable_context_keys(self):

Review Comment:
   I think I also need to add a bit smarter _iter_serializable_context_keys - 
but I will eed to check if installed venv contains airflow/pendulum 
respectively. (or we could make it a requirement). 



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to