Source code for pyretis.bin.pyretisclean
#!/usr/bin/env python3
# Copyright (c) 2026, PyRETIS Development Team.
# Distributed under the LGPLv2.1+ License. See LICENSE for more info.
"""pyretisclean - Remove the artifacts of a PyRETIS run.
This is the implementation behind ``pyretis clean``. It deletes the
output a PyRETIS run leaves in a directory (logs, ``out.toml`` /
``out.rst``, restart files, the ``NNN`` ensemble directories, ``report``,
byte-code caches, ...), so an example or run directory can be reset to its
committed inputs. A per-directory ``clean.toml`` extends or overrides the
built-in defaults; see :mod:`pyretis.inout.clean`.
usage: pyretis clean [-h] [--dry-run] [directory]
"""
# pylint: disable=invalid-name
import argparse
from pyretis.info import PROGRAM_NAME
from pyretis.inout.clean import clean_directory
[docs]
def entry_point(): # pragma: no cover
"""Entry point for ``pyretis clean``."""
parser = argparse.ArgumentParser(
description=f'{PROGRAM_NAME}: remove the artifacts of a run.'
)
parser.add_argument(
'directory',
nargs='?',
default='.',
help='Directory to clean (default: the current directory).',
)
parser.add_argument(
'-n', '--dry-run',
action='store_true',
help='Only list what would be removed; delete nothing.',
)
args = parser.parse_args()
removed = clean_directory(args.directory, dry_run=args.dry_run)
if not removed:
print('Nothing to clean.')
return
prefix = 'Would remove' if args.dry_run else 'Removed'
for path in removed:
print(f'{prefix}: {path}')
print(f'{prefix} {len(removed)} item(s).')
if __name__ == '__main__': # pragma: no cover
entry_point()