Esempio n. 1
0
File: v6.py Progetto: zutobg/populus
def upgrade_user_v6_to_v7(v6_user_config):
    """
    Upgrade a v6 config file to a v7 config file.
    """
    errors = get_validation_errors(v6_user_config, version=V6)
    if errors:
        raise ValueError(
            "Cannot upgrade invalid config.  Please ensure that your current "
            "configuration file is valid:\n\n{0}".format(
                format_errors(errors), ))

    v6_default = load_user_default_config(version=V6)
    v7_default = load_user_default_config(version=V7)

    v6_default_config = Config(v6_default)
    v6_default_config.unref()

    v7_default_config = Config(v7_default)
    v7_default_config.unref()

    if v6_user_config == v6_default_config:
        return v7_default_config

    # V7 just moved to user config, no change in keys
    upgraded_v6_user_config = copy.deepcopy(v6_user_config)
    upgraded_v6_user_config['version'] = V7

    return upgraded_v6_user_config
Esempio n. 2
0
def upgrade_user_v6_to_v7(v6_user_config):
    """
    Upgrade a v6 config file to a v7 config file.
    """
    errors = get_validation_errors(v6_user_config, version=V6)
    if errors:
        raise ValueError(
            "Cannot upgrade invalid config.  Please ensure that your current "
            "configuration file is valid:\n\n{0}".format(
                format_errors(errors),
            )
        )

    v6_default = load_user_default_config(version=V6)
    v7_default = load_user_default_config(version=V7)

    v6_default_config = Config(v6_default)
    v6_default_config.unref()

    v7_default_config = Config(v7_default)
    v7_default_config.unref()

    if v6_user_config == v6_default_config:
        return v7_default_config

    # V7 just moved to user config, no change in keys
    upgraded_v6_user_config = copy.deepcopy(v6_user_config)
    upgraded_v6_user_config['version'] = V7

    return upgraded_v6_user_config
Esempio n. 3
0
def test_upgrade_custom_key(project):
    legacy_config_file_path = get_legacy_json_config_file_path(
        project_dir=project.project_dir)
    shutil.copyfile(get_default_config_path(version=V3),
                    legacy_config_file_path)
    os.remove(project.config_file_path)

    legacy_key = 'compilation.import_remapping'
    legacy_value = ['import-path-from-legacy=contracts']
    upgraded_key = 'compilation.import_remappings'

    legacy_config = Config(load_config(legacy_config_file_path))
    legacy_config[legacy_key] = legacy_value
    write_config(legacy_config, legacy_config_file_path)

    logger = logging.getLogger("test.test_upgrade_custom_key")
    upgrade_configs(project.project_dir, logger, FIRST_USER_CONFIG_VERSION)

    upgraded_project = Project(
        project_dir=project.project_dir,
        user_config_file_path=project.user_config_file_path)

    assert upgraded_project.config.get(upgraded_key) == legacy_value
    assert upgraded_project.project_config.get(upgraded_key) == legacy_value

    default_user_config = Config(
        load_user_default_config(version=FIRST_USER_CONFIG_VERSION))
    assert upgraded_project.user_config.get(
        upgraded_key) == default_user_config.get(upgraded_key)
Esempio n. 4
0
def test_upgrade_to_user_config(project, from_legacy_version):

    shutil.copyfile(
        get_default_config_path(version=from_legacy_version),
        get_legacy_json_config_file_path(project_dir=project.project_dir))

    os.remove(project.config_file_path)

    logger = logging.getLogger("test.test_upgrade_to_user_config")
    upgrade_configs(project.project_dir, logger, FIRST_USER_CONFIG_VERSION)

    upgraded_project = Project(
        project_dir=project.project_dir,
        user_config_file_path=project.user_config_file_path)

    expected_user_config = Config(
        load_user_default_config(FIRST_USER_CONFIG_VERSION))
    expected_user_config.unref()

    expected_project_config = Config(
        load_default_config(FIRST_USER_CONFIG_VERSION))
    expected_project_config.unref()

    assert upgraded_project.legacy_config_path is None
    assert upgraded_project.config == expected_user_config
    assert upgraded_project.user_config == expected_user_config
    assert upgraded_project.project_config == expected_project_config
