write_resource_properties

Warning

🚧 Sprout is still in active development and evolving quickly, so the documentation and functionality may not work as described and could undergo substantial changes 🚧

core.write_resource_properties(
    path: Path,
    resource_properties: ResourceProperties,
)

Writes the specified resource properties to the datapackage.json file.

This functions verifies resource_properties, and if a resource with that ID is already present on the package, the properties of that resource are updated. The values in resource_properties overwrite preexisting values. Otherwise, resource_properties is added as a new resource.

Parameters

path : Path

The path to the datapackage.json file. Use path_properties() to help give the correct path.

resource_properties : ResourceProperties

The resource properties to add. Use ResourceProperties to help create this object.

Returns

Path

The path to the updated datapackage.json file.

Raises

FileNotFound

If the datapackage.json file doesn’t exist.

ExceptionGroup

If there is an error in the properties. A group of CheckErrors, one error per failed check.

JSONDecodeError

If the datapackage.json file couldn’t be read.

Examples

import tempfile
from pathlib import Path

import seedcase_sprout.core as sp

# Create a temporary directory for the example
temp_dir = Path(tempfile.TemporaryDirectory().name)
temp_dir.mkdir()

# Create package and resource structure first
sp.create_package_structure(path=temp_dir)
sp.create_resource_structure(path=temp_dir / "1" / "resources")

# TODO: Write package properties that passes checks
# Write package properties
# sp.write_package_properties(
#     path=temp_dir / "1" / "datapackage.json",
#     package_properties=sp.PackageProperties(
#         title="New Package Title",
#         name="new-package-name",
#         description="New Description",
#     ),

# Write resource properties
# sp.write_resource_properties(
#     path=temp_dir / "1" / "datapackage.json",
#     resource_properties=sp.ResourceProperties(
#         name="new-resource-name",
#         title="New resource name",
#         description="This is a new resource",
#         path="data.parquet",
#     ),
# )
[PosixPath('/tmp/tmpro2nyoml/1/datapackage.json'),
 PosixPath('/tmp/tmpro2nyoml/1/README.md'),
 PosixPath('/tmp/tmpro2nyoml/1/resources')]
[PosixPath('/tmp/tmpro2nyoml/1/resources/1'),
 PosixPath('/tmp/tmpro2nyoml/1/resources/1/raw')]