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

get_entry_point: add proper deprecation pathway for old entry points #5206

Conversation

sphuber
Copy link
Contributor

@sphuber sphuber commented Oct 28, 2021

Fixes #5202

All entry points that ship with aiida-core were deprecated for v2.0
as they were changed to be properly prefixed with core.. To make sure
the old entry points would still be automatically loaded, the factories
were updated to automatically catch them, print a deprecation warning,
and load the new entry point instead.

However, the factory was not the correct place to put this logic, since
the get_entry_point method, which the factories call and is the lowest
function in the stack that actually retrieves the entry point, can also
be called directly, circumventing the deprecation mechanic added to the
factories. This would result in the deprecated entry points raising an
exception when being loaded, for example in the parameter types of the
command line that have support for specific entry points, such as the
IdentifierParamType.

The solution is to move the deprecation mechanic from the factories to
the lowest layer of get_entry_point.

@codecov
Copy link

codecov bot commented Oct 28, 2021

Codecov Report

Merging #5206 (d41e424) into develop (2d6df12) will increase coverage by 0.01%.
The diff coverage is 100.00%.

❗ Current head d41e424 differs from pull request most recent head c858832. Consider uploading reports for the commit c858832 to get more accurate results
Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #5206      +/-   ##
===========================================
+ Coverage    81.21%   81.22%   +0.01%     
===========================================
  Files          532      532              
  Lines        37347    37337      -10     
===========================================
- Hits         30329    30322       -7     
+ Misses        7018     7015       -3     
Flag Coverage Δ
django 76.07% <100.00%> (+0.01%) ⬆️
sqlalchemy 75.17% <100.00%> (+0.03%) ⬆️

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

Impacted Files Coverage Δ
aiida/plugins/entry_point.py 94.40% <100.00%> (+0.66%) ⬆️
aiida/plugins/factories.py 92.39% <100.00%> (+0.20%) ⬆️
aiida/orm/utils/calcjob.py 95.84% <0.00%> (+2.09%) ⬆️

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 2d6df12...c858832. Read the comment docs.

@sphuber sphuber force-pushed the fix/5202/deprecation-support-get-entry-point branch from 5637cfe to ab8d4a4 Compare October 29, 2021 07:00
@sphuber sphuber changed the title get_entry_point: integrate deprecation pathway for old entry points get_entry_point: add proper deprecation pathway for old entry points Oct 29, 2021

This method should be removed in ``aiida-core==3.0``
"""
deprecated_entry_points_mapping = {
Copy link
Member

Choose a reason for hiding this comment

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

I would move this out of the function, so you don't have to recreate the dictionary on every function call. Probably a marginal gain, but don't want to slow down the CLI

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Member

@ramirezfranciscof ramirezfranciscof left a comment

Choose a reason for hiding this comment

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

Thanks! Looks good to me in general, my only question is if it makes sense to have two separate functions doing this. I understand that maybe this is somehow "inherited" of the previous mechanism in which warn_deprecated_entry_point was called by many different factories with different lists of possible entry-points. But now that this is only required in get_entry_point, having that intermediate convert_potentially_deprecated_entry_point that only selects and passes the correct list of entry-points feels like bit forced separation of concerns. Could these be made a single function?

@sphuber sphuber force-pushed the fix/5202/deprecation-support-get-entry-point branch from ab8d4a4 to ab098e5 Compare November 1, 2021 19:39
@sphuber
Copy link
Contributor Author

sphuber commented Nov 1, 2021

Thanks @chrisjsewell and @ramirezfranciscof , addressed both your comments.

Copy link
Member

@chrisjsewell chrisjsewell left a comment

Choose a reason for hiding this comment

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

one more thing cheers

Comment on lines 300 to 302
from warnings import warn

from aiida.common.warnings import AiidaDeprecationWarning
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason to not have these as top-level imports?

Copy link
Contributor Author

@sphuber sphuber Nov 2, 2021

Choose a reason for hiding this comment

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

Because this function is the only place that uses them and when the function gets removed the obsolete imports are also automatically taken care off. Not a huge deal, but why not?

Copy link
Member

Choose a reason for hiding this comment

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

Meh, pylint will flag unused imports, so that's not an issue.
Yeh not a big deal, but that's the python coding standard that we use (outside reasons like CLI response and circular imports), whereas "single use imports should be internal to functions" is not.
Up to you

Copy link
Member

@ramirezfranciscof ramirezfranciscof left a comment

Choose a reason for hiding this comment

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

Thanks! Looks good to me! Feel free to merge after you finish your discussion with @chrisjsewell

BTW this seems the best way to do multi-people review, right? I mean, each approves separately and it is understood the author would wait for approval from all before merging (this would be opposed to something like giving "approving" messages as comment but the last reviewer leaves theirs as "approve")

@sphuber
Copy link
Contributor Author

sphuber commented Nov 2, 2021

BTW this seems the best way to do multi-people review, right? I mean, each approves separately and it is understood the author would wait for approval from all before merging

Yes, I wouldn't go and merge this before having resolved the conversation with @chrisjsewell

All entry points that ship with aiida-core were deprecated for v2.0
as they were changed to be properly prefixed with core.. To make sure
the old entry points would still be automatically loaded, the factories
were updated to automatically catch them, print a deprecation warning,
and load the new entry point instead.

However, the factory was not the correct place to put this logic, since
the `get_entry_point` method, which the factories call and is the lowest
function in the stack that actually retrieves the entry point, can also
be called directly, circumventing the deprecation mechanic added to the
factories. This would result in the deprecated entry points raising an
exception when being loaded, for example in the parameter types of the
command line that have support for specific entry points, such as the
`IdentifierParamType`.

The solution is to move the deprecation mechanic from the factories to
the lowest layer of `get_entry_point`.
@sphuber sphuber force-pushed the fix/5202/deprecation-support-get-entry-point branch from d41e424 to c858832 Compare November 2, 2021 20:56
@sphuber sphuber merged commit 5f259bd into aiidateam:develop Nov 2, 2021
@sphuber sphuber deleted the fix/5202/deprecation-support-get-entry-point branch November 2, 2021 21:19
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.

Verdi: DataParamType cannot be used with deprecated entry points
3 participants