Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/aiida/cmdline/utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def get_env_with_venv_bin() -> MutableMapping:
config = get_config()

currenv = os.environ.copy()
currenv['PATH'] = f"{os.path.dirname(sys.executable)}:{currenv['PATH']}"
currenv['PATH'] = f'{os.path.dirname(sys.executable)}:{currenv["PATH"]}'
currenv['AIIDA_PATH'] = config.dirpath
currenv['PYTHONUNBUFFERED'] = 'True'

Expand Down Expand Up @@ -180,18 +180,18 @@ def get_node_info(node: orm.Node, include_summary: bool = True) -> str:
nodes_output = node.base.links.get_outgoing(link_type=(LinkType.CREATE, LinkType.RETURN))

if nodes_input:
result += f"\n{format_nested_links(nodes_input.nested(), headers=['Inputs', 'PK', 'Type'])}"
result += f'\n{format_nested_links(nodes_input.nested(), headers=["Inputs", "PK", "Type"])}'

if nodes_output:
result += f"\n{format_nested_links(nodes_output.nested(), headers=['Outputs', 'PK', 'Type'])}"
result += f'\n{format_nested_links(nodes_output.nested(), headers=["Outputs", "PK", "Type"])}'

if nodes_caller:
links = sorted(nodes_caller.all(), key=lambda x: x.node.ctime)
result += f"\n{format_flat_links(links, headers=['Caller', 'PK', 'Type'])}"
result += f'\n{format_flat_links(links, headers=["Caller", "PK", "Type"])}'

if nodes_called:
links = sorted(nodes_called.all(), key=lambda x: x.node.ctime)
result += f"\n{format_flat_links(links, headers=['Called', 'PK', 'Type'])}"
result += f'\n{format_flat_links(links, headers=["Called", "PK", "Type"])}'

log_messages = orm.Log.collection.get_logs_for(node)

Expand Down Expand Up @@ -253,7 +253,7 @@ def format_recursive(links, depth=0):
table = []

for depth, label, pk, class_name in format_recursive(links):
table.append([f"{' ' * (depth * indent_size)}{label}", pk, class_name])
table.append([f'{" " * (depth * indent_size)}{label}', pk, class_name])

result = f'\n{tabulate(table, headers=headers)}'
tb.PRESERVE_WHITESPACE = False
Expand All @@ -279,7 +279,7 @@ def get_calcjob_report(calcjob: orm.CalcJobNode) -> str:
report = []

if calcjob_state == CalcJobState.WITHSCHEDULER:
state_string = f"{calcjob_state}, scheduler state: {scheduler_state if scheduler_state else '(unknown)'}"
state_string = f'{calcjob_state}, scheduler state: {scheduler_state if scheduler_state else "(unknown)"}'
else:
state_string = f'{calcjob_state}'

Expand Down
12 changes: 10 additions & 2 deletions src/aiida/common/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,17 @@
from __future__ import annotations

import pathlib
import sys
from typing import Union

__all__ = ('FilePath',)

if sys.version_info >= (3, 11):
from typing import Self
else:
from typing_extensions import Self

FilePath = Union[str, pathlib.PurePath]

__all__ = (
'FilePath',
'Self',
)
26 changes: 13 additions & 13 deletions src/aiida/orm/authinfos.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from __future__ import annotations

from typing import TYPE_CHECKING, Any, Dict, Optional, Type
from typing import TYPE_CHECKING, Any

from aiida.common import exceptions
from aiida.common.pydantic import MetadataField
Expand All @@ -33,7 +33,7 @@ class AuthInfoCollection(entities.Collection['AuthInfo']):
"""The collection of `AuthInfo` entries."""

@staticmethod
def _entity_base_cls() -> Type['AuthInfo']:
def _entity_base_cls() -> type['AuthInfo']:
return AuthInfo

