-
Notifications
You must be signed in to change notification settings - Fork 210
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
CLI
: add option --clean-workdir
to verdi node delete
#6756
Open
khsrali
wants to merge
4
commits into
aiidateam:main
Choose a base branch
from
khsrali:verdi/node-delete--cleanworkdir
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+353
−49
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -328,9 +328,14 @@ def extras(nodes, keys, fmt, identifier, raw): | |
@click.argument('identifier', nargs=-1, metavar='NODES') | ||
@options.DRY_RUN() | ||
@options.FORCE() | ||
@click.option( | ||
'--clean-workdir', | ||
is_flag=True, | ||
help='Also clean the remote work directory, if applicable.', | ||
) | ||
@options.graph_traversal_rules(GraphTraversalRules.DELETE.value) | ||
@with_dbenv() | ||
def node_delete(identifier, dry_run, force, **traversal_rules): | ||
def node_delete(identifier, dry_run, force, clean_workdir, **traversal_rules): | ||
"""Delete nodes from the provenance graph. | ||
|
||
This will not only delete the nodes explicitly provided via the command line, but will also include | ||
|
@@ -356,10 +361,62 @@ def _dry_run_callback(pks): | |
echo.echo_info('The nodes with the following pks would be deleted: ' + ' '.join(map(str, pks))) | ||
return not click.confirm('Shall I continue?', abort=True) | ||
|
||
_, was_deleted = delete_nodes(pks, dry_run=dry_run or _dry_run_callback, **traversal_rules) | ||
def _perform_delete(): | ||
_, was_deleted = delete_nodes(pks, dry_run=dry_run or _dry_run_callback, **traversal_rules) | ||
if was_deleted: | ||
echo.echo_success('Finished deletion.') | ||
|
||
if clean_workdir: | ||
from aiida.manage import get_manager | ||
from aiida.orm import CalcJobNode, QueryBuilder | ||
from aiida.orm.utils.remote import clean_mapping_remote_paths, get_calcjob_remote_paths | ||
from aiida.tools.graph.graph_traversers import get_nodes_delete | ||
|
||
backend = get_manager().get_backend() | ||
# For here we ignore missing nodes will be raised via func:``delete_nodes`` in the next block | ||
pks_set_to_delete = get_nodes_delete( | ||
pks, get_links=False, missing_callback=lambda missing_pks: None, backend=backend, **traversal_rules | ||
)['nodes'] | ||
|
||
qb = QueryBuilder() | ||
qb.append(CalcJobNode, filters={'id': {'in': pks_set_to_delete}}, project='id') | ||
calcjobs_pks = [result[0] for result in qb.all()] | ||
|
||
if not calcjobs_pks: | ||
echo.echo_report('--clean-workdir ignored. No CalcJobNode associated with the given node, found.') | ||
Comment on lines
+385
to
+386
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you can do early return here to avoid nested if..else. |
||
_perform_delete() | ||
return | ||
|
||
path_mapping = get_calcjob_remote_paths( | ||
calcjobs_pks, | ||
only_not_cleaned=True, | ||
) | ||
|
||
if not path_mapping: | ||
echo.echo_report('--clean-workdir ignored. CalcJobNode work directories are already cleaned.') | ||
_perform_delete() | ||
return | ||
|
||
descendant_pks = [remote_folder.pk for paths in path_mapping.values() for remote_folder in paths] | ||
|
||
if not force and not dry_run: | ||
echo.echo_warning( | ||
f'YOU ARE ABOUT TO CLEAN {len(descendant_pks)} REMOTE DIRECTORIES! ' 'THIS CANNOT BE UNDONE!' | ||
) | ||
echo.echo_info( | ||
'Remote directories of nodes with the following pks would be cleaned: ' | ||
+ ' '.join(map(str, descendant_pks)) | ||
) | ||
click.confirm('Shall I continue?', abort=True) | ||
|
||
if dry_run: | ||
echo.echo_report( | ||
'Remote folders of these node are marked for deletion: ' + ' '.join(map(str, descendant_pks)) | ||
) | ||
else: | ||
clean_mapping_remote_paths(path_mapping) | ||
|
||
if was_deleted: | ||
echo.echo_success('Finished deletion.') | ||
_perform_delete() | ||
|
||
|
||
@verdi_node.command('rehash') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put default to True is backward incompatible and potentially danger.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, that's exactly what this command does :-)
It define it as a flag with
is_flag=True
so the default value isFalse
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, right. Then could you write
default=False
to be more explicit?