Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Sep 25, 2024
1 parent aa821b8 commit e890bc2
Show file tree
Hide file tree
Showing 15 changed files with 137 additions and 258 deletions.
6 changes: 2 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ requires-python = '>=3.9'
'core.structure' = 'aiida.orm.nodes.data.structure:StructureData'
'core.upf' = 'aiida.orm.nodes.data.upf:UpfData'

[project.entry-points.'aiida.exporters']

[project.entry-points.'aiida.groups']
'core' = 'aiida.orm.groups:Group'
'core.auto' = 'aiida.orm.groups:AutoGroup'
Expand Down Expand Up @@ -180,10 +182,6 @@ requires-python = '>=3.9'
'core.arithmetic.add_multiply' = 'aiida.workflows.arithmetic.add_multiply:add_multiply'
'core.arithmetic.multiply_add' = 'aiida.workflows.arithmetic.multiply_add:MultiplyAddWorkChain'

[project.entry-points.'aiida.exporters']
# 'core.arithmetic.add_multiply' = 'aiida.workflows.arithmetic.add_multiply:add_multiply'
# 'core.arithmetic.multiply_add' = 'aiida.workflows.arithmetic.multiply_add:MultiplyAddWorkChain'

[project.optional-dependencies]
atomic_tools = [
'PyCifRW~=4.4',
Expand Down
16 changes: 6 additions & 10 deletions src/aiida/cmdline/commands/cmd_data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
"""The `verdi data` command line interface."""

from aiida.cmdline.commands.cmd_verdi import verdi
from aiida.cmdline.utils.pluginable import Pluginable
from aiida.cmdline.params import arguments, options, types
from aiida.cmdline.utils.pluginable import Pluginable


@verdi.group('data', entry_point_group='aiida.cmdline.data', cls=Pluginable)
def verdi_data():
"""Inspect, create and manage data nodes."""


@verdi_data.command('dump')
@arguments.DATA()
@options.PATH()
Expand All @@ -27,22 +28,17 @@ def data_dump(
path,
overwrite,
) -> None:

"""Dump an arbitrary `Data` node entity to disk.
"""
"""Dump an arbitrary `Data` node entity to disk."""
from aiida.tools.dumping.data import DataDumper

data_dumper = DataDumper(
overwrite=overwrite
)
data_dumper = DataDumper(overwrite=overwrite)

print(type(data), data)
# `data` comes as a tuple
if len(data) > 1:
raise NotImplementedError("Dumping of multiple data nodes not yet supported.")
raise NotImplementedError('Dumping of multiple data nodes not yet supported.')

# Probs shouldn't do that. Quick hack.
data=data[0]
data = data[0]

data_dumper.dump(data_node=data, output_path=path)
3 changes: 1 addition & 2 deletions src/aiida/cmdline/commands/cmd_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,7 @@ def group_path_ls(path, type_string, recursive, as_table, no_virtual, with_descr
continue
echo.echo(child.path, bold=not child.is_virtual)


@verdi_group.command('dump')
@arguments.GROUP()
# @with_dbenv()
Expand All @@ -659,10 +660,8 @@ def group_path_ls(path, type_string, recursive, as_table, no_virtual, with_descr
# help='Add a filter to show only groups for which the label contains STRING.',
# )
def group_dump(group):

print(group)
from aiida.tools.dumping.group import GroupDumper

group_dumper = GroupDumper()
group_dumper.dump(group)

5 changes: 1 addition & 4 deletions src/aiida/cmdline/commands/cmd_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,10 +670,7 @@ def process_dump(

try:
dump_path = process_dumper.dump(
process_node=process,
output_path=path,
include_attributes=include_attributes,
include_extras=include_extras
process_node=process, output_path=path, include_attributes=include_attributes, include_extras=include_extras
)
except FileExistsError:
echo.echo_critical(
Expand Down
1 change: 1 addition & 0 deletions src/aiida/cmdline/commands/cmd_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ def profile_delete(force, delete_data, profiles):
get_config().delete_profile(profile.name, delete_storage=delete_data)
echo.echo_success(f'Profile `{profile.name}` was deleted.')


@verdi_profile.command('dump')
@options.PATH()
@arguments.PROFILE(default=defaults.get_default_profile)
Expand Down
63 changes: 25 additions & 38 deletions src/aiida/cmdline/commands/cmd_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
###########################################################################
"""`verdi storage` commands."""

import sys
import pathlib
import sys

import click
from click_spinner import spinner

from aiida.cmdline.commands.cmd_verdi import verdi
from aiida.cmdline.params import options, arguments
from aiida.cmdline.utils import decorators, echo, defaults
from aiida.cmdline.params import arguments, options
from aiida.cmdline.utils import decorators, defaults, echo
from aiida.common import exceptions
from aiida.tools.dumping import ProfileDumper, CollectionDumper, ProcessDumper, DataDumper, GroupDumper
from aiida.tools.dumping import GroupDumper


@verdi.group('storage')
Expand Down Expand Up @@ -246,15 +246,15 @@ def storage_backup(ctx, manager, dest: str, keep: int):
# TODO: Follow API of `verdi archive create`
# ? Specify groups via giving the groups, or just enabling "groups" and then all are dumped?
# ? Provide some mechanism to allow for both, e.g. if no argument is provided, all groups are dumped
@verdi_storage.command("mirror")
@verdi_storage.command('mirror')
@arguments.PROFILE(default=defaults.get_default_profile)
# Custom `--path` option, otherwise conflicting `-p` with `profile` argument
@click.option(
"--path",
'--path',
type=click.Path(path_type=pathlib.Path),
show_default=True,
default=None,
help="Base path for operations that write to disk.",
help='Base path for operations that write to disk.',
)
# @options.PATH()
@options.ALL()
Expand All @@ -272,52 +272,40 @@ def storage_backup(ctx, manager, dest: str, keep: int):
# help='Dump all profile data, overwriting existing files.',
# )
@click.option(
"-p",
"--process-only",
'-p',
'--process-only',
is_flag=True,
default=False,
help="Dump only processes, no explicit data nodes",
help='Dump only processes, no explicit data nodes',
)
@click.option(
"-d",
"--data-only",
'-d',
'--data-only',
is_flag=True,
default=False,
help="Dump only data nodes, no processes",
help='Dump only data nodes, no processes',
)
def archive_mirror(
profile,
path,
all_entries,
nodes,
groups,
codes,
computers,
also_raw,
also_rich,
process_only,
data_only,
**kwargs
profile, path, all_entries, nodes, groups, codes, computers, also_raw, also_rich, process_only, data_only, **kwargs
):
"""Dump profile data to disk."""
from rich.pretty import pprint

pprint(locals())

from aiida import orm

if profile is None:
echo.echo_critical("No profile selected to dump")
echo.echo_critical('No profile selected to dump')

# if path is
if not str(path).endswith(profile.name):
path /= profile.name

inheritance_kwargs = {
'profile': profile,
'parent_path': path,
**kwargs,
}
'profile': profile,
'parent_path': path,
**kwargs,
}

echo.echo_report(f"Dumping of profile `{profile.name}`'s data at path: `{path}`")

Expand All @@ -327,24 +315,23 @@ def archive_mirror(
entities = {}

if nodes:
entities["nodes"] = nodes
entities['nodes'] = nodes

if codes:
entities["codes"] = codes
entities['codes'] = codes

if computers:
entities["computers"] = computers
entities['computers'] = computers

if groups:
entities["groups"] = groups

entities['groups'] = groups

for group in groups:
print('GROUP', group)
group_dumper = GroupDumper(**inheritance_kwargs)
group_dumper.pretty_print()
group_dumper.dump(group)

# if entities is not None and "groups" in entities:

# if not data_only:
Expand Down
22 changes: 11 additions & 11 deletions src/aiida/tools/dumping/abstract.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import pathlib

from rich.console import Console
from rich.table import Table

Expand All @@ -13,7 +14,7 @@ def __init__(
incremental: bool = False,
also_raw: bool = False,
also_rich: bool = False,
dry_run: bool = False
dry_run: bool = False,
):
self.parent_path = parent_path
self.overwrite = overwrite
Expand All @@ -24,12 +25,12 @@ def __init__(

def pretty_print(self, also_private: bool = True, also_dunder: bool = False):
console = Console()
table = Table(title=f"Attributes and Methods of {self.__class__.__name__}")
table = Table(title=f'Attributes and Methods of {self.__class__.__name__}')

# Adding columns to the table
table.add_column("Name", justify="left")
table.add_column("Type", justify="left")
table.add_column("Value", justify="left")
table.add_column('Name', justify='left')
table.add_column('Type', justify='left')
table.add_column('Value', justify='left')

# Lists to store attributes and methods
entries = []
Expand All @@ -40,28 +41,27 @@ def pretty_print(self, also_private: bool = True, also_dunder: bool = False):
if not also_private and not also_dunder:
if not (attr_name.startswith('_') or attr_name.endswith('_')):
attr_value = getattr(self, attr_name)
entry_type = "Attribute" if not callable(attr_value) else "Method"
entry_type = 'Attribute' if not callable(attr_value) else 'Method'
entries.append((attr_name, entry_type, str(attr_value)))

if not also_private:
if attr_name.startswith('__'):
attr_value = getattr(self, attr_name)
entry_type = "Attribute" if not callable(attr_value) else "Method"
entry_type = 'Attribute' if not callable(attr_value) else 'Method'
entries.append((attr_name, entry_type, str(attr_value)))

if not also_dunder:
if not attr_name.startswith('__'):
attr_value = getattr(self, attr_name)
entry_type = "Attribute" if not callable(attr_value) else "Method"
entry_type = 'Attribute' if not callable(attr_value) else 'Method'
entries.append((attr_name, entry_type, str(attr_value)))
else:
attr_value = getattr(self, attr_name)
entry_type = "Attribute" if not callable(attr_value) else "Method"
entry_type = 'Attribute' if not callable(attr_value) else 'Method'
entries.append((attr_name, entry_type, str(attr_value)))


# Sort entries: attributes first, then methods
entries.sort(key=lambda x: (x[1] == "Method", x[0]))
entries.sort(key=lambda x: (x[1] == 'Method', x[0]))

# Add sorted entries to the table
for name, entry_type, value in entries:
Expand Down
10 changes: 5 additions & 5 deletions src/aiida/tools/dumping/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
###########################################################################
"""Functionality for dumping of a Collections of AiiDA ORMs."""

from aiida import orm
import logging
from collections import Counter

from rich.pretty import pprint

from aiida import orm
from aiida.manage.configuration import Profile
from aiida.tools.dumping.abstract import AbstractDumper
from aiida.tools.dumping.data import DataDumper
from aiida.tools.dumping.process import ProcessDumper
from aiida.manage.configuration import Profile
from rich.pretty import pprint
from rich.console import Console
from rich.table import Table

LOGGER = logging.getLogger(__name__)
# TODO: Could also get the entities, or UUIDs directly, rather than just counting them here
Expand Down
11 changes: 6 additions & 5 deletions src/aiida/tools/dumping/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@
"""Functionality for dumping of Data nodes."""

from __future__ import annotations

import logging
from functools import singledispatchmethod
from pathlib import Path

import yaml

from aiida import orm
from aiida.orm.nodes.data.structure import StructureData
from pathlib import Path
import logging
import yaml
from aiida.tools.dumping.abstract import AbstractDumper


logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -91,7 +92,7 @@ def _dump_code(
file_name: str | Path | None = None,
file_format: str = 'yaml',
*args,
**kwargs
**kwargs,
):
if output_path is None:
output_path = Path.cwd()
Expand Down
2 changes: 1 addition & 1 deletion src/aiida/tools/dumping/gio-dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ def export_structure(node, folder, **kargs): # GP: support both functions and cl
# GP: Not specified means use the default, for now from hardcoded list, in the future reading from some defined method of the plugin

# This could be entry point given in plugin
aiida.orm.data.StructureData.export_to_dir # think to a syntax for methods
aiida.orm.data.StructureData.export_to_dir # think to a syntax for methods
Loading

0 comments on commit e890bc2

Please sign in to comment.