Decouple input parsing from XML generation - #151
Open
Igor Opaniuk (igoropaniuk) wants to merge 3 commits into
Open
Decouple input parsing from XML generation#151Igor Opaniuk (igoropaniuk) wants to merge 3 commits into
Igor Opaniuk (igoropaniuk) wants to merge 3 commits into
Conversation
The module ran argv parsing and XML emission as top-level statements at import time, so it could not be imported by pytest or any library caller. This blocks the follow-up work: unit-testing the parser and splitting it into a loaders package. Wrap the flow in main(argv=None) -> int gated by __name__ == "__main__", move the module-level accumulators into locals, and return status codes instead of sys.exit(). The runpy dispatcher in cli.py is unaffected because it sets __name__ to "__main__". Signed-off-by: Igor Opaniuk <igor.opaniuk@oss.qualcomm.com>
The .conf format was hard-coded into gen_partition.py, with no boundary between where data comes from and how partition XML is emitted. Adding another format (YAML) would mean duplicating main() or scattering format branches through every helper. Add qcom_ptool/spec.py for the canonical internal shape (DiskParams, PartitionEntry, PartitionsByLun, LoadedSpec) and qcom_ptool/loaders/ with a load(path, image_map) dispatcher keyed on file extension: a new format becomes a new module plus a suffix registration. Move the conf parser into loaders/conf.py and apply the image-map override in one post-load pass, removing the last shared-global coupling. Signed-off-by: Igor Opaniuk <igor.opaniuk@oss.qualcomm.com>
make integration only checks that referenced files exist; it does not cover size parsing, attribute-bit decoding, LUN grouping or the image-map override -- the contract any future loader must reproduce. Add tests/unit/ pinning those cases against conf.load() and the loaders dispatcher. Wire it in with a make unit-test target, add it to make check, install python3-pytest in CI, and keep pytest config in pyproject.toml so pytest runs from the repo root. Signed-off-by: Igor Opaniuk <igor.opaniuk@oss.qualcomm.com>
Igor Opaniuk (igoropaniuk)
requested review from
Dmitry Baryshkov (lumag),
Nicolas Dechesne (ndechesne) and
Viswanath Kraleti (vkraleti)
as code owners
July 28, 2026 17:48
Viswanath Kraleti (vkraleti)
approved these changes
Aug 1, 2026
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.
This is the first, purely mechanical step of the partition-source rework discussed in [1]: it separates reading a partition spec from emitting XML, without changing a single generated byte.
Today
gen_partition.pyis a script rather than a library: parsing, validation, and XML emission run as top-level statements at import time, and every detail of the.confline format is hard-wired into the emission flow. That has three practical costs:The script tail moves into a
main(), the .conf parser moves into aloaders/package, and a small internal representation (LoadedSpec) becomes the contract between any loader and the emitter. A newpytestsuite pins the parser's exact behavior -size-string parsing, attribute-bit decoding, LUN grouping, the -m image-map override - so that contract is now enforced by tests rather than by habit. Adding a source format becomes "drop a module into loaders/ and register its suffix"; nothing else changes.Follow-up PRs (from [2]) will build on this: the YAML loader with schema validation, the multi-storage board model with composition, and the first board migration (Glymur-CRD) - split out per reviewer request so each part can be reviewed on its own terms.
[1] #124
[2] #134