Skip to content

Commit

Permalink
Add docstrings to 3 functions in kedro/utils.py (#4022)
Browse files Browse the repository at this point in the history
* Add docstrings to utility functions

Signed-off-by: Yury Fedotov <yury_fedotov@mckinsey.com>
  • Loading branch information
yury-fedotov committed Aug 6, 2024
1 parent a153afd commit f29f968
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions kedro/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down

0 comments on commit f29f968

Please sign in to comment.