diff --git a/docs/source/conf.py b/docs/source/conf.py index 03922a0efa..2b68da42f8 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -312,6 +312,7 @@ def setup(app: Sphinx): 'BackendLog': 'aiida.orm.implementation.logs.BackendLog', 'BackendNode': 'aiida.orm.implementation.nodes.BackendNode', 'BackendUser': 'aiida.orm.implementation.users.BackendUser', + 'InteractiveShell': 'IPython.core.interactiveshell.InteractiveShell', } diff --git a/docs/source/nitpick-exceptions b/docs/source/nitpick-exceptions index bf0ba64d66..40cfa756a8 100644 --- a/docs/source/nitpick-exceptions +++ b/docs/source/nitpick-exceptions @@ -200,6 +200,7 @@ py:class PGTest py:class pgtest.pgtest.PGTest py:class IPython.core.magic.Magics +py:class IPython.core.interactiveshell.InteractiveShell py:class HTMLParser.HTMLParser py:class html.parser.HTMLParser diff --git a/src/aiida/__init__.py b/src/aiida/__init__.py index 743c5009ab..7459797b85 100644 --- a/src/aiida/__init__.py +++ b/src/aiida/__init__.py @@ -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 __copyright__ = ( 'Copyright (c), This file is part of the AiiDA platform. ' @@ -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'] + def get_strict_version(): """Return a distutils StrictVersion instance with the current distribution version @@ -93,7 +102,7 @@ def get_file_header(comment_char: str = '# ') -> str: 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 diff --git a/src/aiida/common/log.py b/src/aiida/common/log.py index fc0f860aef..b419887f5f 100644 --- a/src/aiida/common/log.py +++ b/src/aiida/common/log.py @@ -164,7 +164,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 | str = 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 diff --git a/src/aiida/engine/daemon/client.py b/src/aiida/engine/daemon/client.py index ef250802f7..71ce942c41 100644 --- a/src/aiida/engine/daemon/client.py +++ b/src/aiida/engine/daemon/client.py @@ -156,31 +156,31 @@ def virtualenv(self) -> str | None: @property def circus_log_file(self) -> str: - return self.profile.filepaths['circus']['log'] + return str(self.profile.circus_log_file) @property def circus_pid_file(self) -> str: - return self.profile.filepaths['circus']['pid'] + return str(self.profile.circus_pid_file) @property def circus_port_file(self) -> str: - return self.profile.filepaths['circus']['port'] + return str(self.profile.circus_port_file) @property def circus_socket_file(self) -> str: - return self.profile.filepaths['circus']['socket']['file'] + return str(self.profile.circus_socket_endpoints['file']) @property def circus_socket_endpoints(self) -> dict[str, str]: - return self.profile.filepaths['circus']['socket'] + return {k: str(v) for k, v in self.profile.circus_socket_endpoints.items()} @property def daemon_log_file(self) -> str: - return self.profile.filepaths['daemon']['log'] + return str(self.profile.daemon_log_file) @property def daemon_pid_file(self) -> str: - return self.profile.filepaths['daemon']['pid'] + return str(self.profile.daemon_pid_file) def get_circus_port(self) -> int: """Retrieve the port for the circus controller, which should be written to the circus port file. diff --git a/src/aiida/manage/configuration/profile.py b/src/aiida/manage/configuration/profile.py index acaca2e892..f70d5c49b3 100644 --- a/src/aiida/manage/configuration/profile.py +++ b/src/aiida/manage/configuration/profile.py @@ -20,6 +20,8 @@ from .options import parse_option +# from .settings import DAEMON_DIR, DAEMON_LOG_DIR + if TYPE_CHECKING: from aiida.orm.implementation import StorageBackend @@ -229,6 +231,47 @@ def repository_path(self) -> pathlib.Path: return pathlib.Path(os.path.expanduser(parts.path)) + @property + def circus_log_file(self) -> pathlib.Path: + from .settings import DAEMON_LOG_DIR + + return DAEMON_LOG_DIR / f'circus_{self.name}.log' + + @property + def circus_pid_file(self) -> pathlib.Path: + from .settings import DAEMON_DIR + + return DAEMON_DIR / f'circus_{self.name}.pid' + + @property + def circus_port_file(self) -> pathlib.Path: + from .settings import DAEMON_DIR + + return DAEMON_DIR / f'circus-{self.name}.port' + + @property + def circus_socket_endpoints(self) -> dict[str, pathlib.Path]: + from .settings import DAEMON_DIR + + return { + 'file': DAEMON_DIR / f'circus-{self.name}.sockets', + 'controller': pathlib.Path('circus.c.sock'), + 'pubsub': pathlib.Path('circus.p.sock'), + 'stats': pathlib.Path('circus.s.sock'), + } + + @property + def daemon_log_file(self) -> pathlib.Path: + from .settings import DAEMON_LOG_DIR + + return DAEMON_LOG_DIR / f'aiida-{self.name}.log' + + @property + def daemon_pid_file(self) -> pathlib.Path: + from .settings import DAEMON_DIR + + return DAEMON_DIR / f'aiida-{self.name}.pid' + @property def filepaths(self): """Return the filepaths used by this profile. diff --git a/src/aiida/tools/pytest_fixtures/daemon.py b/src/aiida/tools/pytest_fixtures/daemon.py index 74e3620193..29f419a925 100644 --- a/src/aiida/tools/pytest_fixtures/daemon.py +++ b/src/aiida/tools/pytest_fixtures/daemon.py @@ -28,6 +28,7 @@ def test(daemon_client): from aiida.engine.daemon import get_daemon_client from aiida.engine.daemon.client import DaemonNotRunningException, DaemonTimeoutException + print(aiida_profile) daemon_client = get_daemon_client(aiida_profile.name) try: