Skip to content

Commit a806fe0

Browse files
committed
Moved doc parsing to server side
1 parent 68737b8 commit a806fe0

File tree

1 file changed

+12
-2
lines changed
  • task-sdk/src/airflow/sdk/definitions

1 file changed

+12
-2
lines changed

task-sdk/src/airflow/sdk/definitions/dag.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,18 @@ def _convert_doc_md(doc_md: str | None) -> str | None:
185185
return fh.read()
186186
except FileNotFoundError:
187187
return doc_md
188+
return doc_md
189+
188190

191+
def _clean_doc_md(doc_md: str) -> str:
192+
# alternative to using math.inf, the linter doesn't like inf being a float
193+
strip_count = len(doc_md)
194+
195+
for line in doc_md.split("\n"):
196+
if line != "":
197+
strip_count = min(strip_count, len(line) - len(line.lstrip()))
198+
if strip_count > 0:
199+
doc_md = "\n".join([line[strip_count:] for line in doc_md.split("\n")])
189200
return doc_md
190201

191202

@@ -1120,8 +1131,7 @@ def factory(*args, **kwargs):
11201131
with DAG(dag_id, **decorator_kwargs) as dag_obj:
11211132
# Set DAG documentation from function documentation if it exists and doc_md is not set.
11221133
if f.__doc__ and not dag_obj.doc_md:
1123-
dag_obj.doc_md = f.__doc__
1124-
1134+
dag_obj.doc_md = _clean_doc_md(f.__doc__)
11251135
# Generate DAGParam for each function arg/kwarg and replace it for calling the function.
11261136
# All args/kwargs for function will be DAGParam object and replaced on execution time.
11271137
f_kwargs = {}

0 commit comments

Comments
 (0)