Esempio n. 5
0
def upgrade_user_v7_to_v8(v7_user_config):
    """
    Upgrade a v7 user config file to a v8 user config file.
    """
    errors = get_validation_errors(v7_user_config, version=V7)
    if errors:
        raise ValueError(
            "Cannot upgrade invalid config.  Please ensure that your current "
            "configuration file is valid:\n\n{0}".format(
                format_errors(errors),
            )
        )

    v7_default = load_user_default_config(version=V7)

    v7_default_config = Config(v7_default)

    if v7_user_config == v7_default_config:
        return {}

    # V8 just removes all of the `$ref` values from the config.
    upgraded_v7_user_config = Config(copy.deepcopy(v7_user_config))
    upgraded_v7_user_config.unref()
    upgraded_v7_user_config['version'] = V8

    return upgraded_v7_user_config
def test_upgrade_custom_key(project):
    legacy_config_file_path = get_legacy_json_config_file_path(project_dir=project.project_dir)
    shutil.copyfile(
        get_default_config_path(version=V3),
        legacy_config_file_path
    )

    legacy_key = 'compilation.import_remapping'
    legacy_value = ['import-path-from-legacy=contracts']
    upgraded_key = 'compilation.import_remappings'

    legacy_config = Config(load_config(legacy_config_file_path))
    legacy_config[legacy_key] = legacy_value
    write_config(legacy_config, legacy_config_file_path)

    logger = logging.getLogger("test.test_upgrade_custom_key")
    upgrade_configs(project.project_dir, logger, V8)

    upgraded_project = Project(
        project_dir=project.project_dir,
        user_config_file_path=project.user_config_file_path
    )

    assert upgraded_project.config.get(upgraded_key) == legacy_value
    assert upgraded_project.project_config.get(upgraded_key) == legacy_value

    default_user_config = Config(load_user_default_config(version=V8))
    assert upgraded_project.user_config.get(upgraded_key) == default_user_config.get(upgraded_key)
def test_upgrade_to_user_config(project, from_legacy_version):

    shutil.copyfile(
        get_default_config_path(version=from_legacy_version),
        get_legacy_json_config_file_path(project_dir=project.project_dir)
    )

    logger = logging.getLogger("test.test_upgrade_to_user_config")
    upgrade_configs(project.project_dir, logger, LATEST_VERSION)

    upgraded_project = Project(
        project_dir=project.project_dir,
        user_config_file_path=project.user_config_file_path
    )

    expected_user_config = Config(load_user_default_config(LATEST_VERSION))
    expected_user_config.unref()

    expected_project_config = Config(load_default_config(LATEST_VERSION))
    expected_project_config.unref()

    legacy_config_path = get_legacy_json_config_file_path(project.project_dir)
    assert not os.path.exists(legacy_config_path)

    assert upgraded_project.user_config == expected_user_config
    assert upgraded_project.project_config == expected_project_config
Esempio n. 8
0
def upgrade_user_v7_to_v8(v7_user_config):
    """
    Upgrade a v7 user config file to a v8 user config file.
    """
    errors = get_validation_errors(v7_user_config, version=V7)
    if errors:
        raise ValueError(
            "Cannot upgrade invalid config.  Please ensure that your current "
            "configuration file is valid:\n\n{0}".format(
                format_errors(errors), ))

    v7_default = load_user_default_config(version=V7)

    v7_default_config = Config(v7_default)

    if v7_user_config == v7_default_config:
        return {}

    # V8 just removes all of the `$ref` values from the config.
    upgraded_v7_user_config = Config(copy.deepcopy(v7_user_config))
    upgraded_v7_user_config.unref()
    upgraded_v7_user_config['version'] = V8

    return upgraded_v7_user_config
Esempio n. 9
0
def test_upgrade_to_user_config(project, from_legacy_version):

    shutil.copyfile(
        get_default_config_path(version=from_legacy_version),
        get_legacy_json_config_file_path(project_dir=project.project_dir))

    logger = logging.getLogger("test.test_upgrade_to_user_config")
    upgrade_configs(project.project_dir, logger, LATEST_VERSION)

    upgraded_project = Project(
        project_dir=project.project_dir,
        user_config_file_path=project.user_config_file_path)

    expected_user_config = Config(load_user_default_config(LATEST_VERSION))
    expected_user_config.unref()

    expected_project_config = Config(load_default_config(LATEST_VERSION))
    expected_project_config.unref()

    legacy_config_path = get_legacy_json_config_file_path(project.project_dir)
    assert not os.path.exists(legacy_config_path)

    assert upgraded_project.user_config == expected_user_config
    assert upgraded_project.project_config == expected_project_config
Esempio n. 10
0
def user_config_defaults():

    return Config(load_user_default_config())
Esempio n. 11
0
def user_config_defaults():
    return Config(load_user_default_config())