Beispiel #1
0
def get_options_from_config(argv):
    parser = argparse.ArgumentParser()
    _add_config_file_options(parser)
    args, _ = parser.parse_known_args(argv)

    # Create the config if they'd like us to do that.
    if args.create_config:
        args = get_options_from_argparse(argv)
        # yeah yeah, not really yaml, but this is a good way to validate the
        # config as we write it.
        generate_options = GenerateOptions.from_yaml(vars(args))
        with io.open(args.config_filename, 'w') as config_file:
            yaml.safe_dump(
                generate_options.to_yaml(),
                config_file,
                # We want unicode
                encoding=None,
                default_flow_style=False,
            )

    if not os.path.exists(args.config_filename):
        print('No config file found!  Create one with --create-config.')
        exit(1)

    with io.open(args.config_filename) as config_file:
        return GenerateOptions.from_yaml(yaml.load(config_file))
Beispiel #2
0
def get_options_from_config(argv):
    parser = argparse.ArgumentParser()
    _add_config_file_options(parser)
    args, _ = parser.parse_known_args(argv)

    # Create the config if they'd like us to do that.
    if args.create_config:
        args = get_options_from_argparse(argv)
        # yeah yeah, not really yaml, but this is a good way to validate the
        # config as we write it.
        generate_options = GenerateOptions.from_yaml(vars(args))
        with io.open(args.config_filename, 'w') as config_file:
            yaml.safe_dump(
                generate_options.to_yaml(),
                config_file,
                # We want unicode
                encoding=None,
                default_flow_style=False,
            )

    if not os.path.exists(args.config_filename):
        print('No config file found!  Create one with --create-config.')
        exit(1)

    with io.open(args.config_filename) as config_file:
        return GenerateOptions.from_yaml(yaml.load(config_file))
def test_minimal_defaults():
    ret = GenerateOptions.from_yaml({'repo': './', 'database': 'database.db'})
    assert ret == GenerateOptions(
        skip_default_metrics=False,
        metric_package_names=[],
        repo='./',
        database='database.db',
    )
def test_minimal_defaults():
    ret = GenerateOptions.from_yaml({'repo': './', 'database': 'database.db'})
    assert ret == GenerateOptions(
        skip_default_metrics=False,
        metric_package_names=[],
        repo='./',
        repo_type='git',
        database='database.db',
        exclude=re.compile(b'^$'),
    )
def test_none_for_tempdir_allowed():
    ret = GenerateOptions.from_yaml({
        'repo': 'repo',
        'database': 'database.db',
    })
    assert ret == GenerateOptions(
        skip_default_metrics=False,
        metric_package_names=[],
        repo='repo',
        database='database.db',
    )
def test_with_all_options_specified():
    ret = GenerateOptions.from_yaml({
        'skip_default_metrics': True,
        'metric_package_names': ['my_package'],
        'repo': '.',
        'database': 'database.db',
    })
    assert ret == GenerateOptions(
        skip_default_metrics=True,
        metric_package_names=['my_package'],
        repo='.',
        database='database.db',
    )
Beispiel #7
0
def data():
    metric_names = set(widget_metrics)
    diff = flask.request.form['diff'].encode('UTF-8')

    metric_config = GenerateOptions.from_yaml(
        yaml.load(io.open('generate_config.yaml').read()), )
    parsers = get_metric_parsers_from_args(
        metric_config.metric_package_names,
        skip_defaults=False,
    )
    metrics = get_metrics(diff, parsers)
    metrics = [
        metric for metric in metrics
        if metric.value and metric.name in metric_names
    ]

    commit_deltas = sorted([
        CommitDeltaPresenter.from_data(
            metric.name,
            DeltaPresenter('javascript:;', metric.value),
        ) for metric in metrics
    ])
    return simplejson.dumps({
        'metrics':
        render_template('widget.mako', commit_deltas=commit_deltas)
    })
def data():
    metric_names = set(widget_metrics)
    diff = flask.request.form['diff'].encode('UTF-8')

    metric_config = GenerateOptions.from_yaml(
        yaml.load(io.open('generate_config.yaml').read()),
    )
    parsers = get_metric_parsers_from_args(
        metric_config.metric_package_names, skip_defaults=False,
    )
    metrics = get_metrics(diff, parsers)
    metrics = [
        metric for metric in metrics
        if metric.value and metric.name in metric_names
    ]

    commit_deltas = sorted([
        CommitDeltaPresenter.from_data(
            metric.name, DeltaPresenter('javascript:;', metric.value),
        )
        for metric in metrics
    ])
    return simplejson.dumps({
        'metrics': render_template('widget.mako', commit_deltas=commit_deltas)
    })
Beispiel #9
0
def get_options_from_config(config_filename):
    if not os.path.exists(config_filename):
        print('config file not found {}'.format(config_filename))
        exit(1)

    with io.open(config_filename) as config_file:
        return GenerateOptions.from_yaml(yaml.load(config_file))
Beispiel #10
0
def get_options_from_config(config_filename: str) -> GenerateOptions:
    if not os.path.exists(config_filename):
        print(f'config file not found {config_filename}')
        exit(1)

    with open(config_filename) as config_file:
        return GenerateOptions.from_yaml(yaml.load(config_file))
