Skip to content

Commit

Permalink
Move dags-folder bundle to LocalDagBundle; rename kwarg (#45721)
Browse files Browse the repository at this point in the history
This moves the dags-folder bundle to use LocalDagBundle, instead of
having its own class. A follow up will remove the `[core] dags_folder`
config as well, but that will be much larger reaching.

I've also renamed the `local_folder` kwarg to `path` - just a nicer
name for it.
  • Loading branch information
jedcunningham authored Jan 17, 2025
1 parent 060eeb7 commit 5797edc
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 56 deletions.
2 changes: 1 addition & 1 deletion airflow/config_templates/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2707,7 +2707,7 @@ dag_bundles:
[
{{
"name": "dags-folder",
"classpath": "airflow.dag_processing.bundles.dagfolder.DagsFolderDagBundle",
"classpath": "airflow.dag_processing.bundles.local.LocalDagBundle",
"kwargs": {{}}
}}
]
31 changes: 0 additions & 31 deletions airflow/dag_processing/bundles/dagfolder.py

This file was deleted.

10 changes: 7 additions & 3 deletions airflow/dag_processing/bundles/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,25 @@

from pathlib import Path

from airflow import settings
from airflow.dag_processing.bundles.base import BaseDagBundle


class LocalDagBundle(BaseDagBundle):
"""
Local DAG bundle - exposes a local directory as a DAG bundle.
:param local_folder: Local folder where the DAGs are stored
:param path: Local path where the DAGs are stored
"""

supports_versioning = False

def __init__(self, *, local_folder: str, **kwargs) -> None:
def __init__(self, *, path: str | None = None, **kwargs) -> None:
super().__init__(**kwargs)
self._path = Path(local_folder)
if path is None:
path = settings.DAGS_FOLDER

self._path = Path(path)

def get_current_version(self) -> None:
return None
Expand Down
2 changes: 1 addition & 1 deletion airflow/dag_processing/bundles/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def parse_config(self) -> None:
"name": "example_dags",
"classpath": "airflow.dag_processing.bundles.local.LocalDagBundle",
"kwargs": {
"local_folder": example_dag_folder,
"path": example_dag_folder,
},
}
)
Expand Down
2 changes: 1 addition & 1 deletion providers/tests/fab/auth_manager/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def _config_bundle(path_to_parse: Path | str):
{
"name": "testing",
"classpath": "airflow.dag_processing.bundles.local.LocalDagBundle",
"kwargs": {"local_folder": str(path_to_parse), "refresh_interval": 0},
"kwargs": {"path": str(path_to_parse), "refresh_interval": 0},
}
]
with conf_vars({("dag_bundles", "backends"): json.dumps(bundle_config)}):
Expand Down
2 changes: 1 addition & 1 deletion task_sdk/tests/execution_time/test_supervisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def local_dag_bundle_cfg(path, name="my-bundle"):
{
"name": name,
"classpath": "airflow.dag_processing.bundles.local.LocalDagBundle",
"kwargs": {"local_folder": str(path), "refresh_interval": 1},
"kwargs": {"path": str(path), "refresh_interval": 1},
}
]
)
Expand Down
4 changes: 2 additions & 2 deletions task_sdk/tests/execution_time/test_task_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def test_parse(test_dags_dir: Path, make_ti_context):
{
"name": "my-bundle",
"classpath": "airflow.dag_processing.bundles.local.LocalDagBundle",
"kwargs": {"local_folder": str(test_dags_dir), "refresh_interval": 1},
"kwargs": {"path": str(test_dags_dir), "refresh_interval": 1},
}
]
),
Expand Down Expand Up @@ -569,7 +569,7 @@ def test_dag_parsing_context(make_ti_context, mock_supervisor_comms, monkeypatch
{
"name": "my-bundle",
"classpath": "airflow.dag_processing.bundles.local.LocalDagBundle",
"kwargs": {"local_folder": str(test_dags_dir), "refresh_interval": 1},
"kwargs": {"path": str(test_dags_dir), "refresh_interval": 1},
}
]
)
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def _config_bundle(path_to_parse: Path | str):
{
"name": "testing",
"classpath": "airflow.dag_processing.bundles.local.LocalDagBundle",
"kwargs": {"local_folder": str(path_to_parse), "refresh_interval": 0},
"kwargs": {"path": str(path_to_parse), "refresh_interval": 0},
}
]
with conf_vars({("dag_bundles", "backends"): json.dumps(bundle_config)}):
Expand Down
2 changes: 1 addition & 1 deletion tests/dag_processing/bundles/test_dag_bundle_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
{
"name": "my-bundle",
"classpath": "airflow.dag_processing.bundles.local.LocalDagBundle",
"kwargs": {"local_folder": "/tmp/hihi", "refresh_interval": 1},
"kwargs": {"path": "/tmp/hihi", "refresh_interval": 1},
}
]
),
Expand Down
19 changes: 8 additions & 11 deletions tests/dag_processing/test_dag_bundles.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from git import Repo

