ds_resource_plugin_py_lib.libs.utils

File: __init__.py Region: ds_resource_plugin_py_lib/libs/utils

Description

Internal shared libraries used by this package (utilities).

Submodules

Functions

import_string(→ Any)

Import a dotted module path and return the attribute/class designated by the last name in the path.

json_default(→ Any)

default callback for json.dumps().

sanitize_version(→ str)

Sanitize version string to ensure it follows a consistent format.

Package Contents

ds_resource_plugin_py_lib.libs.utils.import_string(dotted_path: str) Any[source]

Import a dotted module path and return the attribute/class designated by the last name in the path. :param dotted_path: The dotted module path to import.

Returns:

The attribute/class designated by the last name in the path.

Raise ImportError if the import failed.

ds_resource_plugin_py_lib.libs.utils.json_default(value: Any) Any[source]

default callback for json.dumps().

Maps common Python types (for example datetime) to JSON-serializable values. Scalar-like objects with a callable .item() (for example numpy scalars) are unwrapped before encoding. Unknown types raise TypeError, matching stdlib behavior.

bytes and bytearray are intentionally not converted: JSON has no binary type, and decoding bytes as text would silently change the data.

ds_resource_plugin_py_lib.libs.utils.sanitize_version(version: str) str[source]

Sanitize version string to ensure it follows a consistent format. We can receive versions written as semver (v1.0.0) or just the number (1.0.0). This function will strip any leading ‘v’ and whitespace.

Parameters:

version – The version string to sanitize.

Returns:

A sanitized version string.