Skip to content

Proposal: Alternative plugin sorting#243

Merged
abravalheri merged 6 commits into
mainfrom
alt-sorting
Mar 21, 2025
Merged

Proposal: Alternative plugin sorting#243
abravalheri merged 6 commits into
mainfrom
alt-sorting

Conversation

@abravalheri

@abravalheri abravalheri commented Mar 14, 2025

Copy link
Copy Markdown
Owner

Alternative to #242.

I am assuming the following:

  • Plugins can be listed in any order, we just need this order to be consistent/reproducible.
    • All schemas/tools that are returned by list_from_entry_points end up loaded in the registry, independently of the order in the list.
    • There is no duplicates defining the same schemas/tools, because we remove them.
  • We do need to stablish some sort of priority/precedence that tells us which plugin "wins" if multiple plugins specifies the same schema/tool.
    • Again the specific choice of how the priorities are assigned is not important, what is important is the consistence/reproducibility.

Therefore, I think the following would be fine:

  • tool plugins are listed first than other schemas,
  • multi plugins always have higher priority, so they can overwrite tool schemas previously loaded.
  • the closer to "zzzzzzz..." is an entry-point name, the higher is the priority (inside the same entry-point group).

In practice this equates the sorted index to the priority in overwriting -- i.e. the higher indexes in the list overwrite the lower ones -- which matches very well dict-comprehensions.

With this in mind, this PR proposes one core change:

  • d5ca823: Simplify the ordering in list_from_entry_points (avoids calling sorted multiple times, avoids [::-1], avoids reversing).

... plus an auxiliary change that adds a helper to the tests:

  • 4388d04: it took me some while to get my head around the order of the entrypoints in the tests, so I wanted to have visibility of them directly on the test function body to facilitate reasoning

Closes #242

@abravalheri abravalheri marked this pull request as ready for review March 14, 2025 03:36
@abravalheri abravalheri requested a review from henryiii March 14, 2025 03:36
Comment thread tests/test_plugins.py Outdated
@henryiii

Copy link
Copy Markdown
Collaborator

I'm thinking about the priority. It would be nice to have individual packages that provide their own schemas to override "stores" that provide lots of schemas. For example, you might want to install schema-store + a specific version of cibuildwheel and get that version of cibuildwheel's schema, not the store version. The main reason for multi schemas to prioritize is they support extra schemas, but the downside is that all current packages that provide one schema are probably would like to override "stores". The other reason for multi schemas to win is because I want validate-pyproject-schema-store to be able to support older versions of validate-pyproject for a while while it also provides the extra schema. However, I could remove single schemas for the ones that have extra schemas (just PDM at the moment), so old versions of validate-pyproject would not be able to check PDM, but newer versions would get the full schema and you'd still be able to override these... someday, whenever validate-pyproject-schema-store dropped the single entry points and just pretends that validate-pyproject < 0.24 doesn't exist. (I can't lower cap it because pre-commit always claims validate-project is 0.1).

Of course, we could just ask tools like cibuildwheel to provide multi plugins too. Then the sorting here matters, but I could just name the schema-store plugin something that is unlikely to win (aaa-schema-store for example :) ).

I'm fine with either one, I do feel long term single beating multi might be nicer, while short term multi beating single is better. 99% percent of users will likely be just fine with the schema store and I might be overthinking this.

@abravalheri

Copy link
Copy Markdown
Owner Author

Thank you very much @henryiii.

It would be nice to have individual packages that provide their own schemas to override "stores" that provide lots of schemas
...
long term single beating multi might be nicer, while short term multi beating single is better.

Alternatively we can also consider the following arrangement:

  • "tool" have priority over "multi" (e.g. "tool" priority 1 and "multi" priority 0).
  • "multi" plugins can include an optional extra field in the dict, "priority" that overwrites the default value.

That would implement the long-term behaviour you described while allowing the tools themselves to bump their priority when they find relevant.

@henryiii

Copy link
Copy Markdown
Collaborator

That would be fine, too.

@abravalheri

Copy link
Copy Markdown
Owner Author

I have implemented the approach described in #243 (comment).

@henryiii, please let me know if you have any thoughts.

@henryiii

Copy link
Copy Markdown
Collaborator

That should work - I can set the priority lower than default for validate-pyproject-schema-store so that more specific plugins override.

@abravalheri abravalheri merged commit 40ec0e5 into main Mar 21, 2025
@abravalheri abravalheri deleted the alt-sorting branch March 21, 2025 20:26
@henryiii

henryiii commented Mar 21, 2025

Copy link
Copy Markdown
Collaborator

Thanks! Trying this out in validate-pyproject-schema-store in henryiii/validate-pyproject-schema-store#117.

henryiii added a commit to henryiii/validate-pyproject-schema-store that referenced this pull request Mar 21, 2025
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
henryiii added a commit to henryiii/validate-pyproject-schema-store that referenced this pull request Mar 21, 2025
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
henryiii added a commit to henryiii/validate-pyproject-schema-store that referenced this pull request Mar 21, 2025
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
@henryiii

Copy link
Copy Markdown
Collaborator

Looks like it's working! :) This will also nicely stay out of the way regardless of which one users use, since I set the priorities to -1 and -2.

henryiii added a commit to henryiii/validate-pyproject-schema-store that referenced this pull request Mar 21, 2025
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
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