from airflow.dag_processing.bundles.base import BaseDagBundle
from airflow.dag_processing.bundles.dagfolder import DagsFolderDagBundle
from airflow.dag_processing.bundles.git import GitDagBundle, GitHook
from airflow.dag_processing.bundles.local import LocalDagBundle
from airflow.exceptions import AirflowException
Expand All @@ -46,7 +45,7 @@ def bundle_temp_dir(tmp_path):

def test_default_dag_storage_path():
with conf_vars({("core", "dag_bundle_storage_path"): ""}):
bundle = LocalDagBundle(name="test", local_folder="/hello")
bundle = LocalDagBundle(name="test", path="/hello")
assert bundle._dag_bundle_root_storage_path == Path(tempfile.gettempdir(), "airflow", "dag_bundles")


Expand All @@ -68,24 +67,22 @@ def path(self):

class TestLocalDagBundle:
def test_path(self):
bundle = LocalDagBundle(name="test", local_folder="/hello")
bundle = LocalDagBundle(name="test", path="/hello")
assert bundle.path == Path("/hello")

@conf_vars({("core", "dags_folder"): "/tmp/somewhere/dags"})
def test_path_default(self):
bundle = LocalDagBundle(name="test", refresh_interval=300)
assert bundle.path == Path("/tmp/somewhere/dags")

def test_none_for_version(self):
assert LocalDagBundle.supports_versioning is False

bundle = LocalDagBundle(name="test", local_folder="/hello")
bundle = LocalDagBundle(name="test", path="/hello")

assert bundle.get_current_version() is None


class TestDagsFolderDagBundle:
@conf_vars({("core", "dags_folder"): "/tmp/somewhere/dags"})
def test_path(self):
bundle = DagsFolderDagBundle(name="test")
assert bundle.path == Path("/tmp/somewhere/dags")


GIT_DEFAULT_BRANCH = "main"


Expand Down
6 changes: 3 additions & 3 deletions tests/dag_processing/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -839,12 +839,12 @@ def test_bundles_are_refreshed(self):
{
"name": "bundleone",
"classpath": "airflow.dag_processing.bundles.local.LocalDagBundle",
"kwargs": {"local_folder": "/dev/null", "refresh_interval": 0},
"kwargs": {"path": "/dev/null", "refresh_interval": 0},
},
{
"name": "bundletwo",
"classpath": "airflow.dag_processing.bundles.local.LocalDagBundle",
"kwargs": {"local_folder": "/dev/null", "refresh_interval": 300},
"kwargs": {"path": "/dev/null", "refresh_interval": 300},
},
]

Expand Down Expand Up @@ -900,7 +900,7 @@ def test_bundles_versions_are_stored(self):
{
"name": "mybundle",
"classpath": "airflow.dag_processing.bundles.local.LocalDagBundle",
"kwargs": {"local_folder": "/dev/null", "refresh_interval": 0},
"kwargs": {"path": "/dev/null", "refresh_interval": 0},
},
]

Expand Down

0 comments on commit 5797edc

Please sign in to comment.