# TODO: This needs to be updated to match using `create_package_properties()`.
import tempfile
from pathlib import Path
import seedcase_sprout.core as sp
# Create a temporary directory for the example
with tempfile.TemporaryDirectory() as temp_dir:
= Path(temp_dir)
temp_path
# Create a package structure first
=temp_path)
sp.create_package_structure(path
# Edit package properties
sp.edit_package_properties(=temp_path / "1" / "datapackage.json",
path=sp.PackageProperties(
properties="New Package Title",
title="new-package-name",
name="New Description",
description
), )
edit_package_properties
🚧 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.edit_package_properties(path: Path, properties: PackageProperties)
Edits the properties of an existing package.
Use this any time you want to edit the package’s properties and particularly after using create_package_structure()
. Because create_package_structure()
also creates an empty datapackage.json
file, edit_package_properties()
is used to fill in the properties file with details specific for the package.
When you need to edit the datapackage.json
properties, use this function to ensure the properties are correctly structured and written. It only edits the properties of the package itself, not on the data resources contained within the package.
If the values in properties
are well-formed, they will overwrite any preexisting values within the original package properties.
Parameters
path : Path
-
The path to the
datapackage.json
file. Usepath_properties()
to provide the correct path. properties : PackageProperties
-
The new package properties to update from the original. Use
PackageProperties
to provide a correctly structured properties dictionary. Seehelp(PackageProperties)
for details on how to use it.
Returns
PackageProperties
-
The updated package properties as a Python dictionary that mimics the JSON structure. Use
write_package_properties()
to save it back to thedatapackage.json
file.
Raises
FileNotFound
-
If the
datapackage.json
file doesn’t exist. JSONDecodeError
-
If the
datapackage.json
file couldn’t be read. ExceptionGroup
-
If there is an error in the current, incoming or resulting package properties. A group of
CheckError
s, one error for each failed check.