Apply pylint to build/soong/bloaty

1. Run black --line-length 80 -S build/soong/bloaty
to fix formatting
2. Annotate # pylint: disable=import-error to skip checks for imports.
The imports are provided by Soong during m <target>

Test: m bloaty_merger_test
Test: pylint --rcfile tools/repohooks/tools/pylintrc
build/soong/bloaty/bloaty_merger.py
build/soong/bloaty/bloaty_merger_test.py
Bug: 195738175

Change-Id: I4579a80203de41d48992424f264dd1cdbafc854c
This commit is contained in:
Spandan Das 2021-08-18 17:46:46 +00:00
parent eaf5e1b3ec
commit 16c2b8c3d3
2 changed files with 78 additions and 72 deletions

View file

@ -24,12 +24,14 @@ import argparse
import csv
import gzip
# pylint: disable=import-error
import ninja_rsp
import file_sections_pb2
BLOATY_EXTENSION = ".bloaty.csv"
def parse_csv(path):
"""Parses a Bloaty-generated CSV file into a protobuf.
@ -43,7 +45,7 @@ def parse_csv(path):
with open(path, newline='') as csv_file:
file_proto = file_sections_pb2.File()
if path.endswith(BLOATY_EXTENSION):
file_proto.path = path[:-len(BLOATY_EXTENSION)]
file_proto.path = path[: -len(BLOATY_EXTENSION)]
section_reader = csv.DictReader(csv_file)
for row in section_reader:
section = file_proto.sections.add()
@ -52,14 +54,15 @@ def parse_csv(path):
section.file_size = int(row["filesize"])
return file_proto
def create_file_size_metrics(input_list, output_proto):
"""Creates a FileSizeMetrics proto from a list of CSV files.
Args:
input_list: The path to the file which contains the list of CSV files. Each
filepath is separated by a space.
output_proto: The path for the output protobuf. It will be compressed using
gzip.
input_list: The path to the file which contains the list of CSV files.
Each filepath is separated by a space.
output_proto: The path for the output protobuf. It will be compressed
using gzip.
"""
metrics = file_sections_pb2.FileSizeMetrics()
reader = ninja_rsp.NinjaRspFileReader(input_list)
@ -70,6 +73,7 @@ def create_file_size_metrics(input_list, output_proto):
with gzip.open(output_proto, "wb") as output:
output.write(metrics.SerializeToString())
def main():
parser = argparse.ArgumentParser()
parser.add_argument("input_list_file", help="List of bloaty csv files.")
@ -77,5 +81,6 @@ def main():
args = parser.parse_args()
create_file_size_metrics(args.input_list_file, args.output_proto)
if __name__ == '__main__':
main()

View file

@ -14,6 +14,7 @@
import gzip
import unittest
# pylint: disable=import-error
from pyfakefs import fake_filesystem_unittest
import bloaty_merger