Native Validation
The migrator library bundled with PyPtP contains the file loaders of Gaia (GNF) and Vision (VNF). PyPtP uses them to convert between file versions and to check whether the application would accept a network. Every error or warning the loader raises is reported with the loader's own message.
Full Example
View the complete code: 15_native_validation.py
The native_loader Validator
The native_loader validator saves the network to a temporary file and loads it with the Gaia or Vision loader. Every error or warning becomes an issue.
from pyptp.validator import CheckRunner, ValidatorCategory
report = CheckRunner(network).run() # includes native_loader
for issue in report.issues:
if issue.validator == "native_loader":
print(issue.object_type, issue.object_id, issue.message)Loader messages are reported as the application produces them (in Dutch). When a message names an object, object_type and object_id identify it, for example Meetveld and its GUID for a measure field without an in-object. File-level messages use object type Network.
| Issue field | Value |
|---|---|
code | native_load_error or native_load_warning |
severity | ERROR for loader errors, WARNING for loader warnings |
object_type / object_id | Object named in the message, or Network / None |
details["native_code"] | Native return code (see below) |
The validator needs the bundled library for your platform (Windows or Linux) and writes a temporary file. To run only the Python validators, pass ValidatorCategory.CORE:
report = CheckRunner(network).run(categories=ValidatorCategory.CORE)Checking a File Directly
To check an existing .gnf or .vnf file without building a network, call the loader directly:
from pyptp.convert.version_migrator import validate_file
result = validate_file("network.vnf")
if not result.ok:
print(result.describe())result.errors and result.warnings hold the loader messages. result.code is one of:
| Code | Constant | Meaning |
|---|---|---|
0 | ERR_SUCCESS | The file loads cleanly |
1 | ERR_LOAD_FAILURE | The file itself cannot be read (missing, locked, unknown version) |
4 | ERR_NETWORK_INVALID | The file was read but the loader rejected part of its content |
Save and Load Run the Loader Too
save() and from_file() run the same loader on every version. Saving to an older version converts the file with it, and saving or loading at the current version (V9.12, G8.12) checks the file with it. When the loader rejects the network they raise RuntimeError with the loader messages included, and no output file is written:
Failed to save as V9.12: The network file contains errors.
error: Meetveld {2A421727-0EA3-4544-9C58-ADB67DCEE36A} in : in-object niet toegekend;The check costs one extra native load per call. native_check=False skips it:
network.save("draft.vnf", native_check=False)
network = NetworkMV.from_file("draft.vnf", native_check=False)Migration to or from an older version always runs the loader.
Next Steps
- Validation for the Python validators and report handling
- Loading Networks for version migration on load