stratified_packager.processing.algorithm
The Stratified Packager Processing algorithm: orchestration of Phases A/B/C (SPEC §8).
All user-facing messaging inside algorithm execution goes through the
qgis.core.QgsProcessingFeedback instance supplied by the Processing
framework — never the plugin logger (whose records do not reach the algorithm’s log
panel or qgis_process output). Fatal failures raise
qgis.core.QgsProcessingException, the framework’s sanctioned failure path;
per-stratum failures are contained (best-effort policy, SPEC §17) and surface in one
final exception listing the failed strata. Helpers invoked during execution take the
feedback as an explicit parameter.
Build layout: every zip gets its own build root mirroring the zip’s internal layout
(gpkgs at their gpkg_rel paths, data/ and resources/ beside them), so
Qt’s relative-path storage produces portable ./… sources in embedded projects
(SPEC §13) and zip assembly is a plain tree walk. The Phase-A→B/C records and the
per-phase helpers live in the sibling material, dedup, virtual and reporting
modules; this module orchestrates them.
Classes
|
|
- class stratified_packager.processing.algorithm.StratifiedPackagerAlgorithm(*args, **kwargs)[source]
stratified_packager:package— one zipped GeoPackage per stratum (SPEC §1).- classmethod tr(sourceText, disambiguation=None, n=-1)[source]
Get the translation for a string using Qt translation API.
- Parameters:
sourceText (
str) – String for translation.disambiguation (
str|None) – Identifying string for when the same text is used in different roles within the context.n (
int) – Number to support plural forms. https://doc.qt.io/qt-6/i18n-source-translation.html#handle-plural-forms
- Return type:
- Returns:
Translated version of the source text.
- _apply_overwrite_mode(inputs, resolution, report_rows, feedback)[source]
Apply
OVERWRITE_MODEto the bundle map (§10, §15).- Parameters:
inputs (
_Inputs) – The resolved inputs.resolution (
StrataResolution) – The strata resolution.report_rows (
list[RunReportRow]) – Mutable run-report rows (skip rows are appended).feedback (
QgsProcessingFeedback) – Execution feedback channel.
- Return type:
dict[str,tuple[StratumSpec,...]]- Returns:
The surviving bundles.
- Raises:
QgsProcessingException – In
errormode when any target exists.
- _build_and_zip(material, builds, warm_builds, workdir, pool, cancel, feedback)[source]
Build every stratum gpkg on this thread, zipping finished bundles in the background.
On
WARM_START_MODE=updateruns the §11 warm pass runs first: every stratum’s warm cache is written and atomically published before any deliverable is built, so an interrupted run still leaves a complete, reusable cache. The deliverables then seed from the fresh cache; a stratum whose cache write failed builds cold. OnWARM_START_MODE=useruns a member whose §11 prefetch landed seeds in place — its cache already sits at the build path.Bundles run in order and their strata in sequence (SPEC §8.4); a bundle’s zip is submitted once its members are written, so the next bundle builds while this one compresses. Cancellation propagates into the in-flight zip jobs.
- Parameters:
material (
_Material) – The run material.builds (
Mapping[str,StratumBuild]) – The stratum builds by sanitized name.warm_builds (
Sequence[StratumBuild]) – The §11 warm-pass builds (empty unlessWARM_START_MODE=update).workdir (
Path) – The run’s build directory.pool (
ThreadPoolExecutor) – The run-scoped background pool.cancel (
Event) – The run’s cancellation event.feedback (
QgsProcessingFeedback) – Execution feedback channel.
- Return type:
- Returns:
The final build state.
- _build_template(material, workdir, feedback)[source]
Write the §8.1.5 template gpkg once (non-warm-marked whole-export primaries).
Each covered stratum is then seeded by a plain copy of the template; only its partitioned layers (and the per-stratum styles) are written afterwards. The template also becomes the covered layers’ read source (§8.2): a warm-seeded stratum (§11) cannot take the template seed, so it writes these layers per stratum — from the local template copy, not the original source again.
- Parameters:
material (
_Material) – The run material.workdir (
Path) – The run’s build directory.feedback (
QgsProcessingFeedback) – Execution feedback channel.
- Raises:
QgsProcessingException – If the template writer fails or a written template table cannot be opened back as the read source.
- Return type:
- _chain_hop_fields(material)[source]
Collect the fields every relation chain queries on each intermediate hop layer (§7.1).
The last hop of a chain is never queried — its far-side keys are the membership condition — so only the layers a chain passes through are collected. Each hop reads its own
to_fields(matched against the incoming keys) and the next hop’sfrom_fields(collected as the outgoing keys).
- _clone(layer, feedback)[source]
Clone layer into a standalone read layer (its subset string rides along, §8.2).
A lazy virtual clone is loaded before the validity check (
load_lazy_virtual()), both so its features can be read at all and so a query that fails surfaces here rather than as an empty table. A read source exposing no fields is the signature of a provider that never loaded its data, which no packaged layer does on purpose — it is warned about rather than silently written out empty.- Parameters:
layer (
QgsVectorLayer) – The user’s layer (never mutated).feedback (
QgsProcessingFeedback) – Execution feedback channel.
- Return type:
- Returns:
An independent clone whose selection may be freely changed.
- Raises:
QgsProcessingException – If the clone is invalid.
- _collect_layer_name_expressions(layers)[source]
Snapshot and parse-validate the §4
layer_nameexpressions at run start.Consulted only when an embedded project is built. A parse error is the fail-fast; the per-stratum evaluation in
_project_plan()surfaces eval/NULL errors later.- Parameters:
layers (
Sequence[QgsMapLayer]) – Every layer that may appear in an embedded project.- Return type:
- Returns:
Layer id -> non-empty expression text.
- Raises:
QgsProcessingException – If a layer’s expression fails to parse.
- _collect_layers(parameters, context, project, feedback)[source]
Resolve
LAYERSand classify the packaged layers by handling (§4 fixed-by-type).Plugin layers are excluded with a warning — they are reported here, not returned.
- Parameters:
context (
QgsProcessingContext) – The processing context.project (
QgsProject) – The run’s project.feedback (
QgsProcessingFeedback) – Execution feedback channel.
- Return type:
tuple[list[QgsVectorLayer],list[QgsMapLayer],list[QgsMapLayer]]- Returns:
(vector, payload (local raster/mesh/point-cloud), embedded-only (remote/annotation/live virtual/project-only))layers.- Raises:
QgsProcessingException – If a layer’s
excludevariable cannot be coerced to bool while resolving an emptyLAYERS(§5 strict regime).
- _discard_workdir(material, workdir, feedback)[source]
Release the run’s workdir-backed layer handles, then remove the build directory (§10).
The preps’ read layers sit over GeoPackages inside the workdir (staging copies, the whole-export template), as do the chain context’s staged hop copies (§8.2); while those layers are alive GDAL holds the files open and Windows refuses to delete them. Dropping the references (plus a GC pass for cycles) releases the handles so the removal can succeed. Residue surviving the retries — e.g. a handle a failed run’s traceback still pins — is reported and left behind (best-effort, §17).
- Parameters:
material (
_Material) – The run material; its layer-holding fields are cleared in place.workdir (
Path) – The run’s build directory.feedback (
QgsProcessingFeedback) – Execution feedback channel.
- Return type:
- _distinct_layers(layers, feedback)[source]
Drop repeated identities from a resolved
LAYERSvalue, reporting the loss (§5).A caller that identifies layers by data source rather than by id — a saved model, a script,
qgis_process --LAYERS=<source>— cannot distinguish layers sharing one source (§12):mapLayerFromString()answers every such string with the same first match. The siblings are unrecoverable from the value alone, so name what collapsed instead of failing or guessing, and keep one entry per layer so the run does not write the survivor once per lost sibling.- Parameters:
layers (
Sequence[QgsMapLayer]) – The layersLAYERSresolved to, repeats included.feedback (
QgsProcessingFeedback) – Execution feedback channel.
- Return type:
- Returns:
The layers in input order, first occurrence of each id only.
- _emit_run_report(parameters, context, report_rows, feedback)[source]
Write the run-level report (§9.1) into the
REPORTfeature sink.The destination is whatever
REPORTresolves to: a memory table (loaded into the project by the GUI) when no path is given, or a file otherwise. Always produced — onDRY_RUNtoo — independent ofGENERATE_REPORT, which gates only the per-zipreport.csv(§9.2). The sink’s columns are theRunReportRowfields.- Parameters:
parameters (
dict[str|None,Any]) – Raw parameter values (carry theREPORTdestination).context (
QgsProcessingContext) – The processing context.report_rows (
Sequence[RunReportRow]) – The run-report rows, in the intended order.feedback (
QgsProcessingFeedback) – Execution feedback channel.
- Return type:
- Returns:
The sink destination id (the memory layer id, or the written path).
- Raises:
QgsProcessingException – If QGIS cannot create the sink or accept a row.
- _excluded_fields(layer)[source]
Read the layer’s
excluded_fieldsvariable (§4).- Parameters:
layer (
QgsVectorLayer) – The packaged layer.- Return type:
- Returns:
The excluded field names.
- Raises:
QgsProcessingException – If the variable is not a JSON list of strings.
- _finalize_members(material, members, state, feedback)[source]
Build the embedded project of each successful member (§13, Phase C).
Two failure regimes (SPEC §4 vs §17): assembling the member’s plan evaluates the
layer_nameexpressions — a §4-strict eval error/NULL fails the stratum (the member leaves the succeeded set and its gpkg is discarded). Once the plan exists, an embedded-project write failure is non-fatal degraded delivery (§17): the member’s data gpkg is intact and still ships — without the embedded project — and a warning is pushed. Genuine data failures are contained upstream in the worker pool, not here.- Parameters:
material (
_Material) – The run material.members (
Sequence[StratumSpec]) – The bundle’s successful members.state (
_BuildState) – The pool state.feedback (
QgsProcessingFeedback) – Execution feedback channel.
- Return type:
- _finish_dry_run(material, strata, report_rows, parameters, context, feedback)[source]
Conclude a dry run: report only, no packages (§9.1).
- Parameters:
material (
_Material) – The run material.strata (
Sequence[StratumSpec]) – The surviving strata.report_rows (
list[RunReportRow]) – Mutable run-report rows.parameters (
dict[str|None,Any]) – Raw parameter values (carry theREPORTdestination).context (
QgsProcessingContext) – The processing context.feedback (
QgsProcessingFeedback) – Execution feedback channel.
- Return type:
- Returns:
The §3 outputs map (no zips).
- _fold_result(state, result, feedback)[source]
Fold one stratum’s write outcome into the build state and the feedback (§9/§11).
- Parameters:
state (
_BuildState) – The build state.result (
StratumWriteResult) – The stratum write result.feedback (
QgsProcessingFeedback) – Execution feedback channel.
- Return type:
- _fold_warm_result(state, result, feedback)[source]
Fold one §11 warm-pass outcome into the build state and the feedback.
Deliverable accounting (
succeeded/failed/layer_results) is untouched: the deliverable pass re-reports every layer (warm-seeded ones aswarm), and a failed cache write only costs that stratum its warm seed — it still builds and ships cold; the missing cache fails the run at the end. The matched fids do fold in: the warm-seeded deliverable reports none for those layers, so the §9.1 orphan union needs the warm pass’s.- Parameters:
state (
_BuildState) – The build state.result (
StratumWriteResult) – The warm-cache write result.feedback (
QgsProcessingFeedback) – Execution feedback channel.
- Return type:
- _fold_zip(state, outcome, feedback)[source]
Fold one bundle’s zip outcome into the build state and the feedback.
- Parameters:
state (
_BuildState) – The build state.outcome (
ZipOutcome) – The zip outcome.feedback (
QgsProcessingFeedback) – Execution feedback channel.
- Return type:
- _layer_write(prep, material, *, to_root='')[source]
Build one (primary) prep’s
LayerWrite.A dedup primary carries every group member’s plan — membership is their union — and every member’s style (the primary’s loads by default). to_root sets the per-stratum
resources/prefix used to rewrite the QML asset paths.- Parameters:
prep (
_LayerPrep) – The (primary) layer prep.material (
_Material) – The run material.to_root (
str) – The stratum’s relative prefix back to its zip root.
- Return type:
- Returns:
The layer write.
- _layout_zip_roots(material, workdir)[source]
Create one zip-mirror build root per bundle and map every member’s build path (§10).
Needs only the bundle layout, so it runs before Phase A — the §11 warm prefetch can then copy cache files straight to their final build paths while Phase A works.
- _make_workdir(inputs, feedback)[source]
Create the run-scoped build directory, sweeping stale leftovers first (§10).
- Parameters:
inputs (
_Inputs) – The resolved inputs.feedback (
QgsProcessingFeedback) – Execution feedback channel.
- Return type:
- Returns:
The build directory (under the Processing temp folder, or under the output directory when
USE_TEMP_FOLDERis off).
- _maybe_submit_zip(pool, state, material, zip_rel, members, workdir, cancel, feedback)[source]
Finalize a finished bundle (Phase C) and submit its zip to the background pool.
Embedded projects for the successful members, then the per-zip report, then the zip job. A bundle whose members all failed is recorded as a failed zip.
- Parameters:
pool (
ThreadPoolExecutor) – The background pool.state (
_BuildState) – The build state.material (
_Material) – The run material.zip_rel (
str) – The bundle’s zip path (no extension).members (
Sequence[StratumSpec]) – The bundle’s member strata.workdir (
Path) – The run’s build directory.cancel (
Event) – The run’s cancellation event.feedback (
QgsProcessingFeedback) – Execution feedback channel.
- Return type:
- _metadata_payload(layer, inputs)[source]
Serialize the layer’s QMD metadata (§8.1 step 4).
- Parameters:
layer (
QgsMapLayer) – The packaged layer.inputs (
_Inputs) – The resolved inputs.
- Return type:
- Returns:
The QMD XML, or an empty string when metadata is excluded.
- _open_local(gpkg_path, table, label)[source]
Open a staged GeoPackage table as a standalone read layer (§8.2).
- Parameters:
- Return type:
- Returns:
The opened layer.
- Raises:
QgsProcessingException – If the table cannot be opened.
- _phase_a(material, strata, features_by_name, workdir, feedback)[source]
Analysis & staging: methods, staging copies, conditions, payloads, build roots.
- Parameters:
material (
_Material) – The run material being filled.strata (
Sequence[StratumSpec]) – The surviving strata.features_by_name (
Mapping[str,QgsFeature]) – Stratum features keyed by sanitized name.workdir (
Path) – The run’s build directory.feedback (
QgsProcessingFeedback) – Execution feedback channel.
- Raises:
QgsProcessingException – Per §4/§7/§8.2 validation rules.
- Return type:
- _phases_b_c(material, strata, *, warm_strata, features_by_name, workdir, report_rows, parameters, context, pool, cancel, feedback)[source]
Build the stratum gpkgs sequentially, embed projects, zip and publish per bundle.
GeoPackage writing stays on this thread (only it may touch QGIS); the background pool zips each finished bundle while the next bundle’s GeoPackages are built (SPEC §8).
- Parameters:
material (
_Material) – The run material.strata (
Sequence[StratumSpec]) – The surviving strata (deliverables;OVERWRITE_MODEapplied).warm_strata (
Sequence[StratumSpec]) – Every resolved stratum — the §11 update pass refreshes all caches, including strata whose deliverable was skip-existing filtered.features_by_name (
Mapping[str,QgsFeature]) – Stratum features keyed by sanitized name.workdir (
Path) – The run’s build directory.report_rows (
list[RunReportRow]) – Mutable run-report rows.parameters (
dict[str|None,Any]) – Raw parameter values (carry theREPORTdestination).context (
QgsProcessingContext) – The processing context.pool (
ThreadPoolExecutor) – The run-scoped background pool.cancel (
Event) – The run’s cancellation event.feedback (
QgsProcessingFeedback) – Execution feedback channel.
- Return type:
- Returns:
The §3 outputs map.
- Raises:
QgsProcessingException – On cancellation, or at the end when any stratum, zip, or warm-cache write failed (best-effort policy, §17).
Place each bundle’s shared
data/andresources/trees into its zip root (§13/§14).Hardlinked when the filesystem allows, copied otherwise, so embedded projects written beside the gpkgs resolve everything relatively. Runs at the end of Phase A (payloads and style assets are Phase-A products); the roots themselves are laid out earlier by
_layout_zip_roots().
- _prepare_vector_layer(layer, table, plan, inputs, feedback)[source]
Build one vector layer’s Phase-A prep over a plain clone (§8.1).
The read source starts as a clone of layer (its subset string rides along; the user’s layer is never read for data, so its selection and subset stay untouched). Staging happens later, per dedup group, in
_stage_preps()— afterapply_dedup()has merged shared-source layers — so a group shares one staging copy instead of building one per member. Conditions are not materialized here; the per-stratum write computes them lazily against the read source.- Parameters:
layer (
QgsVectorLayer) – The packaged vector layer.table (
str) – Its target table name.plan (
LayerMatchPlan) – Its matching plan.inputs (
_Inputs) – The resolved inputs.feedback (
QgsProcessingFeedback) – Execution feedback channel.
- Return type:
- Returns:
The prep.
- Raises:
QgsProcessingException – On a clone failure.
- _project_plan(material, member, state)[source]
Assemble one member’s embedded-project plan (§13).
- Parameters:
material (
_Material) – The run material.member (
StratumSpec) – The member stratum.state (
_BuildState) – The pool state (which tables were kept).
- Return type:
- Returns:
The plan.
- _resolve_inputs(parameters, context, project, settings, feedback)[source]
Resolve every input through explicit value > variable > setting > builtin.
- Parameters:
context (
QgsProcessingContext) – The processing context.project (
QgsProject) – The run’s project.settings (
StratifiedPackagerSettings) – The plugin settings.feedback (
QgsProcessingFeedback) – Execution feedback channel.
- Return type:
- Returns:
The typed inputs.
- Raises:
QgsProcessingException – On unusable stored defaults or missing requirements (§3 footnotes).
- _resolve_methods(inputs, project, ordered, feedback)[source]
Resolve every packaged layer’s matching method (§4); a full-only run is all whole-export.
- Parameters:
inputs (
_Inputs) – The resolved inputs.project (
QgsProject) – The run’s project.ordered (
Sequence[QgsVectorLayer]) – The packaged vector layers in tree order.feedback (
QgsProcessingFeedback) – Execution feedback channel.
- Return type:
- Returns:
One plan per layer id.
- Raises:
QgsProcessingException – Per the §4 rules, or if the relation manager is absent.
- _resolve_strat_layer(parameters, context, project, reader)[source]
Resolve
STRATIFICATION_LAYER(explicit, else the project variable’s layer id).- Parameters:
parameters (dict[str | None, Any]) – Raw parameter values.
context (QgsProcessingContext) – The processing context.
project (QgsProject) – The run’s project.
reader (params.InputReader) – The input reader.
- Return type:
QgsVectorLayer | None
- Returns:
The stratification layer, or
None.
- _resolve_strata_validated(inputs, project, feedback)[source]
Validate the stratification layer and resolve the strata (§6, §15).
- Parameters:
inputs (
_Inputs) – The resolved inputs.project (
QgsProject) – The run’s project.feedback (
QgsProcessingFeedback) – Execution feedback channel.
- Return type:
- Returns:
The strata resolution.
- Raises:
QgsProcessingException – Per the §6 strict rules (including the empty-selection fail-fast, raised by
resolve_strata()) and §3 footnote ¹.
- _scan_extra_dir(inputs, bundles, feedback)[source]
Reject EXTRA_DIR entries colliding with reserved zip content (§10, §15).
- Parameters:
inputs (
_Inputs) – The resolved inputs.bundles (
Mapping[str,tuple[StratumSpec,...]]) – The surviving bundles.feedback (
QgsProcessingFeedback) – Execution feedback channel.
- Raises:
QgsProcessingException – Listing every conflicting entry.
- Return type:
- _sld_text(layer)[source]
Serialize the layer’s SLD, best-effort (§8.1).
Prefer
exportSldStyleV3()(QGIS 3.44+; returns the document); below QGIS 3.44 it is absent, soexcept AttributeErrorfalls back to the deprecatedexportSldStyleV2(3.30). This guarded fallback is the sole sanctionedqgis.corebehavioral fallback (SPEC §1.1); it keeps V3 from raising the support floor.Unlike the QML (
exportNamedStyle()), the SLD is serialized in full — it is intentionally not scoped toSTYLE_CATEGORIES, because the SLD export API offers no category option and SLD represents only symbology and labeling. The category-filteredstyleQMLis the authoritative artifact (SPEC §13).- Parameters:
layer (
QgsMapLayer) – The packaged layer.- Return type:
- Returns:
The SLD XML (possibly empty or invalid; the caller guards validity).
- _stage_chain_hop(layer, names, match_sets, staging_dir, index, chain_context, feedback)[source]
Copy one intermediate hop layer locally and register it on the chain context (§8.2).
- Parameters:
layer (
QgsVectorLayer) – The project’s hop layer (cloned, never read for data nor mutated).names (
Collection[str]) – The field names the chain queries on this layer.match_sets (
Collection[tuple[str,...]]) – Distinct key field sets to index (theINfilters scan them).staging_dir (
Path) – The directory holding the staging GeoPackages.index (
int) – A per-run counter making the staging file name unique.chain_context (
ChainContext) – The run’s chain context, which receives the staged layer.feedback (
QgsProcessingFeedback) – Execution feedback channel.
- Raises:
QgsProcessingException – If the copy cannot be written or re-opened.
- Return type:
- _stage_chain_hops(material, staging_dir, feedback)[source]
Stage the intermediate hop layers of a
STAGE_PROVIDERSprovider (SPEC §7.1/§8.2).Relation-chain intermediates are read straight from the project, once per
INchunk per member per stratum — the one read path per-layer staging never covered, because staging only replaces a packaged layer’s read source. When such a hop sits on a provider the user declared slow, copy it once into a local GeoPackage holding just the fields the chain queries, index those, and resolve the chain against that copy instead.The copy holds every feature: a chain propagates keys through the whole intermediate, so the matched-union slice a packaged layer stages would silently drop rows. A layer that is both a packaged layer and a hop is therefore staged twice, once per role, which is redundant but correct.
A failure here is contained: hop staging is a read-amortization optimization, so the run falls back to reading the project layer rather than aborting.
- Parameters:
material (
_Material) – The run material (its chain context receives the staged layers).staging_dir (
Path) – The directory holding the staging GeoPackages.feedback (
QgsProcessingFeedback) – Execution feedback channel.
- Raises:
QgsProcessingException – On cancellation.
- Return type:
- _stage_layer(layer, plan, stage_providers)[source]
Resolve a partitioned layer’s staging decision (§8.2), wrapping the strict failure.
- Parameters:
layer (
QgsVectorLayer) – The packaged layer.plan (
LayerMatchPlan) – Its matching plan.stage_providers (
Collection[str]) – The resolvedSTAGE_PROVIDERSprovider keys.
- Return type:
- Returns:
Whether to stage the layer into a per-layer GeoPackage.
- Raises:
QgsProcessingException – If the stage variable is neither boolean nor
auto.
- _stage_prep(prep, group, material, real_features, staging_dir, feedback)[source]
Build one staging GeoPackage and swap prep’s read source onto it (§8.2).
The staged copy must be a superset of every read taken against it: the union of every group member’s matches across all strata — or all features when
EXPORT_FULL_PACKAGEis on, since the<full>stratum reads the whole staged copy.- Parameters:
prep (
_LayerPrep) – The group primary (or ungrouped) prep; mutated to read the staged copy.group (
Sequence[_LayerPrep]) – Every prep sharing the table (just prep when ungrouped).material (
_Material) – The run material.real_features (
Sequence[QgsFeature]) – The real strata features.staging_dir (
Path) – The directory holding per-layer staging GeoPackages.feedback (
QgsProcessingFeedback) – Execution feedback channel.
- Raises:
QgsProcessingException – On a staging write or transform failure.
- Return type:
- _stage_preps(material, real_features, staging_dir, feedback, *, skip_warm_staged)[source]
Stage the read sources that resolve
stage=true— once per dedup group (§8.2).Runs after
apply_dedup(), so a group of shared-source layers stages a single copy through its primary (whose read layer already carries the merged field union and cleared subset); ungrouped layers stage individually. Whole-export preps are skipped — the §8.1.5 template is their staged form. With skip_warm_staged, a group whose every member is warm-marked is not staged either: on aWARM_START_MODE=userun whose caches all passed the §11 pre-scan, nothing ever reads such a group’s staged copy.- Parameters:
material (
_Material) – The run material (primary preps mutated in place).real_features (
Sequence[QgsFeature]) – The real strata features (a staging copy unions across them).staging_dir (
Path) – The directory holding per-layer staging GeoPackages.feedback (
QgsProcessingFeedback) – Execution feedback channel.skip_warm_staged (
bool) – Whether fully-warm groups skip staging.
- Raises:
QgsProcessingException – On a bad stage variable, a staging write failure, or cancellation.
- Return type:
- _stratum_band(state, build, feedback)[source]
Return the feedback band covering build’s slice of the 25-95 % B/C range (SPEC §8.4).
The slice spans the build’s per-layer units from the current unit count, so the writer sweeps inside it and the following
_fold_*progress report lands exactly on the slice’s upper bound.- Parameters:
state (
_BuildState) – The build state (unit counters).build (
StratumBuild) – The stratum build about to be written.feedback (
QgsProcessingFeedback) – The run feedback.
- Return type:
- Returns:
The band proxy to hand to
write_stratum().
- _stratum_build(stratum, material, features_by_name)[source]
Assemble one stratum’s deliverable build plan (§8.3 step-3 ordering).
Layer order: warm-marked first, the whole-export template layers, then the partitioned layers. A dedup group contributes one layer (the primary’s), carrying every member’s plan and style.
WARM_START_MODE=updatedeliverables seed from the warm cache the §11 warm pass just wrote, exactly like aWARM_START_MODE=userun.- Parameters:
stratum (
StratumSpec) – The stratum.material (
_Material) – The run material.features_by_name (
Mapping[str,QgsFeature]) – Stratum features keyed by sanitized name (<full>absent).
- Return type:
- Returns:
The build plan.
- _style_documents(layer, inputs, feedback)[source]
Serialize the layer’s style: QML for the selected categories, SLD best-effort (§8.1).
- Parameters:
layer (
QgsMapLayer) – The packaged layer.inputs (
_Inputs) – The resolved inputs.feedback (
QgsProcessingFeedback) – Execution feedback channel.
- Return type:
- Returns:
(qml, sld)— both empty when styles are excluded.
- _submit_warm_prefetch(material, strata, pool, cancel)[source]
Queue background copies of the §11 warm caches to their build paths (warm runs only).
Submitted before Phase A, so a (possibly remote) cache file arrives while layers are prepared and staged; the deliverable pass then seeds in place instead of copying on the critical path. Best-effort: a failed or unfinished copy falls back to the normal seed-time copy from the original cache file.
- Parameters:
material (
_Material) – The run material (bundle layout already computed).strata (
Sequence[StratumSpec]) – The surviving strata (<full>included when it is exported).pool (
ThreadPoolExecutor) – The background pool.cancel (
Event) – The run’s cancellation event.
- Return type:
- _sweep_stale_workdirs(output_dir, feedback)[source]
Best-effort removal of day-old build directories a crashed run left behind (§10).
Only siblings past
_STALE_WORKDIR_AGEare touched — a younger.stratified_build_*directory could belong to a run still executing against the same output directory.- Parameters:
output_dir (
Path) – The run’s output directory.feedback (
QgsProcessingFeedback) – Execution feedback channel.
- Return type:
- _tree_ordered(project, layers)[source]
Order vector layers by layer-tree order (§12/§15 tie-breaking).
- Parameters:
project (
QgsProject) – The run’s project.layers (
Sequence[QgsVectorLayer]) – The packaged vector layers.
- Return type:
- Returns:
The ordered layers (tree order; unlisted ones keep input order).
- _tree_ordered_any(project, layers)[source]
Order any layers by layer-tree order.
- Parameters:
project (
QgsProject) – The run’s project.layers (
Sequence[QgsMapLayer]) – The layers to order.
- Return type:
- Returns:
The ordered layers (tree order; unlisted ones keep input order).
- _validate_warm_inputs(inputs)[source]
Enforce the §11 warm-start requirements at run start.
- Parameters:
inputs (
_Inputs) – The resolved inputs.- Raises:
QgsProcessingException – On a missing directory, an uncoercible
warm_markedvalue, or an empty warm-marked layer set.- Return type:
- _warm_cache_build(stratum, material, features_by_name, build_dir, warm_dir)[source]
Assemble one stratum’s §11 warm-pass build plan (
WARM_START_MODE=update).A fresh gpkg holding only the warm-marked primaries, assembled under build_dir and snapshot into the warm cache after its last layer lands. Empty warm tables are always kept — the cache stays complete regardless of
KEEP_EMPTY_LAYERS, which the deliverable pass applies when it seeds from the cache.- Parameters:
stratum (
StratumSpec) – The stratum.material (
_Material) – The run material.features_by_name (
Mapping[str,QgsFeature]) – Stratum features keyed by sanitized name (<full>absent).build_dir (
Path) – The workdir subdirectory holding the warm-pass builds.warm_dir (
Path) – The warm-cache directory (snapshot destination).
- Return type:
- Returns:
The build plan.
- _warm_covers_all_builds(material, strata, feedback)[source]
Pre-scan the §11 warm caches to decide whether warm-covered staging is skippable.
On a
WARM_START_MODE=userun a fully-warm dedup group’s staged copy is only ever read by a per-stratum cold fallback, so staging it is pure waste unless some stratum will actually fall back. Run the seed-time completeness check (warm_rejection()) against every build’s cache file up front: all usable → staging of fully-warm groups is skipped (§8.2); any rejection → staging proceeds and the run is warned once.- Parameters:
material (
_Material) – The run material (dedup applied, warm ids resolved).strata (
Sequence[StratumSpec]) – The surviving strata (<full>included when it is exported).feedback (
QgsProcessingFeedback) – Execution feedback channel.
- Return type:
- Returns:
Whether every build’s warm cache passes the §11 completeness check.
- _with_full_package(inputs, project, resolution)[source]
Append the
<full>pseudo-stratum whenEXPORT_FULL_PACKAGEis on (§3).FULL_PACKAGE_PATHis the full package’s (extensionless) zip path, relative toOUTPUT_DIRECTORYor absolute (§3,_full_package_zip_rel()); its in-zip gpkg path followsGPKG_PATH_EXPRESSION(empty ⇒ the zip basename), evaluated feature-less for<full>— never derived fromFULL_PACKAGE_PATHitself.- Parameters:
inputs (
_Inputs) – The resolved inputs.project (
QgsProject) – The run’s project (supplies the default basename).resolution (
StrataResolution) – The strata resolution.
- Return type:
- Returns:
The resolution, possibly extended by the full package.
- Raises:
QgsProcessingException – On an invalid full-package path, on a
GPKG_PATH_EXPRESSIONparse/evaluation/NULL error, or on any §6.5/§6.6 collision the re-bundling detects (case-variant zip paths, gpkg paths colliding inside a bundle the full package joins).
- _zip_job(material, zip_rel, workdir)[source]
Assemble one bundle’s zip job from its build root (§10).
- initAlgorithm(configuration=None)[source]
Declare the SPEC §3 inputs and outputs, defaults pre-resolved (SPEC §5).
- processAlgorithm(parameters, context, feedback)[source]
Run the algorithm: validation → Phase A → Phase B/C → report + outputs.
- Parameters:
parameters (dict[str | None, Any]) – Input parameter values, keyed by parameter name.
context (QgsProcessingContext) – Context in which the algorithm runs.
feedback (QgsProcessingFeedback | None) – The sole channel for user-facing messages, progress reporting, and cancellation during execution.
- Return type:
dict[str, Any]
- Returns:
Output value map, keyed by output name (SPEC §3 declared outputs).
- Raises:
qgis.core.QgsProcessingException – On a fatal error that must abort the run, and at the end of a best-effort run in which any stratum failed (listing the failed strata).
- class stratified_packager.processing.algorithm._BandFeedback(parent, start, end)[source]
Proxy feedback whose full 0-100 progress range maps into a band of a parent feedback.
Handed to a sub-operation (a
QgsVectorFileWriterwrite, or aQgsProcessingMultiStepFeedbackstepping over several of them), it scales the sub-operation’s rawsetProgresssweeps into the[start, end]slice of the run’s overall bar, so the bar always reads overall progress (SPEC §8.4). Messages and progress text forward to the parent unchanged; cancellation propagates from the parent the wayQgsProcessingMultiStepFeedbackpropagates it (a direct-connectedcanceledsignal, so no spinning event loop is needed).setProgress()is not virtual, so a C++ caller bypasses any Python override — the scaling therefore rides this object’s ownprogressChangedsignal, the same mechanismQgsProcessingMultiStepFeedbackuses.- Parameters:
parent (
QgsProcessingFeedback)start (
float)end (
float)
- __init__(parent, start, end)[source]
Wire the proxy onto parent.
- Parameters:
parent (
QgsProcessingFeedback) – The feedback receiving the scaled progress and forwarded messages.start (
float) – The parent progress this proxy’s0maps to.end (
float) – The parent progress this proxy’s100maps to.
- _parent
The wrapped feedback (also keeps the Python wrapper alive for C++ callees).
- _span
Parent progress distance covered by this proxy’s
0→100.
- _start
Parent progress at this proxy’s
0.
- stratified_packager.processing.algorithm._full_package_zip_rel(base, output_dir)[source]
Resolve
FULL_PACKAGE_PATHto the<full>bundle’s zip key (SPEC §3).A relative path keeps the §6.5 archive-path rules. An absolute one is honored as-is — like
EXTRA_DIR/WARM_START_DIR— but one resolving inside output_dir folds back to the relative form so bundling identity and the §6.6 collision checks keep seeing a single namespace. Only the basename of an outside-the-output-directory path is validated: its parent directories are the filesystem’s business and may legitimately already exist under names the strict filename rules reject.- Parameters:
- Return type:
- Returns:
The zip key: a
/-joined relative path, or an absolute posix path.- Raises:
ValueError – On a §6.5 shape violation; the message names the violation.
- stratified_packager.processing.algorithm._place(source, destination)[source]
Materialize source at destination (hardlink when possible, copy otherwise).
- stratified_packager.processing.algorithm._report_chain_memo(chain_context, feedback)[source]
Report how many §7.1 hop queries the chain memo saved, once per run.
Debug-level: the memo is an optimization whose effect never changes an output, so it belongs with the other diagnostics rather than in the run’s info stream.
- Parameters:
chain_context (
ChainContext) – The run’s relation-chain context.feedback (
QgsProcessingFeedback) – Execution feedback channel.
- Return type:
- stratified_packager.processing.algorithm._HOP_TABLE: Final = 'hop'
Table name inside a staged relation-chain intermediate’s GeoPackage (SPEC §7.1/§8.2); each hop layer gets its own file, so one fixed name never collides.
- stratified_packager.processing.algorithm._PAYLOAD_LAYER_TYPES: Final[frozenset[Qgis.LayerType]] = frozenset({qgis.core.Qgis.LayerType.Mesh, qgis.core.Qgis.LayerType.PointCloud, qgis.core.Qgis.LayerType.Raster})
Layer types packaged as a
data/payload copy when their source is local (SPEC §14).
- stratified_packager.processing.algorithm._POOL_WIDTH: Final = 2
Background pool width (SPEC §8.4).
One thread keeps zip packaging ahead of the sequential builds — a bundle’s zip is a single DEFLATE stream that finishes well within the next bundle’s build time, so jobs never queue (measured on the 94-zip field project: the pool never held more than one active zip) — and the second overlaps the §11 warm-cache prefetch with Phase A.
- stratified_packager.processing.algorithm._RESERVED_EXTRA_ROOTS: tuple[str, ...] = ('data', 'resources')
Zip-root directory names reserved for the packager’s own payloads (SPEC §10).
- stratified_packager.processing.algorithm._SQLITE_SIDECAR_SUFFIXES: tuple[str, ...] = ('-wal', '-shm', '-journal')
SQLite sidecar suffixes excluded from zips (checkpointed away beforehand, SPEC §10).
- stratified_packager.processing.algorithm._STALE_WORKDIR_AGE: Final = 86400.0
Minimum age in seconds before a leftover
.stratified_build_*directory from an earlier run is swept at run start (§10); younger siblings could belong to a live concurrent run against the same output directory.