feluelle commented on a change in pull request #9394:
URL: https://github.com/apache/airflow/pull/9394#discussion_r449451590
##########
File path: airflow/utils/python_virtualenv.py
##########
@@ -69,3 +72,23 @@ def prepare_virtualenv(
execute_in_subprocess(pip_cmd)
return '{}/bin/python'.format(venv_directory)
+
+
+def render_virtualenv_script(jinja_context: dict) -> str:
+ """
+ Renders the python script to execute in the virtual environment.
+
+ :param jinja_context: The jinja context variables to unpack and replace
with its placeholders in the
+ template file.
+ :type jinja_context: dict
+ :return: the rendered content
+ :rtype: str
+ """
+ template_loader =
jinja2.FileSystemLoader(searchpath=os.path.dirname(__file__))
+ template_env = jinja2.Environment(
+ loader=template_loader,
+ undefined=jinja2.StrictUndefined
+ )
+ template = template_env.get_template('python_virtualenv_script.jinja2')
+ content = template.render(**jinja_context)
Review comment:
I could also use `template.stream(**jinja_context).dump(file)`. So I do
not need to use `open` to create and write to a file.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]