Skip to content

Commit

Permalink
Auto-load default AiiDA profile
Browse files Browse the repository at this point in the history
  • Loading branch information
GeigerJ2 committed Jun 21, 2024
1 parent c2ca642 commit 47a07e0
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/aiida/manage/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,9 @@ def get_backend(self) -> 'StorageBackend':

def get_profile_storage(self) -> 'StorageBackend':
"""Return the current profile's storage backend, loading it if necessary."""
from aiida.cmdline.utils.defaults import get_default_profile
from aiida.common import ConfigurationError
from aiida.common.exceptions import InvalidOperation
from aiida.common.log import configure_logging
from aiida.manage.profile_access import ProfileAccessManager

Expand All @@ -253,10 +255,16 @@ def get_profile_storage(self) -> 'StorageBackend':

# get the currently loaded profile
profile = self.get_profile()

# try to load the default profile
if profile is None:
raise ConfigurationError(
'Could not determine the current profile. Consider loading a profile using `aiida.load_profile()`.'
)
try:
default_profile = get_default_profile()
profile = self.load_profile(default_profile)
except (TypeError, InvalidOperation) as e:
raise ConfigurationError(
'Default profile couldn\'t be loaded. Consider loading one manually via `aiida.load_profile()`.'
) from e

# request access to the profile (for example, if it is being used by a maintenance operation)
ProfileAccessManager(profile).request_access()
Expand Down

0 comments on commit 47a07e0

Please sign in to comment.