Skip to content

Conversation

@brisvag
Copy link
Contributor

@brisvag brisvag commented Dec 1, 2025

Very much work in progress... This is harder than I expected, and I expected hard xD

Suggestions are welcome, if you think I'm doing this completely wrong.

Currently there are issues with schemas failing in all sorts of funny ways...

@DragaDoncila DragaDoncila added this to the 0.7.0 milestone Dec 11, 2025
@codecov
Copy link

codecov bot commented Dec 11, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (0a2beb8) to head (fca15be).

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #419   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           37        37           
  Lines         2763      2776   +13     
=========================================
+ Hits          2763      2776   +13     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor Author

@brisvag brisvag left a comment

Choose a reason for hiding this comment

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

Some comments on the latest changes. Other than that, thanks for finishing this up! I also got really stuck with the jinja stuff...

cmd = contributions.CommandContribution(**cmd_kwargs)
if cmd.id.startswith(self.plugin_name):
n = len(self.plugin_name)
n = len(self.plugin_name) + 1
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why is this needed?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Because if plugin name is my-plugin and the contribution is my-plugin.contribution_name then
contribution[len(self.plugin_name)] gives .contribution_name that is invalid identifier, and crashes on assign validation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I mean, why is this changed from before?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I do not understand. It looks like assignment validation was not triggered.

"""

id: str = Field(
id: Annotated[str, AfterValidator(_validators.command_id)] = Field(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we then ideally migrate all our field validators to use the type annotation instead?

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is suggested for reusable validators. We might want to make more validators reusable.

Comment on lines 482 to 485
if isinstance(value, list) and isinstance(
_get_inner_type(annotation), ModelMetaclass
get_inner_type(annotation), object
):
return [check_pynames(i, (*loc, n)) for n, i in enumerate(value)]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This feels wrong. Isn't the second clause always true by definition?

Instead, we should probably check that the outer type is list, and maybe that the inner type is BaseModel or somethign like that.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It is an object for the current main. Just renamed. But investigation migh be a good idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I pushed a change that should do this a bit better!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok now I actually pushed it. There was a bug in iter_inner_types, also fixed that.

autogenerate: true
menus:
napari/layers/visualize:
/napari/layer_context:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reasons why I had changed this to 'napari/layers/visualize' are 2:

  1. layer_context is not actually contributable (nor planned to be), this was a mistake in the first place
  2. this should not start with a backslash

Copy link
Collaborator

Choose a reason for hiding this comment

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

This change makes problems in multiple tests. Could we fix this naming in folloup PR?

Comment on lines 154 to 155
assert set(menus) == {"/napari/layer_context", "mysubmenu"}
items = list(plugin_manager.iter_menu("/napari/layer_context"))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep, this leading backslash is wrong.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Follow-up PR?

@brisvag brisvag marked this pull request as ready for review December 12, 2025 08:44
@brisvag
Copy link
Contributor Author

brisvag commented Dec 12, 2025

I added 3.14... windows not happy.

@Czaki
Copy link
Collaborator

Czaki commented Dec 12, 2025

I added 3.14... windows not happy.

fixed

@brisvag
Copy link
Contributor Author

brisvag commented Dec 18, 2025

Btw I tested this in napari, and all seems to be working fine even in combination with the v1 sstuff we use there for now.

derekthirstrup added a commit to derekthirstrup/napari that referenced this pull request Dec 30, 2025
Update npe2 dependency from napari/npe2@py314 (doesn't exist) to
brisvag/npe2@py314 which contains the Python 3.14 and Pydantic V2
compatibility changes from PR napari/npe2#419.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
derekthirstrup added a commit to derekthirstrup/napari that referenced this pull request Dec 31, 2025
Skip npe2 docs prep which fails due to Pydantic V2 schema incompatibility.
The npe2 _docs/render.py uses .schema() and expects 'definitions' key,
but Pydantic V2 returns '$defs'. Use slimfast target which uses prep-stubs
instead of prep-docs to avoid cloning and running npe2's render.py.

See: napari/npe2#419

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
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.

3 participants