feat: optional progress callback for parse and unparse#220
Merged
Conversation
ReqIF files coming from real-world tools can contain hundreds of
thousands of spec objects, and parsing or unparsing them takes long
enough that embedding applications need progress feedback.
Following the convention of urllib.request.urlretrieve(reporthook=...),
ReqIFParser.parse/parse_from_string and ReqIFUnparser.unparse accept an
optional callback:
def progress(section: str, items_done: int, items_total: int) -> None
The callback is invoked once per direct child of each REQ-IF-CONTENT
container (DATATYPES, SPEC-TYPES, SPECIFICATIONS, SPEC-RELATIONS,
SPEC-OBJECTS, SPEC-RELATION-GROUPS), with the container tag as the
section name. ReqIFZParser.parse and ReqIFZUnparser.unparse accept the
same callback and report at the archive member level: one call per
member, with the member's filename as the section name. When no
callback is passed, behavior and cost are unchanged.
A README section documents the callback for library users.
Contributor
Author
|
Apologies, I should have let you know that another PR was coming. This one is similar to the logging, except the user constructs the callback rather than getting it from stdlib. |
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.
Parsing or unparsing a ReqIF file with hundreds of thousands of spec objects takes long enough that an application embedding reqif needs to show progress to its user.
Following the convention of
urllib.request.urlretrieve(reporthook=...),ReqIFParser.parse/parse_from_stringandReqIFUnparser.unparseaccept an optional callbackprogress(section: str, items_done: int, items_total: int), invoked once per direct child of eachREQ-IF-CONTENTcontainer, with the container tag as the section name.ReqIFZParser.parseandReqIFZUnparser.unparseaccept the same callback and report at the archive member level, with the member filename as the section name.When no callback is passed, behavior and cost are unchanged — the existing passthrough integration tests cover that path, and a new unit test asserts the output is byte-identical with
and without a callback. A README section under "Using ReqIF as a library" documents the mechanism.