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

Singledispatch entrypoints #38

Merged
merged 3 commits into from
Oct 8, 2024

Conversation

deltamarnix
Copy link
Contributor

I was playing with how we could set up functions in a modular fashion without having to add a function in the corresponding class. cattrs mentions the use of single dispatch functions for their structure and unstructure functions. We can do the same for functions like plot(), where the plot function should be seen as a module, and not as part of the class itself.

I have combined this functionality with the entry_points function to show that a user or plugin package could in theory also add functionality. For example, a user comes with a specific entry point for plotting a specific package, other than the default way that we normally do.

@deltamarnix deltamarnix requested a review from wpbonelli October 7, 2024 06:58
@deltamarnix
Copy link
Contributor Author

Python 3.9 seems to fail, because the arguments for entry_points are wrong.

I wonder if we should still support this version of python: https://scientific-python.org/specs/spec-0000/

@wpbonelli
Copy link
Member

I wonder if we should still support this version of python: https://scientific-python.org/specs/spec-0000/

I figured we'd want to support 3.9 until EOL in Oct next year (https://devguide.python.org/versions/) but as a matter of personal preference I'd much rather take your source's advice and drop it earlier, if only so we can use 3.10 features like pattern matching

@deltamarnix
Copy link
Contributor Author

I figured we'd want to support 3.9 until EOL in Oct next year (https://devguide.python.org/versions/) but as a matter of personal preference I'd much rather take your source's advice and drop it earlier, if only so we can use 3.10 features like pattern matching

If we keep 3.9 supported, we might come in conflict with the latest versions of numpy and xarray. And then we are lacking behind. I think that's why these packages support only a small subset of python versions.

Copy link
Member

@wpbonelli wpbonelli left a comment

Choose a reason for hiding this comment

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

I like it. Extensibility by design — reminds me of pytest, where most basic functionality is implemented in the same way external plugins are

@wpbonelli
Copy link
Member

If we keep 3.9 supported, we might come in conflict with the latest versions of numpy and xarray. And then we are lacking behind. I think that's why these packages support only a small subset of python versions.

True. I didn't realize numpy had already dropped 3.9. I say we just follow them?

@deltamarnix deltamarnix force-pushed the singledispatch-entrypoints branch from d74a6b8 to 12248cb Compare October 8, 2024 15:48
@wpbonelli
Copy link
Member

Somewhat similar discussion: modflowpy/flopy#1470

I don't know if @jlarsen-usgs still has plans for a flopy/modflowapi plugin architecture, more recently he has indicated modflowapi will stay separate from flopy.

But the entrypoints plugin approach seems applicable to the core flopy framework too, if we want the same "engine" to drive not only mf6 but other programs. This would of course expand the scope of this work — maybe wisest to design/build for mf6 initially, then consider extending it to other programs later.

@wpbonelli wpbonelli merged commit 4fb893c into modflowpy:develop Oct 8, 2024
11 checks passed
@deltamarnix deltamarnix deleted the singledispatch-entrypoints branch November 15, 2024 10:41
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