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

Profile setdefault to set default backup #6462

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/aiida/cmdline/utils/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from contextlib import contextmanager

from click_spinner import spinner
from packaging.version import Version
from wrapt import decorator

from . import echo
Expand Down Expand Up @@ -239,13 +240,17 @@
return wrapped(*args, **kwargs)


def deprecated_command(message):
def deprecated_command(message: str, version: str = '3.0.0'):
"""Function decorator that will mark a click command as deprecated when invoked.

:param message: The message that should be printed with the deprecation warning.
:param version: Specifies the version for which the command will be removed. Any string is valid that is accepted by
:class:`packaging.version.Version`.

Example::

@click.command()
@deprecated_command('This command has been deprecated in AiiDA v1.0, please use 'foo' instead.)
@deprecated_command('This command has been deprecated, please use 'foo' instead.' version='1.0')
def mycommand():
pass
"""
Expand All @@ -259,7 +264,15 @@

template = templates.env.get_template('deprecated.tpl')
width = 80
echo.echo(template.render(msg=wrap(message, width - 4), width=width))
from packaging.version import InvalidVersion

try:
version_object = Version(version)
except (TypeError, InvalidVersion) as exception:
raise ValueError(f'`{version}` is not a valid value for `version`') from exception

Check warning on line 272 in src/aiida/cmdline/utils/decorators.py

View check run for this annotation

Codecov / codecov/patch

src/aiida/cmdline/utils/decorators.py#L271-L272

Added lines #L271 - L272 were not covered by tests

extended_message = f'{message} (this will be removed in v{version_object.major}.{version_object.minor})'
echo.echo(template.render(msg=wrap(extended_message, width - 4), width=width))

return wrapped(*args, **kwargs)

Expand Down