From 12460382275d6e9f18e7be904a4e0d8179df27f7 Mon Sep 17 00:00:00 2001 From: PatrykWyzgowski Date: Mon, 14 Oct 2024 14:17:47 +0200 Subject: [PATCH] Unifying default dir argument assignment. --- .../src/ragbits/core/prompt/promptfoo.py | 3 +-- .../src/ragbits/core/utils/_pyproject.py | 19 +++---------------- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/packages/ragbits-core/src/ragbits/core/prompt/promptfoo.py b/packages/ragbits-core/src/ragbits/core/prompt/promptfoo.py index 530a13af..a9525bc3 100644 --- a/packages/ragbits-core/src/ragbits/core/prompt/promptfoo.py +++ b/packages/ragbits-core/src/ragbits/core/prompt/promptfoo.py @@ -21,8 +21,7 @@ def generate_configs( root_path: The root path to search for Prompt objects. Defaults to the directory where the script is run. target_path: The path to save the promptfoo configuration files. Defaults to "promptfooconfigs". """ - if not root_path: - root_path = Path.cwd() + root_path = root_path or Path.cwd() prompts = PromptDiscovery(file_pattern=file_pattern, root_path=root_path).discover() Console().print( diff --git a/packages/ragbits-core/src/ragbits/core/utils/_pyproject.py b/packages/ragbits-core/src/ragbits/core/utils/_pyproject.py index d51e7677..0fcebfa6 100644 --- a/packages/ragbits-core/src/ragbits/core/utils/_pyproject.py +++ b/packages/ragbits-core/src/ragbits/core/utils/_pyproject.py @@ -5,19 +5,6 @@ from pydantic import BaseModel -def _get_current_dir(current_dir: Path | None = None) -> Path: - """ - Returns the current directory if `current_dir` is None. - - Args: - current_dir (Path, optional): The directory to check. Defaults to None. - - Returns: - Path: The current directory. - """ - return current_dir or Path.cwd() - - def find_pyproject(current_dir: Path | None = None) -> Path: """ Find the pyproject.toml file in the current directory or any of its parents. @@ -32,7 +19,7 @@ def find_pyproject(current_dir: Path | None = None) -> Path: Raises: FileNotFoundError: If the pyproject.toml file is not found. """ - current_dir = _get_current_dir(current_dir) + current_dir = current_dir or Path.cwd() possible_dirs = [current_dir, *current_dir.parents] for possible_dir in possible_dirs: @@ -56,7 +43,7 @@ def get_ragbits_config(current_dir: Path | None = None) -> dict[str, Any]: Returns: dict: The ragbits configuration. """ - current_dir = _get_current_dir(current_dir) + current_dir = current_dir or Path.cwd() try: pyproject = find_pyproject(current_dir) @@ -89,7 +76,7 @@ def get_config_instance( Returns: ConfigModelT: The model instance loaded with the configuration """ - current_dir = _get_current_dir(current_dir) + current_dir = current_dir or Path.cwd() config = get_ragbits_config(current_dir) print(config)