stratified_packager.processing.material
Phase-A → Phase-B/C hand-off records and their shared helpers (SPEC §8).
The plain dataclasses the algorithm fills during Phase A and consumes while building and
zipping (_Inputs, _LayerPrep, _PayloadPrep, _Material,
_BuildState), plus the small helpers that several phase modules share
(_field_indexes(), _warm_file_name(), _is_warm_marked()). Kept here so
the extracted phase modules (dedup, reporting) and the orchestrator all
depend on one lower-layer module rather than on each other.
Functions
|
Total a phase's measured times and name its slowest few, worst first. |
- class stratified_packager.processing.material._BuildState(total_units, done_units=0, succeeded=set(), failed=dict(), published=list(), failed_zips=dict(), layer_results=dict(), zip_futures=list(), cold_fallbacks=dict(), matched_union=dict(), failed_warm=dict())[source]
Mutable bookkeeping of the sequential build and the background zip pool.
- Parameters:
total_units (
int)done_units (
int)layer_results (
dict[tuple[str,str],LayerWriteResult])zip_futures (
list[Future[ZipOutcome]])
- __init__(total_units, done_units=0, succeeded=<factory>, failed=<factory>, published=<factory>, failed_zips=<factory>, layer_results=<factory>, zip_futures=<factory>, cold_fallbacks=<factory>, matched_union=<factory>, failed_warm=<factory>)
- Parameters:
total_units (
int)done_units (
int)layer_results (
dict[tuple[str,str],LayerWriteResult])zip_futures (
list[Future[ZipOutcome]])
- failed_warm: dict[str, str]
Stratum name -> error of its failed §11 warm-cache write (the deliverable still builds — cold — but a requested-yet-unwritten cache fails the run at the end).
- layer_results: dict[tuple[str, str], LayerWriteResult]
(stratum name, layer id)-> the layer’s write outcome (the dedup primary’s id).
- matched_union: dict[str, set[int]]
Dedup-primary layer id -> union of matched fids across strata (§9.1 orphans).
- zip_futures: list[Future[ZipOutcome]]
- class stratified_packager.processing.material._Inputs(layers, payload_layers, embedded_layers, strat_layer, name_expression, gpkg_expression, zip_expression, output_dir, compression_level, overwrite_mode, project_inclusion, use_temp_folder, strata_from_selection, include_styles, style_categories, include_metadata, keep_empty_layers, deduplicate, stage_providers, export_full, generate_report, write_checksums, extra_dir, warm_dir, use_warm, update_warm, full_package_path, dry_run)[source]
Every input of SPEC §3, resolved through the §5 chain to typed values.
- Parameters:
layers (
list[QgsVectorLayer])payload_layers (
list[QgsMapLayer])embedded_layers (
list[QgsMapLayer])strat_layer (
QgsVectorLayer|None)name_expression (
str)gpkg_expression (
str)zip_expression (
str)output_dir (
Path)compression_level (
int)overwrite_mode (
OverwriteMode)project_inclusion (
ProjectInclusion)use_temp_folder (
bool)strata_from_selection (
bool)include_styles (
bool)style_categories (
StyleCategory)include_metadata (
bool)keep_empty_layers (
bool)deduplicate (
bool)export_full (
bool)generate_report (
bool)write_checksums (
bool)use_warm (
bool)update_warm (
bool)full_package_path (
str)dry_run (
bool)
- __init__(layers, payload_layers, embedded_layers, strat_layer, name_expression, gpkg_expression, zip_expression, output_dir, compression_level, overwrite_mode, project_inclusion, use_temp_folder, strata_from_selection, include_styles, style_categories, include_metadata, keep_empty_layers, deduplicate, stage_providers, export_full, generate_report, write_checksums, extra_dir, warm_dir, use_warm, update_warm, full_package_path, dry_run)
- Parameters:
layers (
list[QgsVectorLayer])payload_layers (
list[QgsMapLayer])embedded_layers (
list[QgsMapLayer])strat_layer (
QgsVectorLayer|None)name_expression (
str)gpkg_expression (
str)zip_expression (
str)output_dir (
Path)compression_level (
int)overwrite_mode (
OverwriteMode)project_inclusion (
ProjectInclusion)use_temp_folder (
bool)strata_from_selection (
bool)include_styles (
bool)style_categories (
StyleCategory)include_metadata (
bool)keep_empty_layers (
bool)deduplicate (
bool)export_full (
bool)generate_report (
bool)write_checksums (
bool)use_warm (
bool)update_warm (
bool)full_package_path (
str)dry_run (
bool)
- embedded_layers: list[QgsMapLayer]
- layers: list[QgsVectorLayer]
- overwrite_mode: OverwriteMode
- payload_layers: list[QgsMapLayer]
- project_inclusion: ProjectInclusion
- strat_layer: QgsVectorLayer | None
- style_categories: StyleCategory
- class stratified_packager.processing.material._LayerPrep(layer, table, plan, read_layer, kept_fields, kept_field_indexes, excluded_fields, subset_sql='', qml='', sld='', metadata_xml='', staged=False, group_primary_id=None)[source]
Phase-A material of one packaged vector layer.
- Parameters:
- __init__(layer, table, plan, read_layer, kept_fields, kept_field_indexes, excluded_fields, subset_sql='', qml='', sld='', metadata_xml='', staged=False, group_primary_id=None)
- group_primary_id: str | None = None
Dedup groups (§12): the primary member’s layer id when this prep rides a shared table (the primary points at itself); None outside any group.
- kept_field_indexes: tuple[int, ...]
kept_fieldsresolved to indexes intoread_layer.fields()(the writer drops the rest); empty exports every field.
- kept_fields: tuple[str, ...]
Exported field names after exclusions (and the §12 dedup union on a primary).
- layer: QgsVectorLayer
The user’s layer (styles, names, the embedded-project source); never read for data.
- plan: LayerMatchPlan
- read_layer: QgsVectorLayer
The standalone layer the per-stratum write reads and selects from — a clone of
layer, or a layer over the staging/full-package gpkg. Never a project layer, so its selection is mutated freely.
- staged: bool = False
Whether
read_layeris a staging copy (§8.2) — set on the group primary (or an ungrouped layer); non-primary members read through their primary’s staged table.
- class stratified_packager.processing.material._Material(project, inputs, preps=list(), payloads=list(), assets=dict(), bundles=dict(), zip_roots=dict(), gpkg_paths=dict(), zip_of_stratum=dict(), warm_marked_ids=set(), project_only_ids=set(), warm_prefetch=dict(), layer_name_expressions=dict(), initial_view=None, embedded_xml=dict(), template_path=None, chain_context=ChainContext())[source]
Everything Phase A hands to Phases B/C (one object instead of long params).
- Parameters:
project (
QgsProject)inputs (
_Inputs)preps (
list[_LayerPrep])payloads (
list[_PayloadPrep])bundles (
dict[str,tuple[StratumSpec,...]])initial_view (
QgsReferencedRectangle|None)chain_context (
ChainContext)
- __init__(project, inputs, preps=<factory>, payloads=<factory>, assets=<factory>, bundles=<factory>, zip_roots=<factory>, gpkg_paths=<factory>, zip_of_stratum=<factory>, warm_marked_ids=<factory>, project_only_ids=<factory>, warm_prefetch=<factory>, layer_name_expressions=<factory>, initial_view=None, embedded_xml=<factory>, template_path=None, chain_context=<factory>)
- Parameters:
project (
QgsProject)inputs (
_Inputs)preps (
list[_LayerPrep])payloads (
list[_PayloadPrep])bundles (
dict[str,tuple[StratumSpec,...]])initial_view (
QgsReferencedRectangle|None)chain_context (
ChainContext)
- bundles: dict[str, tuple[StratumSpec, ...]]
- chain_context: ChainContext
The run’s relation-chain resolution context (§7.1): staged intermediate hop layers plus the bounded memo that stops every layer sharing a chain — and Phase B after Phase A — from re-querying the same hops for the same stratum.
- embedded_xml: dict[str, str]
Layer id -> serialized
<maplayer>document for the §13 embedded-only layers, snapshotted once in Phase A; empty unless an embedded project is built. Every stratum’s project rebuilds them from these bytes rather than reopening their (often remote) source.
- initial_view: QgsReferencedRectangle | None = None
The source project’s initial map view (§13), snapshotted in Phase A;
Noneunless an embedded project is built or the source has no resolvable view.
- layer_name_expressions: dict[str, str]
Layer id -> non-empty
stratified_packager_layer_nameexpression text (SPEC §4), snapshotted and parse-validated in Phase A; empty unless an embedded project is built.
- payloads: list[_PayloadPrep]
- preps: list[_LayerPrep]
- project: QgsProject
- project_only_ids: set[str]
Layer ids carrying
matching_method = project_only(§4) — a subset of_Inputs.embedded_layers, whose data source the embedded project re-points at each stratum’s gpkg (§13) instead of carrying it over unchanged.
- template_path: Path | None = None
The §8.1.5 template gpkg (non-warm-marked whole-export layers), if built.
- class stratified_packager.processing.material._PayloadPrep(layer, table, members, layer_type, project_source='')[source]
Phase-A material of one whole-export raster/mesh/point-cloud layer (SPEC §14).
- Parameters:
- __init__(layer, table, members, layer_type, project_source='')
- layer: QgsMapLayer
- stratified_packager.processing.material._field_indexes(layer, names)[source]
Resolve field names to their indexes in layer, in field order.
- Parameters:
layer (
QgsVectorLayer) – The layer whose schema is indexed.names (
Collection[str]) – The field names to keep.
- Return type:
- Returns:
The matching indexes in field order (an empty tuple keeps every field).
- stratified_packager.processing.material._is_warm_marked(layer)[source]
Report whether a layer carries
stratified_packager_warm_marked = true(§11).Coerced with the same strict
coerce_bool()every other boolean layer variable uses (§4/§6 strict regime).- Parameters:
layer (
QgsMapLayer) – The packaged layer.- Return type:
- Returns:
Whether the layer belongs to the warm cache.
- Raises:
QgsProcessingException – If the variable holds an uncoercible value.
- stratified_packager.processing.material._warm_file_name(stratum_name)[source]
Map a stratum key to its warm-cache file basename (§11).
- stratified_packager.processing.material.slowest_summary(elapsed)[source]
Total a phase’s measured times and name its slowest few, worst first.
qgis_processblock-buffers stdout, so a harness that timestamps the piped lines timestamps flushes, not work: a stall inside a stratum cannot be attributed to the step that caused it from those timestamps (dozens of lines arrive in one millisecond-wide burst). Measuring in-process and carrying the numbers in the message body is what makes the attribution survive the buffering. Callers own their own sentence — the phases read differently and a shared one would not translate.
- stratified_packager.processing.material._SLOWEST_REPORTED: Final = 3
How many of a phase’s slowest entries
slowest_summary()names.