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
15 changes: 12 additions & 3 deletions src/aiida/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,15 @@
More information at http://www.aiida.net
"""

from aiida.common.log import configure_logging # noqa: F401
from aiida.manage.configuration import get_config_option, get_profile, load_profile, profile_context # noqa: F401
from __future__ import annotations

from typing import TYPE_CHECKING

from aiida.common.log import configure_logging
from aiida.manage.configuration import get_config_option, get_profile, load_profile, profile_context

if TYPE_CHECKING:
from IPython.core.interactiveshell import InteractiveShell

Check warning on line 30 in src/aiida/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/aiida/__init__.py#L30

Added line #L30 was not covered by tests

__copyright__ = (
'Copyright (c), This file is part of the AiiDA platform. '
Expand All @@ -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__.



def get_strict_version():
"""Return a distutils StrictVersion instance with the current distribution version
Expand Down Expand Up @@ -93,7 +102,7 @@
return '\n'.join(f'{comment_char}{line}' for line in lines)


def load_ipython_extension(ipython):
def load_ipython_extension(ipython: InteractiveShell):
"""Load the AiiDA IPython extension, using ``%load_ext aiida``."""
from .tools.ipython.ipython_magics import AiiDALoaderMagics

Expand Down
3 changes: 2 additions & 1 deletion src/aiida/common/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import logging
import types
import typing as t
from pathlib import Path

__all__ = ('AIIDA_LOGGER', 'override_log_level')

Expand Down Expand Up @@ -164,7 +165,7 @@ def evaluate_logging_configuration(dictionary):
return result


def configure_logging(with_orm=False, daemon=False, daemon_log_file=None):
def configure_logging(with_orm: bool = False, daemon: bool = False, daemon_log_file: None | Path = None) -> None:
"""Setup the logging by retrieving the LOGGING dictionary from aiida and passing it to
the python module logging.config.dictConfig. If the logging needs to be setup for the
daemon, set the argument 'daemon' to True and specify the path to the log file. This
Expand Down
Loading