Beispiel #11
0
def data():
    metric_names = frozenset(flask.g.config.widget_metrics)
    diff = flask.request.form['diff'].encode('UTF-8')

    metric_config = GenerateOptions.from_yaml(
        yaml.load(io.open('generate_config.yaml').read()),
    )
    parsers = get_metric_parsers_from_args(
        metric_config.metric_package_names, skip_defaults=False,
    )
    metrics = get_metrics(Commit.blank, diff, parsers, metric_config.exclude)
    metrics = [
        metric for metric in metrics
        if metric.value and metric.name in metric_names
    ]

    commit_deltas = sorted([
        CommitDelta.from_data(
            metric.name, Delta('javascript:;', metric.value),
            color_overrides=flask.g.config.color_overrides,
        )
        for metric in metrics
    ])
    return json.dumps({
        'metrics': render_template('widget.mako', commit_deltas=commit_deltas),
    })
Beispiel #12
0
def get_options_from_config(config_filename):
    if not os.path.exists(config_filename):
        print('config file not found {}'.format(config_filename))
        exit(1)

    with io.open(config_filename) as config_file:
        return GenerateOptions.from_yaml(yaml.load(config_file))
Beispiel #13
0
def data() -> str:
    metric_names = frozenset(flask.g.config.widget_metrics)
    diff = flask.request.form['diff'].encode('UTF-8')

    metric_config = GenerateOptions.from_yaml(
        yaml.load(open('generate_config.yaml').read()),
    )
    parsers = get_metric_parsers_from_args(
        metric_config.metric_package_names, skip_defaults=False,
    )
    metrics = get_metrics(BLANK_COMMIT, diff, parsers, metric_config.exclude)
    metrics = tuple(
        metric for metric in metrics
        if metric.value and metric.name in metric_names
    )

    commit_deltas = sorted(
        CommitDelta.from_data(
            metric.name, Delta('javascript:;', metric.value),
            color_overrides=flask.g.config.color_overrides,
        )
        for metric in metrics
    )
    return json.dumps({
        'metrics': render_template('widget.mako', commit_deltas=commit_deltas),
    })
def test_to_yaml_defaults():
    ret = GenerateOptions(
        skip_default_metrics=False,
        metric_package_names=[],
        repo='.',
        database='database.db',
    ).to_yaml()
    assert ret == {'repo': '.', 'database': 'database.db'}
def test_with_all_options_specified():
    ret = GenerateOptions.from_yaml({
        'skip_default_metrics': True,
        'metric_package_names': ['my_package'],
        'repo': '.',
        'repo_type': 'git',
        'database': 'database.db',
        'exclude': '^vendor/',
    })
    assert ret == GenerateOptions(
        skip_default_metrics=True,
        metric_package_names=['my_package'],
        repo='.',
        repo_type='git',
        database='database.db',
        exclude=re.compile(b'^vendor/'),
    )
def test_to_yaml_all_specified():
    ret = GenerateOptions(
        skip_default_metrics=True,
        tempdir_location='/foo/tmp',
        metric_package_names=['my_package'],
        repo='.',
        database='database.db',
    ).to_yaml()

    assert ret == {
        'skip_default_metrics': True,
        'tempdir_location': '/foo/tmp',
        'metric_package_names': ['my_package'],
        'repo': '.',
        'database': 'database.db',
    }
def test_with_all_options_specified():
    ret = GenerateOptions.from_yaml(
        {
            "skip_default_metrics": True,
            "tempdir_location": "/foo/tmp",
            "metric_package_names": ["my_package"],
            "repo": ".",
            "database": "database.db",
        }
    )
    assert ret == GenerateOptions(
        skip_default_metrics=True,
        tempdir_location="/foo/tmp",
        metric_package_names=["my_package"],
        repo=".",
        database="database.db",
    )
Beispiel #18
0
def test_get_options_from_config_create_config(tempdir_factory):
    tmpdir = tempdir_factory.get()
    with cwd(tmpdir):
        ret = get_options_from_config([
            '--create-config',
            '.',
            'database.db',
        ])

        assert os.path.exists('generate_config.yaml')
        assert yaml.load(io.open('generate_config.yaml').read()) == {
            'repo': '.',
            'database': 'database.db',
        }

        assert ret == GenerateOptions(
            skip_default_metrics=False,
            metric_package_names=[],
            repo='.',
            database='database.db',
        )
def test_empty_config_invalid():
    with pytest.raises(jsonschema.exceptions.ValidationError):
        GenerateOptions.from_yaml({})
def test_empty_config_invalid():
    with pytest.raises(cfgv.ValidationError):
        GenerateOptions.from_yaml({})
def test_empty_config_invalid():
    with pytest.raises(jsonschema.exceptions.ValidationError):
        GenerateOptions.from_yaml({})
def test_none_for_tempdir_allowed():
    ret = GenerateOptions.from_yaml({"repo": "repo", "database": "database.db", "tempdir_location": None})
    assert ret == GenerateOptions(
        skip_default_metrics=False, tempdir_location=None, metric_package_names=[], repo="repo", database="database.db"
    )
def test_minimal_defaults():
    ret = GenerateOptions.from_yaml({"repo": "./", "database": "database.db"})
    assert ret == GenerateOptions(
        skip_default_metrics=False, tempdir_location=None, metric_package_names=[], repo="./", database="database.db"
    )
def test_empty_config_invalid():
    with pytest.raises(cfgv.ValidationError):
        GenerateOptions.from_yaml({})