Skip to content

Commit e92f120

Browse files
committed
fix: path generation in case of relative file paths without artifact directory
Signed-off-by: Georg Heiler <[email protected]>
1 parent 8433d28 commit e92f120

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

docling_core/types/doc/document.py

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4532,16 +4532,47 @@ def _get_output_paths(
45324532
if isinstance(filename, str):
45334533
filename = Path(filename)
45344534
if artifacts_dir is None:
4535+
abs_filename = filename.resolve()
45354536
# Remove the extension and add '_pictures'
4536-
artifacts_dir = filename.with_suffix("")
4537-
artifacts_dir = artifacts_dir.with_name(artifacts_dir.name + "_artifacts")
4538-
if artifacts_dir.is_absolute():
4537+
artifacts_dir = abs_filename.with_name(
4538+
abs_filename.stem + "_artifacts"
4539+
)
4540+
#artifacts_dir = abs_filename.with_suffix("")
4541+
#artifacts_dir = artifacts_dir.with_name(artifacts_dir.name + "_artifacts")
4542+
if filename.is_absolute():
45394543
reference_path = None
45404544
else:
45414545
reference_path = filename.parent
45424546
artifacts_dir = reference_path / artifacts_dir
45434547

45444548
return artifacts_dir, reference_path
4549+
4550+
def _get_output_paths(
4551+
self, filename: Union[str, Path], artifacts_dir: Optional[Path] = None
4552+
) -> Tuple[Path, Optional[Path]]:
4553+
"""
4554+
Determines the output directory for artifacts and the reference path for URIs.
4555+
4556+
This function correctly handles absolute and relative paths for `filename`
4557+
and `artifacts_dir` without path duplication.
4558+
"""
4559+
if isinstance(filename, str):
4560+
filename = Path(filename)
4561+
if artifacts_dir is None:
4562+
# Default case: create an '_artifacts' directory alongside the file.
4563+
final_artifacts_dir = filename.with_name(filename.stem + "_artifacts")
4564+
else:
4565+
if isinstance(artifacts_dir, str):
4566+
artifacts_dir = Path(artifacts_dir)
4567+
if artifacts_dir.is_absolute():
4568+
final_artifacts_dir = artifacts_dir
4569+
else:
4570+
final_artifacts_dir = filename.parent / artifacts_dir
4571+
if final_artifacts_dir.is_absolute():
4572+
reference_path = None
4573+
else:
4574+
reference_path = filename.parent
4575+
return final_artifacts_dir, reference_path
45454576

45464577
def _make_copy_with_refmode(
45474578
self,

0 commit comments

Comments
 (0)