def delete(self, pk: int) -> None:
Expand Down Expand Up @@ -68,12 +68,12 @@ class Model(entities.Entity.Model):
description='Whether the instance is enabled',
is_attribute=False,
)
auth_params: Dict[str, Any] = MetadataField(
auth_params: dict[str, Any] = MetadataField(
default_factory=dict,
description='Dictionary of authentication parameters',
is_attribute=False,
)
metadata: Dict[str, Any] = MetadataField(
metadata: dict[str, Any] = MetadataField(
default_factory=dict,
description='Dictionary of metadata',
is_attribute=False,
Expand All @@ -84,9 +84,9 @@ def __init__(
computer: 'Computer',
user: 'User',
enabled: bool = True,
auth_params: Dict[str, Any] | None = None,
metadata: Dict[str, Any] | None = None,
backend: Optional['StorageBackend'] = None,
auth_params: dict[str, Any] | None = None,
metadata: dict[str, Any] | None = None,
backend: 'StorageBackend' | None = None,
) -> None:
"""Create an `AuthInfo` instance for the given computer and user.

Expand Down Expand Up @@ -151,35 +151,35 @@ def user(self) -> 'User':
return entities.from_backend_entity(users.User, self._backend_entity.user)

@property
def auth_params(self) -> Dict[str, Any]:
def auth_params(self) -> dict[str, Any]:
return self._backend_entity.get_auth_params()

@property
def metadata(self) -> Dict[str, Any]:
def metadata(self) -> dict[str, Any]:
return self._backend_entity.get_metadata()

def get_auth_params(self) -> Dict[str, Any]:
def get_auth_params(self) -> dict[str, Any]:
"""Return the dictionary of authentication parameters

:return: a dictionary with authentication parameters
"""
return self._backend_entity.get_auth_params()

def set_auth_params(self, auth_params: Dict[str, Any]) -> None:
def set_auth_params(self, auth_params: dict[str, Any]) -> None:
"""Set the dictionary of authentication parameters

:param auth_params: a dictionary with authentication parameters
"""
self._backend_entity.set_auth_params(auth_params)

def get_metadata(self) -> Dict[str, Any]:
def get_metadata(self) -> dict[str, Any]:
"""Return the dictionary of metadata

:return: a dictionary with metadata
"""
return self._backend_entity.get_metadata()

def set_metadata(self, metadata: Dict[str, Any]) -> None:
def set_metadata(self, metadata: dict[str, Any]) -> None:
"""Set the dictionary of metadata

:param metadata: a dictionary with metadata
Expand Down
34 changes: 26 additions & 8 deletions src/aiida/orm/comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
###########################################################################
"""Comment objects and functions"""

from __future__ import annotations

from datetime import datetime
from typing import TYPE_CHECKING, List, Optional, Type
from typing import TYPE_CHECKING, Optional

from aiida.common.pydantic import MetadataField
from aiida.manage import get_manager
Expand All @@ -29,7 +31,7 @@ class CommentCollection(entities.Collection['Comment']):
"""The collection of Comment entries."""

@staticmethod
def _entity_base_cls() -> Type['Comment']:
def _entity_base_cls() -> type['Comment']:
return Comment

def delete(self, pk: int) -> None:
Expand All @@ -49,7 +51,7 @@ def delete_all(self) -> None:
"""
self._backend.comments.delete_all()

def delete_many(self, filters: dict) -> List[int]:
def delete_many(self, filters: dict) -> list[int]:
"""Delete Comments from the Collection based on ``filters``

:param filters: similar to QueryBuilder filter
Expand All @@ -69,13 +71,22 @@ class Comment(entities.Entity['BackendComment', CommentCollection]):

class Model(entities.Entity.Model):
uuid: Optional[str] = MetadataField(
description='The UUID of the comment', is_attribute=False, exclude_to_orm=True
None,
description='The UUID of the comment',
is_attribute=False,
exclude_to_orm=True,
)
ctime: Optional[datetime] = MetadataField(
description='Creation time of the comment', is_attribute=False, exclude_to_orm=True
None,
description='Creation time of the comment',
is_attribute=False,
exclude_to_orm=True,
)
mtime: Optional[datetime] = MetadataField(
description='Modified time of the comment', is_attribute=False, exclude_to_orm=True
None,
description='Modified time of the comment',
is_attribute=False,
exclude_to_orm=True,
)
node: int = MetadataField(
description='Node PK that the comment is attached to',
Expand All @@ -89,10 +100,17 @@ class Model(entities.Entity.Model):
orm_class='core.user',
orm_to_model=lambda comment, _: comment.user.pk,
)
content: str = MetadataField(description='Content of the comment', is_attribute=False)
content: str = MetadataField(
description='Content of the comment',
is_attribute=False,
)

def __init__(
self, node: 'Node', user: 'User', content: Optional[str] = None, backend: Optional['StorageBackend'] = None
self,
node: 'Node',
user: 'User',
content: str | None = None,
backend: 'StorageBackend' | None = None,
):
"""Create a Comment for a given node and user

Expand Down
Loading