Skip to content

Commit

Permalink
Archive: Automatically create nested output directories (#6361)
Browse files Browse the repository at this point in the history
Creating an archive, either through `verdi archive create` or through
the API `aiida.tools.archive.create_archive` would raise an exception if
the output path contained nested directories that do not yet exist.
These are now created automatically.
  • Loading branch information
sphuber authored Apr 28, 2024
1 parent 5460a04 commit 212f616
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/aiida/tools/archive/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,8 @@ def transform(d):

if filename.exists():
filename.unlink()

filename.parent.mkdir(parents=True, exist_ok=True)
shutil.move(tmp_filename, filename)

EXPORT_LOGGER.report('Archive created successfully')
Expand Down
8 changes: 8 additions & 0 deletions tests/cmdline/commands/test_archive_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ def test_create_force(run_cli_command, tmp_path):
run_cli_command(cmd_archive.create, options)


def test_create_file_nested_directory(run_cli_command, tmp_path):
"""Test that output files that contains nested directories are created automatically."""
filepath = tmp_path / 'some' / 'sub' / 'directory' / 'output.aiida'
options = [str(filepath)]
run_cli_command(cmd_archive.create, options)
assert filepath.exists()


@pytest.mark.usefixtures('aiida_profile_clean')
def test_create_all(run_cli_command, tmp_path, aiida_localhost):
"""Test that creating an archive for a set of various ORM entities works with the zip format."""
Expand Down

0 comments on commit 212f616

Please sign in to comment.