Skip to content

Commit 25fce50

Browse files
committed
refactor: simplified path processing to use pathlib where possible
1 parent cdf449f commit 25fce50

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

src/humanloop/overload.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,10 @@ def _handle_local_files(
108108

109109
# Then check for file extensions
110110
if sync_client.is_file(path):
111-
try:
112-
parts = path.rsplit(".", 1)
113-
path_without_extension = parts[0] if len(parts) > 0 else path
114-
except Exception:
115-
path_without_extension = path
111+
# Extract the path without extension to suggest correct format in the error message
112+
path_without_extension = str(Path(path).with_suffix(""))
116113

114+
# Always raise error when file extension is detected (based on the outer if condition)
117115
raise HumanloopRuntimeError(
118116
f"Path '{path}' includes a file extension which is not supported in API calls. "
119117
f"When referencing files via the path parameter, use the format without extensions: '{path_without_extension}'. "

src/humanloop/path_utils.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ def normalize_path(path: str, strip_extension: bool = False) -> str:
88

99
# Handle extension
1010
if strip_extension:
11-
normalized = str(path_obj.with_suffix(""))
12-
else:
13-
normalized = str(path_obj)
11+
path_obj = path_obj.with_suffix("")
1412

15-
# Normalize separators
16-
return "/".join(part for part in normalized.replace("\\", "/").split("/") if part)
13+
# Use as_posix() to normalize separators consistently
14+
return path_obj.as_posix()

0 commit comments

Comments
 (0)