def config_migrate(state: State): """Migrate esque config to current version. If the user's esque config file is from a previous version, migrate it to the current version. A backup of the original config file is created with the same name and the extension .bak""" new_path, backup = migration.migrate(config_path()) click.echo(f"Your config has been migrated and is now at {new_path}. A backup has been created at {backup}.")
def test_backup(config_version: int, load_config: config_loader): old_conf, old_yaml = load_config(config_version) _, backup = migrate(Path(old_conf)) if config_version == CURRENT_VERSION: assert backup is None, "No need for backup" return assert backup.read_text() == old_yaml
def migration_wrapper(config_path: Path): nonlocal new_conf_path, backup new_conf_path, backup = migrate(config_path) return new_conf_path, backup
def test_schema(config_version: int, load_config: config_loader): old_conf, _ = load_config(config_version) new_path, _ = migrate(Path(old_conf)) validate_esque_config(yaml.safe_load(new_path.read_text()))
def config(config_version: int, load_config: config_loader): old_conf, _ = load_config(config_version) new_path, _ = migrate(Path(old_conf)) Config.set_instance(Config()) return Config.get_instance()