cdm_data_loaders.core.path_fields ¶
Path-related fields and utils for pipeline settings.
url_protocol ¶
Return the canonical protocol of a path or URL. Plain paths count as 'file'.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
path or URL |
required |
Returns:
| Type | Description |
|---|---|
str
|
lower-case protocol name, with aliases (e.g. s3a -> s3) applied |
Source code in src/cdm_data_loaders/core/path_fields.py
is_local ¶
check_local_path ¶
Strip whitespace and any local protocol from a string path.
Values that are not strings are returned unchanged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Any
|
path to check |
required |
Returns:
| Type | Description |
|---|---|
Any
|
the path without a protocol |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the path is empty or not on the local filesystem |
Source code in src/cdm_data_loaders/core/path_fields.py
to_absolute ¶
Return the absolute, resolved form of a path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
the path to resolve |
required |
Returns:
| Type | Description |
|---|---|
Path
|
absolute path |
ensure_dir ¶
Create a directory, converting OS errors to ValueError so pydantic reports them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
the directory to create |
required |
Returns:
| Type | Description |
|---|---|
Path
|
the path object |
Source code in src/cdm_data_loaders/core/path_fields.py
normalise_dir ¶
Remove trailing slashes from a directory path or URL, keeping roots such as '/' and 'file:///'.
Does not permit protocol-only paths, such as `https://`, `data:`, or `file://`
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
full_path
|
str | None
|
directory path or URL; may include the protocol |
required |
Returns:
| Type | Description |
|---|---|
str
|
the normalised path |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the path is empty or only contains a protocol |
Source code in src/cdm_data_loaders/core/path_fields.py
check_input_dir ¶
Validate and normalise a local directory path or fsspec directory URL.
Values that are not strings or Path objects are returned unchanged.
Local paths (Path objects, plain string paths, or file:// URLs)
must point to an existing directory and are resolved to an absolute path
string. Non-local URLs are stripped of trailing slashes, checked against
fsspec's registered protocols, and returned with a lower-case protocol.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Any
|
path or URL to validate |
required |
Returns:
| Type | Description |
|---|---|
Any
|
resolved absolute local path string or normalised fsspec URL string |
Raises:
| Type | Description |
|---|---|
ValueError
|
if the path is empty, protocol-only, or uses an unknown or uninstalled fsspec protocol |
PydanticCustomError
|
if a local path does not exist or is not a directory |