phi-friday commented on code in PR #41039:
URL: https://github.com/apache/airflow/pull/41039#discussion_r1709086949


##########
airflow/utils/python_virtualenv_script.jinja2:
##########
@@ -64,6 +64,20 @@ with open(sys.argv[3], "r") as file:
     virtualenv_string_args = list(map(lambda x: x.strip(), list(file)))
 {% endif %}
 
+{% if use_airflow_context | default(false) -%}
+if len(sys.argv) > 5:
+    import json
+    from types import ModuleType
+
+    class _MockPython(ModuleType):
+        @staticmethod
+        def get_current_context():
+            with open(sys.argv[5]) as file:
+                return json.load(file)

Review Comment:
   This seems to change a few things
   
   1. The `PythonVirtualenvOperator` is only available when 
`system_site_packages=True` or `expect_airflow=True` (same for 
`BranchPythonVirtualenvOperator`).
   2. `ExternalPythonOperator` is only available when `expect_airflow=True` 
(same for `BranchExternalPythonOperator`).
   3. The `MockPython` should only be changed for `get_current_context`, which 
means that `MockPython` will provide other functions or variables besides 
`get_current_context` as normal.(Of course, we do not guarantee that they will 
work when used).



-- 
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: commits-unsubscr...@airflow.apache.org

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

Reply via email to