Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

builtins.ModuleNotFoundError: No module named 'aiida.backends.tests' #3911

Closed
hongyi-zhao opened this issue Apr 8, 2020 · 6 comments
Closed

Comments

@hongyi-zhao
Copy link

Hi,

I try to run the code snippet given here

from aiida import load_profile
profile = load_profile()

from aiida.common import LinkType
from aiida.orm.utils.links import LinkPair
from aiida.backends.tests.utils.archives import get_archive_file
from aiida.tools.visualization import Graph, pstate_node_styles

But meet the error:

builtins.ModuleNotFoundError: No module named 'aiida.backends.tests'

Any hints?

Regards

@sphuber
Copy link
Contributor

sphuber commented Apr 8, 2020

Hi @hongyi-zhao , this is another problem in the documentation that I will move to the central issue. The module has simply moved, you can now import it from from tests.utils.archives import get_archive_file

@hongyi-zhao
Copy link
Author

hongyi-zhao commented Apr 8, 2020

@sphuber I also got it from greping the source code as follows:

$ grep -rl 'get_archive_file' * | grep archives
tests/utils/archives.py

But using the following import method:

from tests.utils.archives import get_archive_file

still give me the error as follows:

builtins.ModuleNotFoundError: No module named 'tests.utils'

Are you sure it should be imported like this?

Regards

@sphuber
Copy link
Contributor

sphuber commented Apr 8, 2020

the problem is that this function is really just a utility function for testing, so it has been moved to the tests folder in the aiida-core repository. Since this is outside of the aiida package, it is not an actual module and cannot be imported like normally, unless it is added to the PYTHONPATH explicitly. For now, since you have the source, you can maybe just get the absolute path of the graph1.aiida file directly. That is all that the get_archive_file utility is returning anyway. The file should be in aiida-core/tests/fixtures/graphs/graph1.aiida

@hongyi-zhao
Copy link
Author

Failed, see following:

$ verdi import -n /home/werner/Public/hpc/tools/aiida/aiida-core.git/tests/fixtures/graphs/graph1.aiida
Info: importing archive /home/werner/Public/hpc/tools/aiida/aiida-core.git/tests/fixtures/graphs/graph1.aiida
READING DATA AND METADATA...
EXTRACTING NODE DATA...
Warning: Export file version is 0.6, can import only version 0.8
Info: migrating archive /home/werner/Public/hpc/tools/aiida/aiida-core.git/tests/fixtures/graphs/graph1.aiida
READING DATA AND METADATA...
EXTRACTING NODE DATA...

Warning: 
************************************************************************************************************************
Found one or multiple records that violate the integrity of the database
Violation reason: Found ProcessNodes with active process states that should never have been allowed to be exported.
Performed action: nothing
Violators written to: /home/werner/.cache/wingpro7/migration-72lk08wt.log
************************************************************************************************************************

Error: an exception occurred while migrating the archive /home/werner/Public/hpc/tools/aiida/aiida-core.git/tests/fixtures/graphs/graph1.aiida.
Use 'verdi export migrate' to update this export file.
Traceback (most recent call last):
  File "/home/werner/Public/hpc/tools/aiida/aiida-core.git/aiida/cmdline/commands/cmd_import.py", line 123, in _migrate_archive
    migrate, input_file=file_to_import, output_file=temp_folder.get_abs_path(temp_out_file), silent=False
  File "/home/werner/.pyenv/versions/3.7.6/envs/aiida/lib/python3.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/home/werner/Public/hpc/tools/aiida/aiida-core.git/aiida/cmdline/commands/cmd_export.py", line 181, in migrate
    new_version = migration.migrate_recursively(metadata, data, folder)
  File "/home/werner/Public/hpc/tools/aiida/aiida-core.git/aiida/tools/importexport/migration/__init__.py", line 54, in migrate_recursively
    MIGRATE_FUNCTIONS[old_version](metadata, data, folder)
  File "/home/werner/Public/hpc/tools/aiida/aiida-core.git/aiida/tools/importexport/migration/v06_to_v07.py", line 124, in migrate_v6_to_v7
    migration_data_migration_legacy_process_attributes(data)
  File "/home/werner/Public/hpc/tools/aiida/aiida-core.git/aiida/tools/importexport/migration/v06_to_v07.py", line 94, in migration_data_migration_legacy_process_attributes
    'Your export archive is corrupt! '
aiida.tools.importexport.common.exceptions.CorruptArchive: Your export archive is corrupt! Please see the log-file in your current directory for more details.

Error: an exception occurred while importing the archive /home/werner/Public/hpc/tools/aiida/aiida-core.git/tests/fixtures/graphs/graph1.aiida
Traceback (most recent call last):
  File "/home/werner/Public/hpc/tools/aiida/aiida-core.git/aiida/cmdline/commands/cmd_import.py", line 65, in _try_import
    import_data(file_to_import, group, **kwargs)
  File "/home/werner/Public/hpc/tools/aiida/aiida-core.git/aiida/tools/importexport/dbimport/__init__.py", line 73, in import_data
    return import_data_dj(in_path, group=group, silent=silent, **kwargs)
  File "/home/werner/Public/hpc/tools/aiida/aiida-core.git/aiida/tools/importexport/dbimport/backends/django/__init__.py", line 122, in import_data_dj
    if os.path.isdir(in_path):
  File "/home/werner/.pyenv/versions/3.7.6/lib/python3.7/genericpath.py", line 42, in isdir
    st = os.stat(s)
TypeError: stat: path should be string, bytes, os.PathLike or integer, not NoneType

@sphuber
Copy link
Contributor

sphuber commented Apr 8, 2020

The archive is apparently corrupt. I have attached a fixed version. It is in .zip format but you can import it just as normally with verdi import
graph1.zip

I will make a PR to fix the corrupt archive in the repo, thanks for the report

@hongyi-zhao
Copy link
Author

Thanks, this one can be imported successfully.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants