Integrate with android-components gradle build script

This commit is contained in:
Michael Droettboom 2018-10-23 16:20:34 -04:00
Родитель 4f8d4051c8
Коммит 7899e4a961
7 изменённых файлов: 23 добавлений и 21 удалений

Просмотреть файл

Просмотреть файл

@ -79,7 +79,7 @@ def output_kotlin(metrics, output_dir):
('denominator', ''),
('time_unit', 'millisecond'),
('objects', None),
('extra_keys', {}),
('allowed_extra_keys', []),
]
for category_key, category_val in metrics.items():

Просмотреть файл

@ -30,14 +30,14 @@ class Metric:
super().__init_subclass__(**kwargs)
@classmethod
def make_metric(cls, category_name, name, metric_info, validated=False):
def make_metric(cls, category, name, metric_info, validated=False):
"""
Given a metric_info dictionary from metrics.yaml, return a metric
instance.
"""
metric_type = metric_info['type']
return cls.metric_types[metric_type](
category_name=category_name,
category=category,
name=name,
_validated=validated,
**metric_info
@ -49,14 +49,14 @@ class Metric:
"""
d = dataclasses.asdict(self)
del d['name']
del d['category_name']
del d['category']
return d
def __post_init__(self, expires_after_build_date, _validated):
if not _validated:
schema = parser._get_metrics_schema()
data = {
self.category_name: {
self.category: {
self.name: self.serialize()
}
}
@ -75,7 +75,7 @@ class Metric:
type: str
# Metadata
category_name: str
category: str
name: str
bugs: List[Union[int, str]]
description: str
@ -179,3 +179,7 @@ class Event(Metric):
objects: List[str] = field(default_factory=list)
extra_keys: Dict[str, str] = field(default_factory=dict)
@property
def allowed_extra_keys(self):
return list(self.extra_keys.keys())

Просмотреть файл

@ -17,13 +17,11 @@ object {{ category_name|Camelize }} {
/**
* {{ metric.description|wordwrap(wrapstring='\n * ') }}
*/
val {{ metric.name|Camelize }}: {{ metric.type|Camelize }}MetricType by lazy {
val {{ metric.name|camelize }}: {{ metric.type|Camelize }}MetricType by lazy {
{{ metric.type|Camelize }}MetricType(
{% for arg_name, default in extra_args -%}
{% if metric[arg_name] is defined and metric[arg_name] != default -%}
{{ arg_name|camelize }}={{ metric[arg_name]|kotlin }},
{% endif %}
{%- endfor -%}
{% for arg_name, default in extra_args if metric[arg_name] is defined and metric[arg_name] != default -%}
{{ arg_name|camelize }}={{ metric[arg_name]|kotlin }}{{ "," if not loop.last }}
{% endfor -%}
)
};
{% endfor %}

Просмотреть файл

@ -52,7 +52,7 @@ setup(
description="Parser tools for Mozilla's glean telemetry",
entry_points={
'console_scripts': [
'glean_parser=glean_parser.cli:main',
'glean_parser=glean_parser.__main__:main',
],
},
install_requires=requirements,

Просмотреть файл

@ -10,7 +10,7 @@ from pathlib import Path
from click.testing import CliRunner
from glean_parser import cli
from glean_parser import __main__
ROOT = Path(__file__).parent
@ -19,7 +19,7 @@ ROOT = Path(__file__).parent
def test_basic_help():
"""Test the CLI."""
runner = CliRunner()
help_result = runner.invoke(cli.main, ['--help'])
help_result = runner.invoke(__main__.main, ['--help'])
assert help_result.exit_code == 0
assert '--help Show this message and exit.' in help_result.output
@ -28,7 +28,7 @@ def test_translate(tmpdir):
"""Test the 'translate' command."""
runner = CliRunner()
result = runner.invoke(
cli.main,
__main__.main,
[
'translate',
str(ROOT / 'data' / 'core.yaml'),
@ -49,7 +49,7 @@ def test_translate_errors(tmpdir):
"""Test the 'translate' command."""
runner = CliRunner()
result = runner.invoke(
cli.main,
__main__.main,
[
'translate',
str(ROOT / 'data' / 'invalid.yaml'),
@ -67,7 +67,7 @@ def test_translate_invalid_format(tmpdir):
"""Test passing an invalid format to the 'translate' command."""
runner = CliRunner()
result = runner.invoke(
cli.main,
__main__.main,
[
'translate',
str(ROOT / 'data' / 'core.yaml'),

Просмотреть файл

@ -35,7 +35,7 @@ def test_enforcement():
with pytest.raises(jsonschema.exceptions.ValidationError):
metrics.Boolean(
type='boolean',
category_name='category',
category='category',
name='metric',
bugs=[42],
description=42,
@ -49,7 +49,7 @@ def test_isodate():
"""
m = metrics.Boolean(
type='boolean',
category_name='category',
category='category',
name='metric',
bugs=[42],
expires_after_build_date='2018-06-10',
@ -61,7 +61,7 @@ def test_isodate():
with pytest.raises(ValueError):
m = metrics.Boolean(
type='boolean',
category_name='category',
category='category',
name='metric',
bugs=[42],
expires_after_build_date='foo',