-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add build-sequence-summary.json #526
Add build-sequence-summary.json #526
Conversation
Machine readable version of the current markdown table Useful in pipeline environments to filter skipped or prebuilt packages from a subsequent twine publish Signed-off-by: Pris Nasrat <[email protected]>
@staticmethod | ||
def dict_factory(x): | ||
return { | ||
k: str(v) if isinstance(v, pathlib.Path | Version) else v for (k, v) in x |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would have expected the 2nd argument to be a tuple, but TIL about union type. Does that come from type hints?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was my first approach - then my editor/pyright complained with the recommendation to use union type not tuple here. Looks like came in via https://peps.python.org/pep-0604/#isinstance-and-issubclass
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, thanks for sharing that link! I'm still learning about some of the recent changes to the language after spending a few years away from Python, so every little bit helps. :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The feature was introduced in Python 3.10 as part of PEP 604, https://docs.python.org/3.10/whatsnew/3.10.html#pep-604-new-type-union-operator
with open(ctx.work_dir / "build-sequence-summary.json", "w", encoding="utf-8") as f: | ||
json.dump( | ||
[ | ||
dataclasses.asdict(e, dict_factory=BuildSequenceEntry.dict_factory) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this could just be dataclasses.asdict(e)
. Did you find you needed to pass the factory function explicitly or does that do something extra?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So both Version and pathlib.Path failed to serialize with errors like
ERROR: Object of type PosixPath is not JSON serializable
Using the custom dict_factory (set on the dataclass) here to use str for those worked. I debated switching to pydantic here, used else but this seemed sufficient given it's a report.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What you have looks good. Pydantic wouldn't be wrong, but is probably an extra complication here.
I've triggered a new release including this feature. Thank you for contributing! https://github.com/python-wheel-build/fromager/releases/tag/0.36.0 |
Machine readable version of the current markdown table
Useful in pipeline environments to filter skipped or prebuilt packages from a subsequent twine publish
Signed-off-by: Pris Nasrat [email protected]