Skip to content

feat: optional progress callback for parse and unparse#220

Merged
stanislaw merged 1 commit into
strictdoc-project:mainfrom
fNBU:feat/progress-callback
Jun 12, 2026
Merged

feat: optional progress callback for parse and unparse#220
stanislaw merged 1 commit into
strictdoc-project:mainfrom
fNBU:feat/progress-callback

Conversation

@fNBU

@fNBU fNBU commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

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_string and ReqIFUnparser.unparse accept an optional callback progress(section: str, items_done: int, items_total: int), invoked once per direct child of each REQ-IF-CONTENT container, with the container tag as the section name. ReqIFZParser.parse and
ReqIFZUnparser.unparse accept 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.

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.
@fNBU

fNBU commented Jun 11, 2026

Copy link
Copy Markdown
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.

@stanislaw stanislaw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Very good! Thank you.

@stanislaw stanislaw merged commit 48745b3 into strictdoc-project:main Jun 12, 2026
9 checks passed
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.

3 participants