Skip to content

Commit

Permalink
add choice
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjsewell committed Jan 21, 2022
1 parent 0cfae86 commit 8e4b70a
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
6 changes: 3 additions & 3 deletions aiida/cmdline/commands/cmd_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
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 import MIGRATIONS, downgrade_config, get_config_path
from aiida.manage.configuration.settings import DEFAULT_CONFIG_INDENT_SIZE


Expand Down Expand Up @@ -197,12 +197,12 @@ def verdi_config_caching(disabled):


@verdi_config.command('downgrade')
@click.argument('version', type=int)
@click.argument('version', type=click.Choice({str(m.down_revision) for m in MIGRATIONS}))
def verdi_config_downgrade(version):
"""Print a configuration, downgraded to a specific version."""
path = 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)
downgrade_config(config, int(version))
path.write_text(json.dumps(config, indent=DEFAULT_CONFIG_INDENT_SIZE), encoding='utf8')
echo.echo_success('Downgraded')
1 change: 1 addition & 0 deletions aiida/manage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
'ConfigValidationError',
'DEFAULT_DBINFO',
'DeliveryFailed',
'MIGRATIONS',
'OLDEST_COMPATIBLE_CONFIG_VERSION',
'Option',
'Postgres',
Expand Down
1 change: 1 addition & 0 deletions aiida/manage/configuration/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
'CURRENT_CONFIG_VERSION',
'Config',
'ConfigValidationError',
'MIGRATIONS',
'OLDEST_COMPATIBLE_CONFIG_VERSION',
'Option',
'Profile',
Expand Down
1 change: 1 addition & 0 deletions aiida/manage/configuration/migrations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

__all__ = (
'CURRENT_CONFIG_VERSION',
'MIGRATIONS',
'OLDEST_COMPATIBLE_CONFIG_VERSION',
'check_and_migrate_config',
'config_needs_migrating',
Expand Down
8 changes: 4 additions & 4 deletions aiida/manage/configuration/migrations/migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

__all__ = (
'CURRENT_CONFIG_VERSION', 'OLDEST_COMPATIBLE_CONFIG_VERSION', 'get_current_version', 'check_and_migrate_config',
'config_needs_migrating', 'upgrade_config', 'downgrade_config'
'config_needs_migrating', 'upgrade_config', 'downgrade_config', 'MIGRATIONS'
)

ConfigType = Dict[str, Any]
Expand Down Expand Up @@ -196,7 +196,7 @@ def downgrade(self, config: ConfigType) -> None:
config['options'][current] = config['options'].pop(new)


_MIGRATIONS = (Initial, AddProfileUuid, SimplifyDefaultProfiles, AddMessageBroker, SimplifyOptions)
MIGRATIONS = (Initial, AddProfileUuid, SimplifyDefaultProfiles, AddMessageBroker, SimplifyOptions)


def get_current_version(config):
Expand All @@ -218,7 +218,7 @@ def get_oldest_compatible_version(config):
def upgrade_config(
config: ConfigType,
target: int = CURRENT_CONFIG_VERSION,
migrations: Iterable[Type[SingleMigration]] = _MIGRATIONS
migrations: Iterable[Type[SingleMigration]] = MIGRATIONS
) -> ConfigType:
"""Run the registered configuration migrations up to the target version.
Expand Down Expand Up @@ -246,7 +246,7 @@ def upgrade_config(


def downgrade_config(
config: ConfigType, target: int, migrations: Iterable[Type[SingleMigration]] = _MIGRATIONS
config: ConfigType, target: int, migrations: Iterable[Type[SingleMigration]] = MIGRATIONS
) -> ConfigType:
"""Run the registered configuration migrations down to the target version.
Expand Down

0 comments on commit 8e4b70a

Please sign in to comment.