diff --git a/kedro/utils.py b/kedro/utils.py index bc9328290b..4613ea3620 100644 --- a/kedro/utils.py +++ b/kedro/utils.py @@ -31,10 +31,26 @@ def load_obj(obj_path: str, default_obj_path: str = "") -> Any: def _is_databricks() -> bool: + """Evaluate if the current run environment is Databricks or not. + + Useful to tailor environment-dependent activities like Kedro magic commands + or logging features that Databricks doesn't support. + + Returns: + True if run environment is Databricks, otherwise False. + """ return "DATABRICKS_RUNTIME_VERSION" in os.environ def _is_project(project_path: Union[str, Path]) -> bool: + """Evaluate if a given path is a root directory of a Kedro project or not. + + Args: + project_path: Path to be tested for being a root of a Kedro project. + + Returns: + True if a given path is a root directory of a Kedro project, otherwise False. + """ metadata_file = Path(project_path).expanduser().resolve() / _PYPROJECT if not metadata_file.is_file(): return False @@ -46,6 +62,17 @@ def _is_project(project_path: Union[str, Path]) -> bool: def _find_kedro_project(current_dir: Path) -> Any: # pragma: no cover + """Given a path, find a Kedro project associated with it. + + Can be: + - Itself, if a path is a root directory of a Kedro project. + - One of its parents, if self is not a Kedro project but one of the parent path is. + - None, if neither self nor any parent path is a Kedro project. + + Returns: + Kedro project associated with a given path, + or None if no relevant Kedro project is found. + """ paths_to_check = [current_dir] + list(current_dir.parents) for parent_dir in paths_to_check: if _is_project(parent_dir):