Skip to content

Commit

Permalink
Unifying default dir argument assignment.
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrykWyzgowski committed Oct 14, 2024
1 parent 57ef338 commit 1246038
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 18 deletions.
3 changes: 1 addition & 2 deletions packages/ragbits-core/src/ragbits/core/prompt/promptfoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
19 changes: 3 additions & 16 deletions packages/ragbits-core/src/ragbits/core/utils/_pyproject.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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:
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 1246038

Please sign in to comment.