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

Make load_profile importable from aiida module #6609

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

unkcpz
Copy link
Member

@unkcpz unkcpz commented Nov 13, 2024

fixes #6608

load_profile() is widely used and documented. Exposing it as API under aiida module directly can make a bunch of LSP happy.

load_profile() is widely used and documented. Exposing it as API under
aiida module directly can make a bunch of LSP happy.
@unkcpz unkcpz requested a review from GeigerJ2 November 13, 2024 22:55
Copy link

codecov bot commented Nov 13, 2024

Codecov Report

Attention: Patch coverage is 82.92683% with 7 lines in your changes missing coverage. Please review.

Project coverage is 77.90%. Comparing base (ef60b66) to head (ec71c9f).
Report is 133 commits behind head on main.

Files with missing lines Patch % Lines
src/aiida/manage/configuration/profile.py 83.34% 4 Missing ⚠️
src/aiida/engine/daemon/client.py 71.43% 2 Missing ⚠️
src/aiida/__init__.py 87.50% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6609      +/-   ##
==========================================
+ Coverage   77.51%   77.90%   +0.40%     
==========================================
  Files         560      567       +7     
  Lines       41444    42177     +733     
==========================================
+ Hits        32120    32854     +734     
+ Misses       9324     9323       -1     

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

[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
@@ -35,6 +42,8 @@
)
__paper_short__ = 'S. P. Huber et al., Scientific Data 7, 300 (2020).'

__all__ = ['load_profile', 'configure_logging', 'get_config_option', 'get_profile', 'profile_context']
Copy link
Member Author

Choose a reason for hiding this comment

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

I think it makes no sense to expose configure_logging to end user. But for backward compatibility, I keep it for the moment. I prefer to remove it, agree?

For load_profile and profile_context and get_config_option, they are mentioned in the documentation so I keep those. The get_profile also seems quite handy.

Copy link
Collaborator

Choose a reason for hiding this comment

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

In order for this to not be a breaking change, you'll have to include get_strict_version and load_ipython_extension as well.

Copy link
Member Author

@unkcpz unkcpz Nov 14, 2024

Choose a reason for hiding this comment

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

What you mean? It was not there, I think by adding things no change is breaking.
The user still can do:

import aiida
aiida.get_strict_version

Even without the function in the __all__.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, but if they did from aiida import * than now suddenly get_strict_version will not be available.

Copy link
Collaborator

@danielhollas danielhollas Nov 14, 2024

Choose a reason for hiding this comment

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

In other words, I believe when __all__ is not defined, all symbols are imported when you do star import.

Copy link
Member Author

Choose a reason for hiding this comment

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

I tested, that's true, I didn't know before. Then I'll add them to __all__.

This avoid the use of file filepaths which has inconsistent return types
@danielhollas danielhollas self-requested a review November 14, 2024 12:07
@danielhollas
Copy link
Collaborator

danielhollas commented Nov 14, 2024

Exposing it as API under aiida module directly can make a bunch of LSP happy.

Out of curiosity, which LSPs specifically are you talking about?

The load_profile is exposed from aiida package. The __all__ attribute influences only the star imports (from aiida import *). So I don't understand why an LSP should complain.

https://docs.python.org/3/tutorial/modules.html#importing-from-a-package


@property
def daemon_pid_file(self) -> str:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn't this a breaking change if the return type is changed?

Copy link
Member Author

Choose a reason for hiding this comment

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

Since it is python, I don't regard it as a "breaking change". The mypy might be unhappy if you already use types on downsteram plugins. But functionality side it won't break anything.

Copy link
Member Author

@unkcpz unkcpz Nov 14, 2024

Choose a reason for hiding this comment

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

Sorry, I think I am not correct, the function return type changed actually.
Then my argument would be, this is the function I think should not exposed as public API.

In the end, we need a clear thoughts and go through again things and make API exposed very clear. One typical bad impl is for scheduler plugins, the API we exposed to allow user to implement new scheduler is methods start with underscore. But that is another story, happy to discuss next week in person.

@unkcpz
Copy link
Member Author

unkcpz commented Nov 14, 2024

Out of curiosity, which LSPs specifically are you talking about?

The load_profile is exposed from aiida package. The all attribute influences only the star imports (from aiida import *). So I don't understand why an LSP should complain.

I use basedpyright, and I think it is also good to have a list of what APIs we are going to exposed explicitly in all, besides make LSP happy.

@unkcpz unkcpz marked this pull request as draft November 14, 2024 16:56
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.

"aiida" module does not have the __all__ attribute
2 participants