Skip to content

Commit 610292f

Browse files
grievejiafacebook-github-bot
authored andcommitted
Implement pyre statistics (9/9) -- putting it together
Reviewed By: dkgi Differential Revision: D30415364 fbshipit-source-id: cf7275e8c7922446e5dad169b56224a3f9e78079
1 parent 1ac85f0 commit 610292f

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

client/command_arguments.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,5 +122,6 @@ class RageArguments:
122122
@dataclass(frozen=True)
123123
class StatisticsArguments:
124124
filter_paths: List[str] = field(default_factory=list)
125+
log_identifier: Optional[str] = None
125126
log_results: bool = False
126127
print_aggregates: bool = False

client/commands/v2/statistics.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55

66
import dataclasses
77
import itertools
8+
import json
89
import logging
10+
import time
911
from pathlib import Path
10-
from typing import Any, Callable, Dict, Mapping, Iterable, Optional, Sequence, Union
12+
from typing import Any, Callable, Dict, Mapping, Iterable, Optional, Union
1113

1214
import libcst as cst
1315

@@ -17,6 +19,7 @@
1719
configuration as configuration_module,
1820
statistics_collectors as collectors,
1921
statistics,
22+
log,
2023
)
2124
from . import remote_logging
2225

@@ -133,7 +136,7 @@ class StatisticsData:
133136
strict: Dict[str, Any] = dataclasses.field(default_factory=dict)
134137

135138

136-
def collect_statistics(sources: Sequence[Path], strict_default: bool) -> StatisticsData:
139+
def collect_statistics(sources: Iterable[Path], strict_default: bool) -> StatisticsData:
137140
modules: Dict[Path, cst.Module] = {}
138141
for path in sources:
139142
module = parse_path_to_module(path)
@@ -227,7 +230,29 @@ def run_statistics(
227230
configuration: configuration_module.Configuration,
228231
statistics_arguments: command_arguments.StatisticsArguments,
229232
) -> commands.ExitCode:
230-
LOG.warning("Coming soon...")
233+
data = collect_statistics(
234+
find_paths_to_parse(find_roots(configuration, statistics_arguments)),
235+
strict_default=configuration.strict,
236+
)
237+
238+
if statistics_arguments.print_aggregates:
239+
aggregated_data = aggregate_statistics(data)
240+
log.stdout.write(json.dumps(dataclasses.asdict(aggregated_data), indent=4))
241+
else:
242+
log.stdout.write(json.dumps(dataclasses.asdict(data), indent=4))
243+
if statistics_arguments.log_results:
244+
logger = configuration.logger
245+
if logger is None:
246+
LOG.warning("Skip remote logging since no logger is specified.")
247+
else:
248+
log_identifier = statistics_arguments.log_identifier
249+
run_id = (
250+
log_identifier
251+
if log_identifier is not None
252+
else str(time.time_ns())
253+
)
254+
log_to_remote(logger, run_id, dataclasses.asdict(data))
255+
231256
return commands.ExitCode.SUCCESS
232257

233258

client/pyre.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,8 +1369,7 @@ def start(
13691369

13701370

13711371
@pyre.command()
1372-
# TODO[T60916205]: Rename this argument, it doesn't make sense anymore
1373-
@click.argument("filter_paths", type=filesystem.exists, nargs=-1)
1372+
@click.argument("filter_paths", type=str, nargs=-1)
13741373
@click.option(
13751374
"--log-results",
13761375
is_flag=True,
@@ -1401,6 +1400,7 @@ def statistics(
14011400
configuration,
14021401
command_arguments.StatisticsArguments(
14031402
filter_paths=list(filter_paths),
1403+
log_identifier=command_argument.log_identifier,
14041404
log_results=log_results,
14051405
print_aggregates=print_aggregates,
14061406
),

0 commit comments

Comments
 (0)