|
15 | 15 | from pydantic import AnyHttpUrl, TypeAdapter, ValidationError |
16 | 16 | from typing_extensions import deprecated |
17 | 17 |
|
| 18 | +from docling_core.types.doc.utils import relative_path # noqa |
18 | 19 | from docling_core.types.io import DocumentStream |
19 | 20 |
|
20 | 21 |
|
@@ -168,43 +169,3 @@ def resolve_file_source( |
168 | 169 | source=source, |
169 | 170 | headers=headers, |
170 | 171 | ) |
171 | | - |
172 | | - |
173 | | -def relative_path(src: Path, target: Path) -> Path: |
174 | | - """Compute the relative path from `src` to `target`. |
175 | | -
|
176 | | - Args: |
177 | | - src (str | Path): The source directory or file path (must be absolute). |
178 | | - target (str | Path): The target directory or file path (must be absolute). |
179 | | -
|
180 | | - Returns: |
181 | | - Path: The relative path from `src` to `target`. |
182 | | -
|
183 | | - Raises: |
184 | | - ValueError: If either `src` or `target` is not an absolute path. |
185 | | - """ |
186 | | - src = Path(src).resolve() |
187 | | - target = Path(target).resolve() |
188 | | - |
189 | | - # Ensure both paths are absolute |
190 | | - if not src.is_absolute(): |
191 | | - raise ValueError(f"The source path must be absolute: {src}") |
192 | | - if not target.is_absolute(): |
193 | | - raise ValueError(f"The target path must be absolute: {target}") |
194 | | - |
195 | | - # Find the common ancestor |
196 | | - common_parts = [] |
197 | | - for src_part, target_part in zip(src.parts, target.parts): |
198 | | - if src_part == target_part: |
199 | | - common_parts.append(src_part) |
200 | | - else: |
201 | | - break |
202 | | - |
203 | | - # Determine the path to go up from src to the common ancestor |
204 | | - up_segments = [".."] * (len(src.parts) - len(common_parts)) |
205 | | - |
206 | | - # Add the path from the common ancestor to the target |
207 | | - down_segments = target.parts[len(common_parts) :] |
208 | | - |
209 | | - # Combine and return the result |
210 | | - return Path(*up_segments, *down_segments) |
0 commit comments