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

Use a common configuration model #374

Merged
merged 7 commits into from
Aug 20, 2024
Merged

Use a common configuration model #374

merged 7 commits into from
Aug 20, 2024

Conversation

nbraud
Copy link
Collaborator

@nbraud nbraud commented Aug 10, 2024

Model the configuration with Pydantic, and convert the rest of Bork to use that rather than load_pyproject and raw dicts.

This shouldn't change the actual configuration schema, merely document and validate it.

Rationale

  • Document the data model
  • Centralize the definition of config entries' types and default values
    Previously, each use of a config entry had its own idea about that
  • Reliably validate the configuration
  • Provide an abstraction terser and more ergonomic than raw dicts
    +37 -60 lines, excluding the model's implementation and removal of load_pyproject

Drawbacks

Pydantic is a new dependency, with pydantic_core weighing ~2 MiB.
I don't think it matters all that much: Bork is a development tool, and its latest release was already 5 MiB.

@nbraud nbraud force-pushed the remolisher/config branch from 053f44d to b74a405 Compare August 10, 2024 11:11
@nbraud
Copy link
Collaborator Author

nbraud commented Aug 10, 2024

Ah, typing.Self was added in Py3.11

@nbraud
Copy link
Collaborator Author

nbraud commented Aug 10, 2024

Would it not be amasing if tests showed the entire error output?

@nbraud nbraud force-pushed the remolisher/config branch 2 times, most recently from c385c6f to a78e908 Compare August 10, 2024 12:29
@nbraud nbraud marked this pull request as draft August 10, 2024 12:32
@nbraud nbraud force-pushed the remolisher/config branch from 892bade to ad62d1b Compare August 10, 2024 21:34
@nbraud
Copy link
Collaborator Author

nbraud commented Aug 10, 2024

Ah fuck, the zipapp bootstrapping fails because pydantic-core is actually written in Rust. I forgot about that >_>'

@nbraud
Copy link
Collaborator Author

nbraud commented Aug 11, 2024

@duckinator I could turn all the models into dataclasses, and write our own more-basic input validation layer... but I'm honestly unsure whether we should prioritize Bork itself being available as a zipapp, or maintainability.

@nbraud nbraud force-pushed the remolisher/config branch 4 times, most recently from 1187dfd to 3d63953 Compare August 11, 2024 21:34
@nbraud nbraud force-pushed the remolisher/config branch from 3d63953 to dd796f6 Compare August 11, 2024 21:46
@nbraud nbraud marked this pull request as ready for review August 11, 2024 21:46
@nbraud
Copy link
Collaborator Author

nbraud commented Aug 11, 2024

@duckinator that's ready-to-review and CI is green 🎉

All in all I'm pretty happy, we are getting to a point where type-checking is able to find bugs (whereas before, too much of the codebase was untyped and mypy would just slap Any on most things)

@duckinator
Copy link
Owner

@nbraud sorry, I somehow got distracted from looking at this until today.

I like this overall, but I'd like some kind of test for building ZipApps (even if not of Bork).

@nbraud nbraud force-pushed the remolisher/config branch from 936a40a to 883869f Compare August 19, 2024 22:36
@nbraud
Copy link
Collaborator Author

nbraud commented Aug 19, 2024

I'd like some kind of test for building ZipApps (even if not of Bork)

Done!

@duckinator duckinator merged commit 9cb64f2 into main Aug 20, 2024
11 checks passed
@duckinator duckinator deleted the remolisher/config branch August 20, 2024 02:09
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.

2 participants