trailpack.config.config_builder
Configuration builder for exporting UI session state to reusable JSON configs.
Functions
|
Build mapping configuration from column mappings. |
|
Build metadata configuration from general details. |
|
Serialize mapping config to JSON string. |
|
Serialize metadata config to JSON string. |
|
Generate a standardized filename for config export. |
Module Contents
- trailpack.config.config_builder.build_mapping_config(column_mappings: Dict[str, str], file_name: str, sheet_name: str, language: str = 'en') Dict[str, Any][source]
Build mapping configuration from column mappings.
- Parameters:
column_mappings – Dictionary mapping column names to ontology/unit IDs
file_name – Original file name
sheet_name – Sheet name
language – Language code for ontology mappings (default: “en”)
- Returns:
Dictionary with mapping configuration
Example
>>> mappings = { ... "Product": "https://vocab.sentier.dev/products/product/Product", ... "CO2_unit": "https://vocab.sentier.dev/units/unit/KiloGM" ... } >>> config = build_mapping_config(mappings, "data.xlsx", "Sheet1")
- trailpack.config.config_builder.build_metadata_config(general_details: Dict[str, Any]) Dict[str, Any][source]
Build metadata configuration from general details.
- Parameters:
general_details – Dictionary with package metadata from UI
- Returns:
Dictionary with metadata configuration
Example
>>> details = { ... "name": "my-dataset", ... "title": "My Dataset", ... "description": "Description here", ... "licenses": [{"name": "MIT", "path": "..."}], ... "contributors": [{"name": "John", "role": "author"}], ... } >>> config = build_metadata_config(details)
- trailpack.config.config_builder.export_mapping_json(config: Dict[str, Any], indent: int = 2) str[source]
Serialize mapping config to JSON string.
- Parameters:
config – Mapping configuration dictionary
indent – JSON indentation (default: 2)
- Returns:
JSON string
Example
>>> config = build_mapping_config({}, "data.xlsx", "Sheet1") >>> json_str = export_mapping_json(config)
- trailpack.config.config_builder.export_metadata_json(config: Dict[str, Any], indent: int = 2) str[source]
Serialize metadata config to JSON string.
- Parameters:
config – Metadata configuration dictionary
indent – JSON indentation (default: 2)
- Returns:
JSON string
Example
>>> config = build_metadata_config({"name": "my-dataset"}) >>> json_str = export_metadata_json(config)
- trailpack.config.config_builder.generate_config_filename(config_type: str, package_name: str | None = None, file_name: str | None = None, sheet_name: str | None = None) str[source]
Generate a standardized filename for config export.
- Parameters:
config_type – Type of config (“mapping” or “metadata”)
package_name – Package name if available
file_name – Original file name (fallback)
sheet_name – Sheet name (for mapping configs)
- Returns:
Filename string
Example
>>> generate_config_filename("mapping", "my-dataset") 'my-dataset_mapping_config.json' >>> generate_config_filename("mapping", None, "data.xlsx", "Sheet1") 'data_Sheet1_mapping_config.json'