uranusjr commented on code in PR #73118: URL: https://github.com/apache/airflow/pull/73118#discussion_r4024231259
########## task-sdk/src/airflow/sdk/importers/python_importer.py: ########## @@ -56,12 +65,60 @@ log = logging.getLogger(__name__) -class PythonDagImporter(AbstractDagImporter): +class _DefinitionSourceLoader(importlib.abc.SourceLoader): + """ + A SourceLoader that executes a DagDefinition straight from its bytes. + + It needs no file on disk: :meth:`.get_data`` returns the definition's + source, and :meth:`get_filename` reports the definition's repr, so + ``__file__`` and tracebacks stay meaningful. + + Bytecode caching is left disabled (the inherited ``path_stats`` raises + ``OSError``) since it's not particularly useful in dag processors. + """ + + def __init__(self, definition: DagDefinition) -> None: + self._definition = definition + + def get_filename(self, fullname: str) -> str: + return repr(self._definition) + + def get_data(self, path: str) -> bytes: + return self._definition.read_bytes() Review Comment: Fixed with an extra check. -- 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]
