-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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 entry points to allow packages to register plugins/extensions in various parts of Astropy #6623
Comments
The main problem is documentation I guess. I don't mean documenting the entry points but updating the documentation of |
Well if the entry points were granular enough to be separate for reader/writer/identifier then you could generate the existing Table.read docstring without actually loading the entry points. Alternatively we could simply list the formats in the Table.read docstring without the details of reader/writer/identifier and we need to then provide a way to get format-specific detailed help anyway (which could trigger the entry point loading) - see #1011 |
The APE should also address conflicts where someone has installed different packages that uses the same entry point name but for different purposes (I'm also making this up but hey, could happen). |
If we're thinking of custom additions, there's also:
Those two at least register just by subclassing a base format. It would seem |
I am all for this! Not having to document to SunPy users that they have to do a |
This is starting to sound like a GSoC 2018 project... 😅 |
I'm a bit worried about inter-package compatibility. The entry points have to be installed but are checked at runtime. Likewise the current registering is also done at runtime. I'm a bit worried about how one would deprecate the current way in favor of the new way. I mean the deprecation would come at runtime while the entry-points need (?) to be defined at install-time. Probably something that needs to be addressed in the discussion/APE. |
Another question: Would that make It's optional currently because of the |
Yes
Correct - I think at this point it would be core enough to be required. Having said that it is probably the easiest required dependency to have, since if you have pip or conda then you are guaranteed to have setuptools.
There's no need to deprecate the current way - the entry points have to call setup functions in the separate packages but those setup functions still have to do something, so e.g. an entry point for a table reader format could still call the |
The more I think about this the more I realize it really should be an APE. I will try and come up with something soon. Anyone interested in helping once I have a draft? (@Cadair?) |
See also jupyter/notebook#2894 for some discussions we're having on entry_points, the slowness is something to consider, but also see the entrypoints package mentioned there. |
suuuurrrreee 😉 |
@takluyver 's entrypoints package would avoid that, I think it's a bit awkward to have setuptools as a dependency, it would be nice actually if entrypoints would be a setuptools dependency. |
There are two parts to setuptools - setuptools itself, which contains code for making and publishing packages, and I've initiated a discussion on distutils-sig about standardising the entry points format, so that we're on solid ground for code other than setuptools to access them. After some early disagreement, I think this is now moving forwards. Once that's done, I hope to experiment with caching entry points so finding them can be quicker. It will probably be some time before that's ready for general use, though. |
In the context of #6623 (comment) above, an issue has come up that should probably be addressed in any APE on this (@Cadair?): an entry_point plugin has to be installed to be tested (we think). That breaks the usual understanding that you can run tests without installing (i.e. |
More generally, the APE/this scheme needs to justify the added complexity/confusion of using entry points over explicit plugin approaches. While it might seem more compact to use entry points, remember both |
@eteq - could you clarify what you mean by 'explicit plugin approaches'? |
Isn't this what ASDF schema is using? Is this resolved? |
ASDF is indeed using entry points. but I think this issue touches on the broader question of whether we want to expand the use of entry points to other parts of the package, so I'd suggest keeping this open. |
Yes, some form of supporting entry points still seems very worthwhile - the example of having to load |
Beware that entrypoints are not cached, so loading them generally requires enumerating all installed Python packages, which can be very expensive. I suggest avoiding doing anything at runtime that requires |
Some work has been done on the entry point parsing, see pypa/setuptools#510 (comment). |
I've used the entry-points package for my affiliated package |
As nicely described by @saimn in #6623, with I think this extensibility is worth pursuing, in light of "consolidation" being a possible theme for Astropy 4.3. |
|
Re: |
I think that means that some new features may be available only in the |
There are currently several places where we allow or should allow packages to register extensions to Astropy. For example:
The current workflow is for a package to append something to a list or call a register function. However, this is not ideal because it means the user has to know to explicitly import the package first. For example, let's say sunpy defined a
.solar
file format (I'm making this up, but hey).If I just did:
this wouldn't work. I'd need to do:
The standard way around this kind of issue is to consider using entry points to set up a plugin system. With entry points, sunpy could then say it has plugins for file formats and provide the entry point to set up those file formats. This then allows astropy to discover plugins without the user having to import other packages explicitly (installing is enough).
To avoid a proliferation of ways of doing this, we should probably decide if we want to do this and then come up with standard entry point categories, e.g.
[astropy.table.serialization]
,[astropy.table.formats]
,[astropy.coordinates.frames]
and so on.Note that if we had one entry point per Table format, we could also use entry points in the core package itself to register reader/writers instead of doing this ugly hack:
astropy/astropy/table/__init__.py
Line 54 in 58fdc01
As a bonus, for Table formats, this could mean loading entry points only when the format is requested, which could improve import-time performance.
I'm opening this here to get some initial feedback - not sure if this should become an APE, or if this + astropy-dev discussion would be enough. Maybe we can see how controversial this idea is 😆
The text was updated successfully, but these errors were encountered: