stratified_packager.processing.project_builder
Embedded per-stratum project construction (SPEC §13).
Runs on the algorithm thread during Phase C — never against
instance(). The fresh project re-points included layers at
the stratum GeoPackage tables and the data/ payload copies, restores the layer-tree
structure (groups, order, visibility) restricted to included layers, applies the full
(rewritten) styles, remaps relations among included layers, and carries the project
CRS, transform context and title. Paths are stored relative: the caller builds the
stratum inside a directory tree that mirrors the zip layout, so Qt’s relative-path
storage produces portable ./… sources (SPEC §13).
Functions
|
Build and write one stratum's embedded project (SPEC §13). |
Classes
|
Everything needed to build one stratum's embedded project. |
- class stratified_packager.processing.project_builder.StratumProjectPlan(title, mode, gpkg_path, qgz_path=None, vector_tables=<factory>, data_sources=<factory>, embedded_only=(), styles_qml=<factory>, subsets=<factory>, display_names=<factory>)[source]
Everything needed to build one stratum’s embedded project.
- Parameters:
- __init__(title, mode, gpkg_path, qgz_path=None, vector_tables=<factory>, data_sources=<factory>, embedded_only=(), styles_qml=<factory>, subsets=<factory>, display_names=<factory>)
- data_sources: dict[str, Path]
Included payload layers: source layer id -> absolute path of the
data/copy inside the zip-mirror tree.
- display_names: dict[str, str]
Source layer id -> custom display name for this stratum (SPEC §4
layer_name, already evaluated). Absent ids keep the original layer name.
- embedded_only: tuple[str, ...] = ()
Source layer ids riding only in the project (remote sources, annotations).
- mode: ProjectInclusion
gpkg(project storage inside the GeoPackage) orqgz(file beside it).
- stratified_packager.processing.project_builder._append_unplaced(fresh, fresh_root, replacements, placed)[source]
Append included layers that had no source tree node (legend-less additions).
- Parameters:
fresh (
QgsProject) – The project under construction.fresh_root (
QgsLayerTreeGroup) – Its layer-tree root.replacements (
Mapping[str,QgsMapLayer]) – Source layer id -> replacement layer.placed (
set[str]) – Layer ids already placed by the tree walk.
- Return type:
- stratified_packager.processing.project_builder._apply_styles_and_subsets(plan, replacements, feedback)[source]
Apply the rewritten QML styles and re-apply subset strings.
- Parameters:
plan (
StratumProjectPlan) – The stratum’s project plan.replacements (
Mapping[str,QgsMapLayer]) – Source layer id -> replacement layer.feedback (
QgsProcessingFeedback) – Execution feedback channel.
- Return type:
- stratified_packager.processing.project_builder._build_layers(source, plan, feedback)[source]
Create the fresh project’s layers, keyed by their source layer id.
Broken layers are never included (SPEC §13 bad-layer policy) — a re-pointed layer that fails to open is dropped with a warning.
- Parameters:
source (
QgsProject) – The open project being packaged.plan (
StratumProjectPlan) – The stratum’s project plan.feedback (
QgsProcessingFeedback) – Execution feedback channel.
- Return type:
- Returns:
Source layer id -> replacement layer.
- stratified_packager.processing.project_builder._capture_log()[source]
Collect
QgsMessageLogentries emitted on the current thread.Surfaces why
write()failed: it returns only a bool while the cause is logged. The write runs synchronously on the algorithm thread, so its emissions invoke the handler before the block exits. The handler is a plain callable with no receiver thread affinity, so an unrelated emission from another thread during this window would run it on that thread — a tolerated, GIL-safe append of a stray line.- Yield:
The list each entry (
[tag] message) is appended to.
- stratified_packager.processing.project_builder._embedded_replacement(original, source, plan, feedback)[source]
Build the embedded-only replacement for one layer.
Live virtual layers are re-pointed at the stratum gpkg (
_rebuild_virtual_layer()); remote and annotation layers are cloned with their original sources.- Parameters:
original (QgsMapLayer) – The source project’s embedded-only layer.
source (QgsProject) – The open project being packaged.
plan (StratumProjectPlan) – The stratum’s project plan.
feedback (QgsProcessingFeedback) – Execution feedback channel.
- Return type:
QgsMapLayer | None
- Returns:
The replacement layer, or
Noneto drop it.
- stratified_packager.processing.project_builder._fast_open()[source]
Build the layer options of a re-pointed embedded-project layer.
loadDefaultStyle=False: the style is applied explicitly afterwards from the exported QML (the very payload the gpkglayer_stylesrows carry — _finalize_layer writes both from the same source), so the per-layer default-style lookup is a redundant read.skipCrsValidation=True: the CRS comes from the just-written gpkg (or the virtual query); there is nothing to interactively validate on a worker thread.- Return type:
- Returns:
The options for
QgsVectorLayerconstruction.
- stratified_packager.processing.project_builder._rebuild_virtual_layer(original, source, plan, feedback)[source]
Re-point a live virtual layer’s sources at this stratum’s gpkg tables.
Each source the virtual layer queries is rewritten to the GeoPackage table that holds that layer in this stratum; the query, uid and geometry definition are preserved. The layer is dropped (returning
None) when any source has no table in this stratum (e.g. an empty layer omitted underKEEP_EMPTY_LAYERS=False). Style and attribute-form config ride along by cloning the original and only swapping its data source.- Parameters:
original (QgsMapLayer) – The source project’s virtual layer.
source (QgsProject) – The open project being packaged (resolves source references).
plan (StratumProjectPlan) – The stratum’s project plan.
feedback (QgsProcessingFeedback) – Execution feedback channel.
- Return type:
QgsMapLayer | None
- Returns:
The re-pointed virtual layer, or
Noneto drop it.
- stratified_packager.processing.project_builder._remap_relations(source, fresh, replacements, feedback)[source]
Recreate the relations whose both ends are included.
Relations touching excluded layers are dropped.
- Parameters:
source (
QgsProject) – The open project being packaged.fresh (
QgsProject) – The project under construction.replacements (
Mapping[str,QgsMapLayer]) – Source layer id -> replacement layer.feedback (
QgsProcessingFeedback) – Execution feedback channel.
- Return type:
- stratified_packager.processing.project_builder._replicate_tree(source, fresh, replacements, feedback)[source]
Replicate the layer tree (groups, order, visibility) for included layers.
- Parameters:
source (
QgsProject) – The open project being packaged.fresh (
QgsProject) – The project under construction.replacements (
Mapping[str,QgsMapLayer]) – Source layer id -> replacement layer.feedback (
QgsProcessingFeedback) – Execution feedback channel.
- Return type:
- stratified_packager.processing.project_builder._resolve_virtual_source_table(src, source, plan)[source]
Find the stratum gpkg table backing one virtual-layer source.
References by layer id resolve directly; embedded sources match the first packaged layer with the same provider and source string.
- Parameters:
src (
SourceLayer) – A source layer of the virtual definition.source (
QgsProject) – The open project being packaged.plan (
StratumProjectPlan) – The stratum’s project plan.
- Return type:
- Returns:
The table name, or
Nonewhen the source is not packaged here.
- stratified_packager.processing.project_builder._write_failure_detail(plan, messages)[source]
Describe why
write()failed, for the raised exception.Prefers the captured log; falls back to filesystem facts about the destination when the log stayed silent.
- Parameters:
plan (
StratumProjectPlan) – The stratum’s project plan.messages (
Sequence[str]) – Captured log entries from_capture_log().
- Return type:
- Returns:
A single-line detail string.
- stratified_packager.processing.project_builder.build_stratum_project(source, plan, feedback)[source]
Build and write one stratum’s embedded project (SPEC §13).
- Parameters:
source (
QgsProject) – The open project being packaged (read-only here).plan (
StratumProjectPlan) – The stratum’s project plan.feedback (
QgsProcessingFeedback) – Execution feedback channel.
- Raises:
QgsProcessingException – If writing the project fails.
- Return type: