-
Notifications
You must be signed in to change notification settings - Fork 217
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
👌 IMPROVE: Configuration migrations #5319
Changes from 7 commits
c5e9d19
5f64ec1
e483a74
fc142ab
16a2703
e3c059a
532f315
bd3a6df
baea9ce
4b797eb
2f9fa47
0cfae86
8e4b70a
e34d041
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,13 +8,17 @@ | |
# For further information please visit http://www.aiida.net # | ||
########################################################################### | ||
"""`verdi config` command.""" | ||
import json | ||
from pathlib import Path | ||
import textwrap | ||
|
||
import click | ||
|
||
from aiida.cmdline.commands.cmd_verdi import verdi | ||
from aiida.cmdline.params import arguments | ||
from aiida.cmdline.utils import echo | ||
from aiida.manage.configuration import downgrade_config, get_config_path | ||
from aiida.manage.configuration.settings import DEFAULT_CONFIG_INDENT_SIZE | ||
|
||
|
||
@verdi.group('config') | ||
|
@@ -190,3 +194,31 @@ def verdi_config_caching(disabled): | |
echo.echo(identifier) | ||
elif disabled: | ||
echo.echo(identifier) | ||
|
||
|
||
@verdi_config.command('downgrade') | ||
@click.argument('version', type=int) | ||
@click.option( | ||
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. Correct me if I am wrong, but I don't think you answered my question yet why we need the option to specify an arbitrary input and output file. Since this is user facing it should simply always operate on the currently configured config file. I would suggest to remove this additional complexity since I don't think it is needed for now and you don't have tests for it. 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. removed |
||
'-p', | ||
'--path', | ||
default=None, | ||
type=click.Path(exists=True, path_type=Path), | ||
help='Path to the config file (default to current configuration).' | ||
) | ||
@click.option( | ||
'-o', | ||
'--output', | ||
default=None, | ||
type=click.Path(exists=True, path_type=Path), | ||
help='Path to write to (default to input path).' | ||
) | ||
def verdi_config_downgrade(version, path, output): | ||
"""Print a configuration, downgraded to a specific version.""" | ||
path = path or Path(get_config_path()) | ||
echo.echo_report(f'Downgrading configuration to v{version}: {path}') | ||
config = json.loads(path.read_text(encoding='utf8')) | ||
downgrade_config(config, version) | ||
output = Path(output or path) | ||
output.parent.mkdir(parents=True, exist_ok=True) | ||
output.write_text(json.dumps(config, indent=DEFAULT_CONFIG_INDENT_SIZE), encoding='utf8') | ||
echo.echo_success(f'Downgraded configuration written to: {output}') |
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.
Can we make this a
type=click.Choice
and get the available numbers dynamically from the available migrations? That would make it a lot better from a UI perspective.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.
done