Skip to content

Commit

Permalink
Refactoring importexport module.
Browse files Browse the repository at this point in the history
Split up and then remove `aiida.orm.importexport`.

Moved to `aiida.tools.importexport`.
Split up into structure (relative to `aiida.tools.importexport`:
./dbexport/__init__.py
./dbexport/utils.py
./dbexport/zip.py
./dbimport/__init__.py
./dbimport/backends/utils.py
./dbimport/backends/django/__init__.py
./dbimport/backends/sqla/__init__.py
./dbimport/backends/sqla/utils.py
./config.py
./utils.py

Import/export is now considered a tool, and has nothing to do with the
specifics of AiiDA.
It should be in a state, where it would be easy to remove it and save
it in a separate repo.

Import with a django or sqlalchemy backend has been split up.
For export, this is not needed, since it is already backend-independent.
To further reflect the split of backends, the actual import functions
have been placed
under `aiida.tools.importexport.dbimport.backends.[django/sqla].`.
In the future, `dbimport` should reflect the situation from `dbexport`
and be backend independent, creating the imported nodes through the
new backend-independent ORM entities.

Export to a zip-folder/file has been split up in a separate file.
This should later be implemented in another place, since a ZipFolder
class exists here.
For example `aiida.common.folder`. See also issue #3100.

Note: Be careful with wildcard imports in `__init__` files for backends
specific functionality.
  • Loading branch information
CasperWA committed Jul 1, 2019
1 parent eebef39 commit 9dbb85f
Show file tree
Hide file tree
Showing 21 changed files with 3,195 additions and 3,021 deletions.
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@
aiida/manage/backup/backup_base.py|
aiida/orm/autogroup.py|
aiida/orm/querybuilder.py|
aiida/orm/importexport.py|
aiida/orm/nodes/data/array/bands.py|
aiida/orm/nodes/data/array/projection.py|
aiida/orm/nodes/data/array/xy.py|
Expand Down
2 changes: 1 addition & 1 deletion aiida/backends/tests/orm/implementation/test_comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def test_creation_with_time(self):
Test creation of a BackendComment when passing the mtime and the ctime. The passed ctime and mtime
should be respected since it is important for the correct import of nodes at the AiiDA import/export.
"""
from aiida.orm.importexport import deserialize_attributes
from aiida.tools.importexport.dbimport.backends.utils import deserialize_attributes

ctime = deserialize_attributes('2019-02-27T16:20:12.245738', 'date')
mtime = deserialize_attributes('2019-02-27T16:27:14.798838', 'date')
Expand Down
2 changes: 1 addition & 1 deletion aiida/backends/tests/orm/implementation/test_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def test_creation_with_time(self):
Test creation of a BackendNode when passing the mtime and the ctime. The passed ctime and mtime
should be respected since it is important for the correct import of nodes at the AiiDA import/export.
"""
from aiida.orm.importexport import deserialize_attributes
from aiida.tools.importexport.dbimport.backends.utils import deserialize_attributes

ctime = deserialize_attributes('2019-02-27T16:20:12.245738', 'date')
mtime = deserialize_attributes('2019-02-27T16:27:14.798838', 'date')
Expand Down
6 changes: 3 additions & 3 deletions aiida/backends/tests/test_export_and_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from aiida import orm
from aiida.backends.testbase import AiidaTestCase
from aiida.common.utils import get_new_uuid
from aiida.orm.importexport import import_data, export
from aiida.tools.importexport import import_data, export
from aiida.backends.tests.utils.configuration import with_temp_dir


Expand Down Expand Up @@ -296,7 +296,7 @@ def test_control_of_licenses(self):
"""Test control of licenses."""
from aiida.common.exceptions import LicensingException
from aiida.common.folders import SandboxFolder
from aiida.orm.importexport import export_tree
from aiida.tools.importexport.dbexport import export_tree

from aiida.plugins import DataFactory

Expand Down Expand Up @@ -1175,7 +1175,7 @@ def test_different_computer_same_name_import(self, temp_dir):
This test checks that if there is a name collision, the imported
computers are renamed accordingly.
"""
from aiida.orm.importexport import DUPL_SUFFIX
from aiida.tools.importexport.config import DUPL_SUFFIX

# Set the computer name
comp1_name = "localhost_1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
from aiida.backends.tests.utils.archives import get_archive_file, get_json_files, migrate_archive
from aiida.backends.tests.utils.configuration import with_temp_dir
from aiida.cmdline.utils.migration import migrate_recursively, verify_metadata_version
from aiida.orm.importexport import import_data
from aiida.orm.importexport import EXPORT_VERSION as newest_version
from aiida.tools.importexport import import_data, EXPORT_VERSION as newest_version


class TestExportFileMigration(AiidaTestCase):
Expand Down
2 changes: 1 addition & 1 deletion aiida/backends/tests/utils/archives.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def import_archive(archive, filepath=None, external_module=None):
:param filepath: str of directories of where to find archive (starting "/"s are irrelevant)
:param external_module: string with name of external module, where archive can be found
"""
from aiida.orm.importexport import import_data
from aiida.tools.importexport import import_data

dirpath_archive = get_archive_file(archive, filepath=filepath, external_module=external_module)

Expand Down
2 changes: 1 addition & 1 deletion aiida/cmdline/commands/cmd_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def create(output_file, codes, computers, groups, nodes, archive_format, force,
Export various entities, such as Codes, Computers, Groups and Nodes, to an archive file for backup or
sharing purposes.
"""
from aiida.orm.importexport import export, export_zip
from aiida.tools.importexport import export, export_zip

entities = []

Expand Down
4 changes: 2 additions & 2 deletions aiida/cmdline/commands/cmd_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def _try_import(migration_performed, file_to_import, archive, group, migration,
`'extras_mode_new'`: `import_data`'s `'extras_mode_new'` keyword, determining import rules for Extras.
`'comment_mode'`: `import_data`'s `'comment_mode'` keyword, determining import rules for Comments.
"""
from aiida.orm.importexport import import_data
from aiida.tools.importexport import import_data

# Checks
expected_keys = ['extras_mode_existing', 'extras_mode_new', 'comment_mode']
Expand Down Expand Up @@ -191,7 +191,7 @@ def cmd_import(ctx, archives, webpages, group, extras_mode_existing, extras_mode
from six.moves import urllib

from aiida.common.folders import SandboxFolder
from aiida.orm.importexport import get_valid_import_links
from aiida.tools.importexport.utils import get_valid_import_links

archives_url = []
archives_file = []
Expand Down
Loading

0 comments on commit 9dbb85f

Please sign in to comment.