feat(xml): modularize xmlutils into typed telemffb.xml package#67
Open
walmis wants to merge 5 commits into
Open
feat(xml): modularize xmlutils into typed telemffb.xml package#67walmis wants to merge 5 commits into
walmis wants to merge 5 commits into
Conversation
Split monolithic xmlutils.py (2383 lines) into a modular package: - store.py: XML I/O, retry parsing, consolidation - read.py: Read-only queries and 6-layer config cascade resolution - write.py: Mutation operations (write, erase, clone, profile management) - merge.py: Pure functions for merging/filtering data dicts - types.py: TypedDict definitions for all config row shapes xmlutils.py is now a thin backward-compat shim delegating to the new package while preserving module-level globals (device, auto_user_root, etc.). Added comprehensive type hints and docstrings across all modules. All 229 tests pass (98 legacy + 94 new + 37 schema validation).
FileLock now accepts shared=True to acquire a shared lock on POSIX (fcntl.LOCK_SH), allowing multiple processes to read concurrently while writers block until all readers finish. Windows falls back to exclusive locks since named mutexes lack reader-writer semantics. - try_parse() acquires a shared lock per retry attempt - update_roots() delegates locking to try_parse() (no outer wrapper) - write_userconfig() / really_write_userconfig() remain exclusive
…-memory try_parse() now reads raw bytes under the shared lock (fast I/O) then releases it before calling ET.parse(). This lets writers proceed as soon as the file read completes rather than waiting for full DOM construction. A ParseError triggers a retry that re-acquires the lock and re-reads, guarding against edge cases where another writer modifies the file between our read and parse.
… typos in defaults.xml - Update schema test to allow classdefaults_any to reference classes from any sim - Fix 'JetrAircraft' -> 'JetAircraft' typo in classdefaults_BMS - Fix 'GilderAircraft' -> 'GliderAircraft' typo in classdefaults_MSFS
…fter DLL loading loop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Refactors the monolithic
xmlutils.py(2,383 lines) into a modular, typedtelemffb/xml/package with full backward compatibility.Changes
New:
telemffb/xml/packagestore.pyread.pywrite.pymerge.pytypes.py\_\_init\_\_.pyXmlConfigManagerclassConcurrency improvements (
namedmutex.py)FileLockclass: cross-platform file-level lockingfcntl.flock()with shared (LOCK_SH) and exclusive (LOCK_EX) modesos.replace()for crash safetyBug fixes
defaults.xml:JetrAircraft→JetAircraft,GilderAircraft→GliderAircraftclassdefaults_anyto reference classes from any simTests
tests/test_xmlutils.py— 98 tests for legacy module paritytests/test_defaults_xml_schema.py— 38 schema validation tests against shipped defaults.xmlMigration path
Existing code using
import telemffb.xmlutils as xucontinues to work unchanged. The new package can be adopted incrementally viaXmlConfigManager. Legacyxmlutils.pycan be removed once all call sites are migrated.