softyoungha commented on code in PR #40775:
URL: https://github.com/apache/airflow/pull/40775#discussion_r1689966117
##########
airflow/operators/python.py:
##########
@@ -728,6 +755,43 @@ def __init__(
**kwargs,
)
+ @property
+ def merged_props(self) -> dict[str, Any]:
+ hook = PythonVirtualenvHook(venv_conn_id=self.venv_conn_id)
+ props: dict[str, Any] = {}
+ requirements = hook.requirements
+ if self._is_requirements_set:
+ requirements = self.requirements
+ props["requirements"] = requirements
+ system_site_packages = hook.system_site_packages
+ if self._is_system_site_packages_set:
+ system_site_packages = self.system_site_packages
+ props["system_site_packages"] = system_site_packages
+ index_urls = hook.index_urls
+ if self.index_urls is not None:
+ index_urls = self.index_urls
+ props["index_urls"] = index_urls
+ if python_version := self.python_version or hook.python_version:
+ props["python_version"] = python_version
+ if pip_install_options := self.pip_install_options or
hook.pip_install_options:
+ props["pip_install_options"] = pip_install_options
+ if venv_cache_path := self.venv_cache_path or hook.venv_cache_path:
+ props["venv_cache_path"] = venv_cache_path
+ return props
+
+ @contextmanager
+ def apply_virtualenv_hook(self, rollback: bool = True) -> Generator[None,
None, None]:
+ buffer = {}
+ for key, value in self.merged_props.items():
+ buffer[key] = getattr(self, key)
+ setattr(self, key, value)
+ try:
+ yield
+ finally:
+ if rollback:
+ for key, value in buffer.items():
+ setattr(self, key, value)
Review Comment:
gather hook's data and replace original operator's props.
To avoid disturbing the existing logic, it implemented by
`apply_virtualenv_hook` context.
--
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]