Skip to content

Conversation

Kludex
Copy link
Member

@Kludex Kludex commented Jul 24, 2023

Change Summary

Implement a plugin system using Python entry points.

Related issue number

Checklist

  • The pull request title is a good summary of the changes - it will be used in the changelog
  • Unit tests for the changes exist
  • Tests pass on CI
  • Documentation reflects the changes where applicable
  • My PR is ready to review, please add a comment including the phrase "please review" to assign reviewers

Missing

I'll add them if everything is fine with the current implementation.

  • Tests
  • Documentation
  • Other places where we can have PluggableSchemaValidator

Selected Reviewer: @samuelcolvin

@linear
Copy link

linear bot commented Jul 24, 2023

PYD-181 Pydantic observability plugin

The idea is to support plugins from Pydantic, in a way we could "intercept", or "have hooks" on validation. For that, we intend to leverage the Entry Points Specification from Python.

As a reference, the two most known entry points are for flake8 and pytest.

The plugin needs to be agnostic i.e. it should just wrap the code we call the SchemaValidator.validate_*, which should allow pydantic_sdk to intercept the validation, and retrieve the data it wants.

The implementation will be "hidden" in a fork.

Questions

  1. Do we want to raise if the extra key doesn't have a plugin?

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Jul 24, 2023

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: e073168
Status: ✅  Deploy successful!
Preview URL: https://720a4185.pydantic-docs2.pages.dev
Branch Preview URL: https://kludex-pyd-181.pydantic-docs2.pages.dev

View logs

@Kludex Kludex requested a review from adriangb July 24, 2023 10:35
@Kludex
Copy link
Member Author

Kludex commented Jul 24, 2023

please review

Copy link
Member

@samuelcolvin samuelcolvin left a comment

Choose a reason for hiding this comment

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

otherwise I think this looks like a great start.

Obviously needs tests and documentation.


def on_step(*args: Any, **kwargs: Any) -> None:
for plugin in plugins:
with contextlib.suppress(AttributeError, TypeError):
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure we should be suppressing these errors?

Copy link
Member Author

@Kludex Kludex Jul 24, 2023

Choose a reason for hiding this comment

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

Otherwise, I'll need more conditionals below to check if the steps are implemented, i.e. if on_event is not None and if step_func is not None. It's a bit more verbose.

What do you prefer?

@pydantic-hooky pydantic-hooky bot added awaiting author revision awaiting changes from the PR author and removed ready for review labels Jul 24, 2023
@pydantic-hooky pydantic-hooky bot assigned Kludex and unassigned davidhewitt Jul 24, 2023
@Kludex
Copy link
Member Author

Kludex commented Jul 24, 2023

@samuelcolvin Should I allow BaseModel.__init_subclass__ to receive keyword arguments on this PR?

@Kludex
Copy link
Member Author

Kludex commented Jul 25, 2023

@samuelcolvin Should I allow BaseModel.__init_subclass__ to receive keyword arguments on this PR?

I've talked to @davidhewitt. I'll accept other keyword arguments for __init_subclass__, and allow the plugin to customize itself depending on that.

@Kludex Kludex marked this pull request as draft July 25, 2023 09:43
@Kludex Kludex force-pushed the kludex/PYD-181 branch 2 times, most recently from 54a7612 to f7c32d1 Compare July 25, 2023 12:29
@Kludex Kludex marked this pull request as ready for review July 26, 2023 10:16
@Kludex
Copy link
Member Author

Kludex commented Jul 26, 2023

Only some tests missing here.

@Kludex
Copy link
Member Author

Kludex commented Jul 26, 2023

please review

@pydantic-hooky pydantic-hooky bot added ready for review and removed awaiting author revision awaiting changes from the PR author labels Jul 26, 2023
@pydantic-hooky pydantic-hooky bot assigned davidhewitt and unassigned Kludex Jul 26, 2023
@samuelcolvin samuelcolvin changed the title Support pydantic entry point Pydantic plugin - entry point support Jul 26, 2023
@lig lig assigned samuelcolvin and unassigned lig Sep 18, 2023
@lig lig added ready for review and removed awaiting author revision awaiting changes from the PR author labels Sep 18, 2023
@samuelcolvin samuelcolvin mentioned this pull request Sep 22, 2023
7 tasks
@pydantic-hooky pydantic-hooky bot added awaiting author revision awaiting changes from the PR author and removed ready for review labels Sep 22, 2023
@pydantic-hooky pydantic-hooky bot assigned Kludex and unassigned samuelcolvin Sep 22, 2023
@lig lig enabled auto-merge (squash) September 22, 2023 16:18
@lig lig merged commit f120e7c into main Sep 22, 2023
@lig lig deleted the kludex/PYD-181 branch September 22, 2023 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting author revision awaiting changes from the PR author relnotes-feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support plugins
5 participants