Skip to content

Setting Prophet and ili2py Integration#171

Draft
signedav wants to merge 5 commits into
mainfrom
ili2pyintegration
Draft

Setting Prophet and ili2py Integration#171
signedav wants to merge 5 commits into
mainfrom
ili2pyintegration

Conversation

@signedav

@signedav signedav commented Jul 3, 2026

Copy link
Copy Markdown
Member

Follow up of #160 - do not merge yet.

ili2py integration

  • install scripts (because not yet on pypi it's done over github) and packages used by ili2py (like xsdata and via xsdata typing-extension) 0ad15db
  • bridge implemented in ili2pytools.pythonizer containing BakerPyIndex extending ili2py Index reading the metamodel from imd and inits itself. Then it is able to return library and enumeration object as well as having some convenience functions to get e.g. the classes filtered by the relevant topics etc.
  • Tests of these functions

Model Prophet / Settings Prophet mplementation

  • util functions to compile the model using ilicompiler integration #160 (in modelbaker.utils)
  • ModelProphet to receive some infos controlled directly by the Plugin (etc.)
  • Tests for ModelProphet (and with it ili2py (maybe should be separated)

Structure

├── ili2pytools
│   ├── __init__.py
│   ├── pythonizer.py
|   |       - BakerPyIndex(imd_file)
|   |         - inits the Index extension via ili2py reader in the init
|   |         - library_object returns Library
|   |         - enumeration_object returns Enumeration
|   |         - convenience functions
│   ├── model_prophet.py (maybe to move somewhere else?)
|   |       - ModelProphet (with functions replying all the questions)
|   └── utils.py
|   |       - utilities to create e.g. TOML files / or in future SVG UML or load in QGIS (not yet sure)
├──  [...]
├── libs
│   ├── [...]
│   ├── ili2py

Bestandteile

BakerPyIndex:

Erbt Index und erhält imd file im init und erstellt sich selbst via reader damit. Er enthält einerseits funktionen um Library und Enumeration zurückzugeben sowie auch convenience Funktionen. Zbs: relevant_geometric_attributes_per_class, das mir die Geometriespalten per Klassenname zurückgibt und ich kann ihm auch eine blacklist der Modelle übergeben (wenn ich e.g. keine Basis-Modelle möchte) etc.

  • creates metamodell and itself
  • on request library object
  • on request enum object
  • convenience functions

ModelProphet:

Eigentlich eine Util-Klasse:
BakerPyIndex + Model-Blacklist wird im init übergeben. Für Aussen ein Tool um alles abzufragen, was ich wissen möchte über das Modell. Heisst nicht mehr SettingsProphet weil es nicht nur Infos für die Settings enthält, sondern vieeel mehr...

  • filters for relevant stuff
  • replies questions (like has_basketoid_definition etc.)
  • not only settings specific

SettingsProphet(ModelProphet)

  • more convenience functions for the ModelProphet (specific to read ili2db settings in advance)

utils.py

Evtl. auch als Klasse bauen und logfunction übergeben etc. Random utils zum Sachen bauen. Nutzt manchmal auch ModelProphet oder Pythonizer oder ili2py evtl. auch direkt. Aktuell drin wäre eine Funktion um ein TOML-File zu bauen (siehe Use Case unten). in Zukunft aber auch evtl. um UMLs zu bauen oder sogar Layer in QGIS laden (oder auch Daten)...

Use Cases:

  • Ich möchte wissen (im Model Baker GUI) ob --createBasketColumn als Setting anbieten soll oder nicht? (wenn im Modell BASKET OID definiert ist es nämlich eh Pflicht): Baue BakerPyIndex und mache ModelProphet(baker_py_index, model_blacklist).has_basket_oid_definition()
  • Ich möchte mir ein Extra Meta Attribut File bauen, um ili2db zu übergeben mit den geometrie-mappings:
    Baue BakerPyIndex, hole mir die Infos aus dem Prophet: ModelProphet(baker_py_index, model_blacklist).multi_geometry_structures_on_23() und übergebe die den utils.temp_meta_attr_file()
  • (future) Ich möchte die Enumeration Werte eines spezifischen Attributes haben: Baue BakerPyIndex und mache ModelProphet(baker_py_index, model_blacklist).enumeration_values(attr_iliname)
  • (future) Ich möchte als Info ein UML des Modells anzeigen: utils.uml_as_svg(BakerPy... weiss noch nicht genau wie
  • (future) Ich möchte die Objekte in QGIS laden (qgis_loader-style): utils.load_xtf(xtf, BakerPyLibrary... weiss noch nicht genau wie)

Info

To run in Plugin this is needed opengisch/QgisModelBaker#1148

To dos

  • fix tests on ili2c part and rebase
  • finalize tests for pythonizer (ili2py part)
  • Setting Prophet: needs_basket_column (to hide setting or not)
  • Setting Prophet: has_arcs (to hide setting or not)
  • Setting Prophet: has_enumeration (to hide it or not)
  • Setting Prophet: has_extended_enumeration (to make it smart1 xor enumTabs avalable)
  • Setting Prophet: translation_info (is tranlated, what languages)
  • Setting Prophet: has_multiple_geometry_columns (to hide setting or not)
    Little bit more extended and stretch goal:
  • clean up BakerPyIndex
  • clean up Setting Prophet
  • dependency -> move to nativ ili2py depends_on
  • Make lots of comments to the BakerPyIndex

Not part of this integration

  • Setting Prophet: smart_suggestion
  • Setting Prophet: Enumeration suggestion
  • Setting Prophet: multi_geometry_structures_on_23 and Build my extra-meta-attr-file

Some restructuring on the ili2db functions but keeping backwards compatibility (except the iliExcecutable, but should not be a problem, because it's usually derived (by IliImporter/IliExporter etc.) for the library usage
@signedav

signedav commented Jul 6, 2026

Copy link
Copy Markdown
Member Author

See the test cases to continue and think about:

The goal of the SettingsProphet is to have a clean tooling box to get the info. But what if we need more (not settings specific) like enumeration values or visualize someting? There might be another Prophet-like-Class but do they have a common parent?

@signedav

signedav commented Jul 7, 2026

Copy link
Copy Markdown
Member Author

Additional info to control the Library (not part of this PR, but maybe we need to be prepared for this use case on thinking about the structure):

Receiving enumerations

from QgisModelBaker.libs.modelbaker.libs.ili2py.interfaces.interlis.interlis_24.ilismeta.ilismeta16_2022_10_10.enum_type_type import (
    EnumTypeType,
)
from QgisModelBaker.libs.modelbaker.libs.ili2py.writers.py.python_structure import (
    Enumeration,
)

[...]
# let's get the enumeration values of an attribute e.g. KbS_V1_5.Belastete_Standorte.Belasteter_Standort.Standorttyp
attribute_iliname = KbS_V1_5.Belastete_Standorte.Belasteter_Standort.Standorttyp

# let's say we have the Kbs_V1_5 db already and read the ili via utils of this PR here #171 
model_files = db_utils.model_files_generated_from_db(
    self.configuration, self.models
)
# and compile
_, imd_file, _ = Ili2DbUtils().compile(ili_file)
# and pythonize the BakerPyIndex
pythonizer = Pythonizer(imd_file=imd_file)
baker_py_index = pythonizer.baker_py_index()

# and this is the interesting stuff
imd_field_object = index.index.get(attribute_iliname)
imd_field_type_oid = imd_field_object.type_value.ref
imd_field_type_object = index.index.get(imd_field_type_oid)
if isinstance(imd_field_type_object, EnumTypeType):
    # now we know that it's an enum
    # and now we kind of create a library instance of Enumeration
   enum_object = Enumeration.from_imd(imd_field_type_object, index)
   self.log_function(
      f"Enum value: {enum_object.values}",
      LogLevel.INFO,
  )

And why Enumeration and not Library or BakerPyLibrary?

See #153

Loading objects

Info from the WS in Windisch: https://github.com/moflexch/awt5_windisch/tree/main/ws3_ili2py. How to load objects to QGIS

  1. In console:
    ./ili2py-linux python-classes -i models/SZ_Waldfeststellungen_V2/SZ_Waldfeststellungen_V2.imd -o ./ -l **interface**
    
  2. an interface module has been created containing the library of the model, now it can be accessed with:
    from interface.references import BinBlBoxType, Ref
    from interface.xtf_opening import Transfer
    
    Means we can start t he xtf_qgis_loader.py (located in the same folder than interface) - see https://github.com/moflexch/awt5_windisch/blob/main/ws3_ili2py/xtf_qgis_loader.py
    And magic happens....

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds an ili2c-based compilation path and introduces an ili2py “pythonizer” bridge plus prophet utilities (Model/SettingsProphet) to query model characteristics for downstream settings decisions, along with new tests and test models.

Changes:

  • Add ili2c integration (IliCompiler, Ili2CCommandConfiguration) and expose a Ili2DbUtils.compile() helper that compiles .ili to .imd.
  • Add ili2py bridge utilities (BakerPyIndex) and prophet classes (ModelProphet / SettingsProphet) with comprehensive QGIS-based tests.
  • Extend packaging to vendor ili2py (git clone) and additional Python deps (xsdata, typing-extensions), plus expand test model fixtures.

Reviewed changes

Copilot reviewed 26 out of 27 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
tests/utils.py Adds an ili2c test configuration helper.
tests/test_compile.py New test validating ili2c compilation output (IMD contents).
tests/test_pythonizer.py New tests for BakerPyIndex index/library/enumeration helpers.
tests/test_model_prophet.py New tests for SettingsProphet model capability queries.
tests/testdata/ilimodels/ArcInfrastruktur_V1.ili New fixture model used in prophet tests.
tests/testdata/ilimodels/KT_ArcInfrastruktur_V1.ili New fixture model extending topics (arcs/multi-geom scenarios).
tests/testdata/ilimodels/PianiDiUtilizzazione_V1_2.ili New translation fixture model for language/translation detection.
scripts/package_pip_packages.sh Vendors new Python deps and pulls ili2py from GitHub at a pinned commit.
modelbaker/utils/ili2db_utils.py Adds compile() helper using ili2c (IliCompiler).
modelbaker/utils/db_utils.py Adds helper to generate temporary .ili files from DB-stored model content.
modelbaker/utils/globals.py Extends model blacklist with INTERLIS.
modelbaker/iliwrapper/iliexecutable.py Refactors executable base to support both ili2db and ili2c entrypoints.
modelbaker/iliwrapper/ilicompiler.py New IliCompiler wrapper using ili2c executable.
modelbaker/iliwrapper/ili2dbconfig.py Adds Ili2CCommandConfiguration for ili2c args.
modelbaker/iliwrapper/ili2dbutils.py Adds ili2c jar discovery/download + shared download helper.
modelbaker/iliwrapper/ili2dbtools.py Adds ili2c download URL/version helpers.
modelbaker/iliwrapper/ilicache.py Stores model “File” metadata and exposes it via item roles.
modelbaker/iliwrapper/iliimporter.py Switches to Ili2DbExecutable base.
modelbaker/iliwrapper/iliexporter.py Switches to Ili2DbExecutable base.
modelbaker/iliwrapper/ilideleter.py Switches to Ili2DbExecutable base.
modelbaker/iliwrapper/iliupdater.py Switches to Ili2DbExecutable base.
modelbaker/iliwrapper/ilivalidator.py Switches to Ili2DbExecutable base.
modelbaker/iliwrapper/ilimetaconfigexporter.py Switches to Ili2DbExecutable base.
modelbaker/ili2pytools/pythonizer.py New BakerPyIndex (ili2py Index bridge) + convenience queries.
modelbaker/ili2pytools/model_prophet.py New prophet utilities to derive model-based settings decisions.
modelbaker/ili2pytools/utils.py New helper for generating meta-attrs temp files (currently buggy).
modelbaker/ili2pytools/init.py Introduces ili2pytools package.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread modelbaker/iliwrapper/iliexecutable.py
Comment thread modelbaker/utils/ili2db_utils.py Outdated
Comment thread modelbaker/utils/db_utils.py Outdated
Comment thread modelbaker/ili2pytools/utils.py
Comment thread modelbaker/ili2pytools/pythonizer.py
Comment thread modelbaker/ili2pytools/model_prophet.py
Comment thread scripts/package_pip_packages.sh Outdated
Comment thread modelbaker/iliwrapper/ili2dbutils.py
Comment thread tests/test_compile.py
Comment thread tests/test_compile.py
@signedav signedav force-pushed the ili2pyintegration branch from 9715aa9 to ba5343f Compare July 10, 2026 15:26
@signedav signedav force-pushed the ili2pyintegration branch from ba5343f to 76036e2 Compare July 10, 2026 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants