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

Entry points: add the core. prefix to all entry points #5073

Merged
merged 2 commits into from
Aug 31, 2021

Conversation

sphuber
Copy link
Contributor

@sphuber sphuber commented Aug 12, 2021

Fixes #4914

This PR updates all* entry points that ship with aiida-core and prepends the core. entry point namespace, as to conform with our own convention. The benefit is not just to be consistent but it will also make it easy to determine exactly where all entry points come from, which may not always have been trivial without the prefix.

The PR includes full database migrations and archive migrations to update all the relevant versions of the entry point names as they are stored on Computer and Node instances. This makes sure that existing data is fully backwards compatible. As for backwards compatibility of code: all factories include a check for the old entry points and will emit a deprecation warning and will then load the corresponding entry point from the new entry point string. This means that code using the factories is fully backwards compatible. There are a few places in the CLI that are not backwards compatible unfortunately. For example when using -S slurm when setting up a computer, one now has to update this to use the new entry point, i.e., -S core.slurm. The same goes for REST API queries where query parameters that used transport_type=local now should use transport_type=core.local. Ultimately, I think this is worth it in the long run.

@giovannipizzi
Copy link
Member

Thanks @sphuber!
I let the others do a review, just a couple of quick comments, if not done already

@sphuber
Copy link
Contributor Author

sphuber commented Aug 13, 2021

* We should add a note to https://github.com/aiidateam/aiida-core/wiki/AiiDA-2.0-plugin-migration-guide (this should, I believe, eventually become a guide not only for developers but also for users moving to 2.0?)

Indeed, this is up to date so far with the state of develop. If this gets merged I will make sure to add an entry in the wiki.

@ltalirz
Copy link
Member

ltalirz commented Aug 13, 2021

Thanks @sphuber !

I have two main questions:

  1. Do we need to deprecate the old strings at all?
    My gut feeling tells me that most users would intuitively be against the new strings, simply because they are longer (but I'd be happy to be convinced otherwise).
    I guess we want the new strings for reasons of internal consistency (just to remind me, what is the main problem we're solving here?) but we might be able to do that without the user having to care about it (at least so far we haven't had an actual case of namespace overlap to my knowledge).
    Of course, having two sets of strings side-by-side is more complicated than just having one, so there is a downside.

  2. Is now the right time for deprecating the strings?
    I guess we all agree that we won't remove support with v2.0. However, as a diligent plugin developer you don't want your plugin to raise deprecation warnings, and so you would have to update all entry-point strings in your code now.
    If there is ever going to be a move of certain data types outside aiida-core (structuredata), perhaps that would be a better time to deprecate entry point strings without core. prefix as well so to only cause this disruption once.

@ramirezfranciscof
Copy link
Member

@ltalirz I agree with your 2nd point that it would be jarring for users to already start getting deprecation warnings with a brand new major release of the code, and it would be perhaps better if we wait a bit before deprecating and maybe join that with the deprecation of moving out data plugins.

@sphuber
Copy link
Contributor Author

sphuber commented Aug 13, 2021

Do we need to deprecate the old strings at all?
My gut feeling tells me that most users would intuitively be against the new strings, simply because they are longer (but I'd be happy to be convinced otherwise).

We kind of have to deprecate them because we cannot keep both at all levels. We can keep the old strings working in the factories (which is already implemented) but for some of the entry points (the calcjobs, workflows, parsers, schedulers and transports) the entry point name is stored on the relevant Node or Computer in the database. This is used to reload the corresponding class. The migration that I added takes care to migrate existing attributes. So even though some parts of the interface may support both temporarily, the data will have to adopt a single one anyway.

I guess we want the new strings for reasons of internal consistency (just to remind me, what is the main problem we're solving here?) but we might be able to do that without the user having to care about it (at least so far we haven't had an actual case of namespace overlap to my knowledge). Of course, having two sets of strings side-by-side is more complicated than just having one, so there is a downside.

I described the benefits in the OP of the PR. This is to be consistent, conformant with our own guidelines and it will make it more obvious where certain plugins come from. The ecosystem might be small enough now where that is not (yet) difficult to say, but in the future, things might not be so obvious. The explicitness of the core prefix is very valuable I think.

Is now the right time for deprecating the strings? I guess we all agree that we won't remove support with v2.0. However, as a diligent plugin developer you don't want your plugin to raise deprecation warnings, and so you would have to update all entry-point strings in your code now.

I don't agree. The whole point of deprecation warnings is to allow a grace period. The point is not to never have them show up. If that were the case, we wouldn't even need a deprecation period and just work with the developers to adapt their code straight away to the changes before they release the next version. The changes necessary would also be minimal. The entry points are not used that often, but where ever they are used, they can be updated with relatively simple search-and-replace.

If there is ever going to be a move of certain data types outside aiida-core (structuredata), perhaps that would be a better time to deprecate entry point strings without core. prefix as well so to only cause this disruption once.

The discussion of moving out the domain-specific data plugins has been brought up many times, even before 1.0 and we keep postponing it. At this point, we don't know when that is going to happen, so I'd prefer to do this now, so things are consistent and prepared.

@codecov
Copy link

codecov bot commented Aug 25, 2021

Codecov Report

Merging #5073 (7efd1a2) into develop (2a2bf21) will decrease coverage by 0.01%.
The diff coverage is 86.67%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #5073      +/-   ##
===========================================
- Coverage    80.63%   80.63%   -0.00%     
===========================================
  Files          534      537       +3     
  Lines        37067    37179     +112     
===========================================
+ Hits         29887    29975      +88     
- Misses        7180     7204      +24     
Flag Coverage Δ
django 75.30% <80.52%> (-0.02%) ⬇️
sqlalchemy 74.32% <81.03%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
aiida/backends/testbase.py 93.23% <ø> (ø)
aiida/cmdline/params/options/main.py 96.25% <ø> (ø)
aiida/manage/tests/pytest_fixtures.py 93.34% <ø> (ø)
aiida/orm/autogroup.py 89.11% <ø> (ø)
aiida/orm/computers.py 81.42% <0.00%> (ø)
aiida/plugins/entry_point.py 93.75% <ø> (ø)
...ools/importexport/archive/migrations/v12_to_v13.py 72.00% <72.00%> (ø)
aiida/cmdline/params/types/plugin.py 88.68% <83.34%> (-1.01%) ⬇️
aiida/plugins/factories.py 91.67% <86.37%> (-7.20%) ⬇️
...site/db/migrations/0049_entry_point_core_prefix.py 100.00% <100.00%> (ø)
... and 32 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2a2bf21...7efd1a2. Read the comment docs.

@sphuber
Copy link
Contributor Author

sphuber commented Aug 30, 2021

Here follows a summary of the discussion and discussion taken at the meeting of Aug 30 2021.

Main argument against this change:

  • It adds additional work for plugin developers because they will have to adapt their code to get rid of the deprecation warning.

The counter arguments to this point:

  • This change is being added to a major revision, so deprecation warnings can be expected
  • Plugins anyway have typically an upper limit on their aiida-core requirement to only support a single major version. When v2.0 is released, they will anyway have to make a new release in which case adding a small commit that quickly updates the entry point names with the correct prefix would be trivial.
  • Plugins that are not actively maintained anymore and are unlikely to make a new release to deal with the warnings, will anyway not work for the new major version since there are some actual (however few) breaking changes, given that it is a major release. This is therefore not a sufficient reason not to go ahead with this change.

It was decided that with these counter arguments, the main downside of this change of adding some work for plugin developers does not outweigh the long term benefit of having correct and explicit entry point names. Therefore we have decided to go ahead with this change.

@sphuber
Copy link
Contributor Author

sphuber commented Aug 30, 2021

@chrisjsewell if we can get an official approval that would be great

@sphuber sphuber force-pushed the fix/4914/core-entry-point-prefix branch 2 times, most recently from 7068f00 to 85275d3 Compare August 31, 2021 07:17
The AiiDA plugin system allows the functionality provided by `aiida-core`
to be extended through entry points. These are defined in specific entry
point groups with a specific name. For these names to be uniquely
resolvable, each name needs to be unique within an entry point group.
That is why the convention is that each plugin package prefixes their
entry points with the package name, effectively namespacing all entry
points. Not only does this prevent entry point name clashes between
different packages, it also makes it explicit what package any
particular entry point comes from.

Uptil now, however, `aiida-core` was not respecting its own community
guideline and failed to prefix its entry points with `core.`. Not only
does this make it less obvious that these entry points are defined by
`aiida-core`, which may become more problematic as the ecosystem keeps
growing, but it also effectively blocks certain namespaces for potential
external plugin packages. For example, the namespace `array` is
effectively hijacked in the `aiida.data` group, since our `ArrayData`
plugin and its subclasses use it. This would make it difficult for a
potential `aiida-array` package to choose the name for its entry points.

Therefore, we opt to update `aiida-core`'s entry point names and
properly prefix them with `core.`. The following entry point groups were
updated:

 * `aiida.calculations`
 * `aiida.cmdline.computer.configure`
 * `aiida.cmdline.data`
 * `aiida.data`
 * `aiida.parsers`
 * `aiida.schedulers`
 * `aiida.tools.data.orbitals
 * `aiida.tools.dbimporters`
 * `aiida.transports`
 * `aiida.workflows`

The missing entry point groups simply didn't have any entry points
registered by `aiida-core`. The exception is `aiida.node`, but this
entry point group is not actually extensible by plugin packages and is
merely there for internal use. As such, the entry points are also never
used by external packages. The classes are imported directly from the
`aiida.orm` package.
The `get_entry_point_from_string` method of the `PluginParamType`
parameter type, tries to determine the entry point group and name from
the value passed to the parameter and when matched, attempts to load the
corresponding entry point. It was doing so by directly calling the
`get_entry_point` method from the `aiida.plugins` module.

Since the plugins that ship with `aiida-core` were recently updated to
have them properly prefixed with `core.`, the old unprefixed entry point
names are now deprecated. When used through the factories, the legacy
entry point names are automatically detected and converted to the new
one, with a deprecation warning being printed. However, the command line
didn't have this functionality, since the `PluginParamType` was not
going through the factories.

Here, for the entry point groups that have a factory, the plugin param
type is updated to use the factories, hence also automatically profiting
from the deprecation pathway, allowing users to keep using the old entry
point names for a while.

The factories had to be modified slightly in order to make this work.
Since the `PluginParamType` has the argument `load` which determines
whether the matched entry point should be loaded or not, it should be
able to pass this through to the factories, since this was always
loading the entry point by default. For this reason, the factories now
also have the `load` keyword argument. When set to false, the entry
point itself is returned, instead of the resource that it points to. It
is set to `True` by default to maintain backwards compatibility.
@sphuber sphuber force-pushed the fix/4914/core-entry-point-prefix branch from 85275d3 to 7efd1a2 Compare August 31, 2021 07:37
@sphuber sphuber merged commit 9cc5624 into aiidateam:develop Aug 31, 2021
@sphuber sphuber deleted the fix/4914/core-entry-point-prefix branch August 31, 2021 08:08
@chrisjsewell
Copy link
Member

@chrisjsewell if we can get an official approval that would be great

well better late than never

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.

add 'core' prefix to entry points defined by aiida-core
5 participants