Exemplo n.º 1
0
def upgrade_legacy_config_file(project_dir):
    has_ini_config = check_if_ini_config_file_exists(project_dir)
    has_json_config = check_if_json_config_file_exists(project_dir)

    if not has_ini_config:
        raise ValueError("No `populus.ini` file found")
    elif has_json_config:
        raise ValueError(
            "Cannot upgrade config file if there is already an existing "
            "`populus.json` file.")

    ini_config_file_path = get_ini_config_file_path(project_dir)
    json_config_file_path = get_json_config_file_path(project_dir)

    upgraded_config = translate_legacy_ini_config_file(ini_config_file_path)

    default_config = load_default_config(version=V1)
    config = deep_merge_dicts(default_config, upgraded_config)

    write_config(
        project_dir,
        config,
        json_config_file_path,
    )
    backup_ini_config_file_path = "{0}.bak".format(ini_config_file_path)
    shutil.move(ini_config_file_path, backup_ini_config_file_path)
    return backup_ini_config_file_path
Exemplo n.º 2
0
    def load_config(self):
        self._config_cache = None

        if self.config_file_path is None:
            has_ini_config = check_if_ini_config_file_exists()
            has_json_config = check_if_json_config_file_exists()

            if has_ini_config and has_json_config:
                raise DeprecationWarning(
                    "Found both `populus.ini` and `populus.json` config files. "
                    "Please migrate you `populus.ini` file settings into the "
                    "`populus.json` file and remove the `populus.ini` file")
            elif has_ini_config:
                warnings.warn(
                    DeprecationWarning(
                        "The `populus.ini` configuration format has been "
                        "deprecated.  You must upgrade your configuration file to "
                        "the new `populus.json` format."))
                path_to_load = get_default_config_path()
            elif has_json_config:
                path_to_load = get_json_config_file_path()
            else:
                path_to_load = get_default_config_path()
        else:
            path_to_load = self.config_file_path

        self._project_config = _load_config(path_to_load)
        self._project_config_schema = load_config_schema()
Exemplo n.º 3
0
def init(ctx):
    """
    Generate project layout with an example contract.
    """
    project = ctx.obj['PROJECT']

    has_json_config = check_if_json_config_file_exists(project.project_dir)

    if has_json_config:
        click.echo(
            "Found existing `populus.json` file.  Not writing default config."
        )
    else:
        json_config_file_path = get_json_config_file_path(project.project_dir)
        default_config = load_default_config()
        write_config(
            project.project_dir,
            default_config,
            json_config_file_path,
        )
        click.echo(
            "Wrote default populus configuration to `./{0}`.".format(
                os.path.relpath(json_config_file_path, project.project_dir),
            )
        )

    project.load_config()

    if ensure_path_exists(project.contracts_dir):
        click.echo(
            "Created Directory: ./{0}".format(
                os.path.relpath(project.contracts_dir)
            )
        )

    example_contract_path = os.path.join(project.contracts_dir, 'Greeter.sol')
    if not os.path.exists(example_contract_path):
        with open(example_contract_path, 'w') as example_contract_file:
            example_contract_file.write(GREETER_FILE_CONTENTS)
        click.echo("Created Example Contract: ./{0}".format(
            os.path.relpath(example_contract_path)
        ))

    tests_dir = os.path.join(project.project_dir, 'tests')
    if ensure_path_exists(tests_dir):
        click.echo("Created Directory: ./{0}".format(os.path.relpath(tests_dir)))

    example_tests_path = os.path.join(tests_dir, 'test_greeter.py')
    if not os.path.exists(example_tests_path):
        with open(example_tests_path, 'w') as example_tests_file:
            example_tests_file.write(TEST_FILE_CONTENTS)
        click.echo("Created Example Tests: ./{0}".format(
            os.path.relpath(example_tests_path)
        ))
Exemplo n.º 4
0
    def load_config(self):
        self._config_cache = None

        if self.config_file_path is None:
            has_json_config = check_if_json_config_file_exists()

            if has_json_config:
                path_to_load = get_json_config_file_path()
            else:
                path_to_load = get_default_config_path()
        else:
            path_to_load = self.config_file_path

        self._project_config = _load_config(path_to_load)

        config_version = self._project_config['version']
        self._project_config_schema = load_config_schema(config_version)
Exemplo n.º 5
0
def init_cmd(ctx):
    """
    Generate project layout with an example contract.
    """
    logger = logging.getLogger('populus.cli.init_cmd')
    project = ctx.obj['PROJECT']

    has_json_config = check_if_json_config_file_exists(project.project_dir)

    if has_json_config:
        logger.info(
            "Found existing `populus.json` file.  Not writing default config.")
    else:
        json_config_file_path = get_json_config_file_path(project.project_dir)
        default_config = load_default_config()
        write_config(
            project.project_dir,
            default_config,
            json_config_file_path,
        )
        logger.info("Wrote default populus configuration to `./{0}`.".format(
            os.path.relpath(json_config_file_path, project.project_dir), ))

    project.load_config()

    if ensure_path_exists(project.contracts_source_dir):
        logger.info("Created Directory: ./{0}".format(
            os.path.relpath(project.contracts_source_dir)))

    example_contract_path = os.path.join(project.contracts_source_dir,
                                         'Greeter.sol')
    if not os.path.exists(example_contract_path):
        shutil.copy(GREETER_SOURCE_PATH, example_contract_path)
        logger.info("Created Example Contract: ./{0}".format(
            os.path.relpath(example_contract_path)))

    tests_dir = os.path.join(project.project_dir, 'tests')
    if ensure_path_exists(tests_dir):
        logger.info("Created Directory: ./{0}".format(
            os.path.relpath(tests_dir)))

    example_tests_path = os.path.join(tests_dir, 'test_greeter.py')
    if not os.path.exists(example_tests_path):
        shutil.copy(GREETER_TEST_PATH, example_tests_path)
        logger.info("Created Example Tests: ./{0}".format(
            os.path.relpath(example_tests_path)))