Skip to content
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

Merged
merged 1 commit into from
Dec 12, 2024

Conversation

pnasrat
Copy link
Contributor

@pnasrat pnasrat commented Dec 12, 2024

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]

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]>
@mergify mergify bot added the ci label Dec 12, 2024
@pnasrat pnasrat changed the title Add build-sequence-suummary.json Add build-sequence-summary.json Dec 12, 2024
@staticmethod
def dict_factory(x):
return {
k: str(v) if isinstance(v, pathlib.Path | Version) else v for (k, v) in x
Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Member

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. :-)

Copy link
Collaborator

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)
Copy link
Member

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?

Copy link
Contributor Author

@pnasrat pnasrat Dec 12, 2024

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.

Copy link
Member

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.

@mergify mergify bot merged commit 34c79b3 into python-wheel-build:main Dec 12, 2024
74 checks passed
@dhellmann
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants