Cleanup pylint errors in mainline_modules_sdks*.py

Bug: 218685706
Test: atest --host mainline_modules_sdks_test
      packages/modules/common/build/mainline_modules_sdks.sh
      pyformat -s 4 --force_quote_type double -i build/mainline_modules_sdks*.py
      /usr/bin/pylint --rcfile $ANDROID_BUILD_TOP/tools/repohooks/tools/pylintrc build/mainline_modules_sdks*.py
Change-Id: I5ba3da7dcde6d44b1855b41bac8eb80e0f3a593c
This commit is contained in:
Paul Duffin
2022-03-16 14:43:01 +00:00
parent 4404571a65
commit 4f192a156b
2 changed files with 23 additions and 26 deletions

View File

@@ -73,7 +73,7 @@ class SoongConfigBoilerplateInserter(FileTransformation):
configModuleTypePrefix: str configModuleTypePrefix: str
def apply(self, producer, path): def apply(self, producer, path):
with open(path, "r+") as file: with open(path, "r+", encoding="utf8") as file:
self._apply_transformation(producer, file) self._apply_transformation(producer, file)
def _apply_transformation(self, producer, file): def _apply_transformation(self, producer, file):
@@ -246,12 +246,13 @@ class SnapshotBuilder:
# This MUST be identical to the TARGET_BUILD_VARIANT used to build # This MUST be identical to the TARGET_BUILD_VARIANT used to build
# the corresponding APEXes otherwise it could result in different # the corresponding APEXes otherwise it could result in different
# hidden API flags, see http://b/202398851#comment29 for more info. # hidden API flags, see http://b/202398851#comment29 for more info.
targetBuildVariant = os.environ.get("TARGET_BUILD_VARIANT", "user") target_build_variant = os.environ.get("TARGET_BUILD_VARIANT",
"user")
cmd = [ cmd = [
"build/soong/soong_ui.bash", "build/soong/soong_ui.bash",
"--make-mode", "--make-mode",
"--soong-only", "--soong-only",
f"TARGET_BUILD_VARIANT={targetBuildVariant}", f"TARGET_BUILD_VARIANT={target_build_variant}",
"TARGET_PRODUCT=mainline_sdk", "TARGET_PRODUCT=mainline_sdk",
"MODULE_BUILD_FROM_SOURCE=true", "MODULE_BUILD_FROM_SOURCE=true",
"out/soong/apex/depsinfo/new-allowed-deps.txt.check", "out/soong/apex/depsinfo/new-allowed-deps.txt.check",
@@ -335,20 +336,17 @@ class BuildRelease:
return self.ordinal <= other.ordinal return self.ordinal <= other.ordinal
def create_no_dist_snapshot(build_release: BuildRelease, def create_no_dist_snapshot(_: BuildRelease, __: "SdkDistProducer",
producer: "SdkDistProducer",
modules: List["MainlineModule"]): modules: List["MainlineModule"]):
"""A place holder dist snapshot creation function that does nothing.""" """A place holder dist snapshot creation function that does nothing."""
print(f"create_no_dist_snapshot for modules {[m.apex for m in modules]}") print(f"create_no_dist_snapshot for modules {[m.apex for m in modules]}")
return
def create_sdk_snapshots_in_Soong(build_release: BuildRelease, def create_sdk_snapshots_in_soong(build_release: BuildRelease,
producer: "SdkDistProducer", producer: "SdkDistProducer",
modules: List["MainlineModule"]): modules: List["MainlineModule"]):
"""Builds sdks and populates the dist.""" """Builds sdks and populates the dist."""
producer.produce_dist_for_build_release(build_release, modules) producer.produce_dist_for_build_release(build_release, modules)
return
def reuse_latest_sdk_snapshots(build_release: BuildRelease, def reuse_latest_sdk_snapshots(build_release: BuildRelease,
@@ -356,7 +354,6 @@ def reuse_latest_sdk_snapshots(build_release: BuildRelease,
modules: List["MainlineModule"]): modules: List["MainlineModule"]):
"""Copies the snapshots from the latest build.""" """Copies the snapshots from the latest build."""
producer.populate_dist(build_release, build_release.sdk_versions, modules) producer.populate_dist(build_release, build_release.sdk_versions, modules)
return
Q = BuildRelease( Q = BuildRelease(
@@ -372,12 +369,12 @@ R = BuildRelease(
S = BuildRelease( S = BuildRelease(
name="S", name="S",
# Generate a snapshot for S using Soong. # Generate a snapshot for S using Soong.
creator=create_sdk_snapshots_in_Soong, creator=create_sdk_snapshots_in_soong,
) )
Tiramisu = BuildRelease( Tiramisu = BuildRelease(
name="Tiramisu", name="Tiramisu",
# Generate a snapshot for Tiramisu using Soong. # Generate a snapshot for Tiramisu using Soong.
creator=create_sdk_snapshots_in_Soong, creator=create_sdk_snapshots_in_soong,
) )
# Insert additional BuildRelease definitions for following releases here, # Insert additional BuildRelease definitions for following releases here,
@@ -388,7 +385,7 @@ Tiramisu = BuildRelease(
# before LEGACY_BUILD_RELEASE. # before LEGACY_BUILD_RELEASE.
LATEST = BuildRelease( LATEST = BuildRelease(
name="latest", name="latest",
creator=create_sdk_snapshots_in_Soong, creator=create_sdk_snapshots_in_soong,
# There are no build release specific environment variables to pass to # There are no build release specific environment variables to pass to
# Soong. # Soong.
soong_env={}, soong_env={},
@@ -744,8 +741,8 @@ def filter_modules(modules):
if target_build_apps: if target_build_apps:
target_build_apps = target_build_apps.split() target_build_apps = target_build_apps.split()
return [m for m in modules if m.apex in target_build_apps] return [m for m in modules if m.apex in target_build_apps]
else:
return modules return modules
def main(): def main():

View File

@@ -14,12 +14,12 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
"""Unit tests for mainline_modules_sdks.py.""" """Unit tests for mainline_modules_sdks.py."""
import dataclasses
from pathlib import Path from pathlib import Path
import os import os
import tempfile import tempfile
import unittest import unittest
import zipfile import zipfile
from unittest import mock
import mainline_modules_sdks as mm import mainline_modules_sdks as mm
@@ -127,7 +127,7 @@ class TestProduceDist(unittest.TestCase):
sorted(files)) sorted(files))
def pathToTestData(relative_path): def path_to_test_data(relative_path):
"""Construct a path to a test data file. """Construct a path to a test data file.
The relative_path is relative to the location of this file. The relative_path is relative to the location of this file.
@@ -147,8 +147,8 @@ def pathToTestData(relative_path):
return os.path.join(this_file_without_ext + "_data", relative_path) return os.path.join(this_file_without_ext + "_data", relative_path)
def readTestData(relative_path): def read_test_data(relative_path):
with open(pathToTestData(relative_path), "r") as f: with open(path_to_test_data(relative_path), "r", encoding="utf8") as f:
return f.read() return f.read()
@@ -156,19 +156,19 @@ class TestSoongConfigBoilerplateInserter(unittest.TestCase):
def apply_transformations(self, src, transformations, expected): def apply_transformations(self, src, transformations, expected):
producer = mm.SdkDistProducer( producer = mm.SdkDistProducer(
subprocess_runner=None, subprocess_runner=mock.Mock(mm.SubprocessRunner),
snapshot_builder=None, snapshot_builder=mock.Mock(mm.SnapshotBuilder),
script=self._testMethodName, script=self._testMethodName,
) )
with tempfile.TemporaryDirectory() as tmp_dir: with tempfile.TemporaryDirectory() as tmp_dir:
path = os.path.join(tmp_dir, "Android.bp") path = os.path.join(tmp_dir, "Android.bp")
with open(path, "w") as f: with open(path, "w", encoding="utf8") as f:
f.write(src) f.write(src)
mm.apply_transformations(producer, tmp_dir, transformations) mm.apply_transformations(producer, tmp_dir, transformations)
with open(path, "r") as f: with open(path, "r", encoding="utf8") as f:
result = f.read() result = f.read()
self.maxDiff = None self.maxDiff = None
@@ -181,9 +181,9 @@ class TestSoongConfigBoilerplateInserter(unittest.TestCase):
that the correct Soong config module types and variables are used and that the correct Soong config module types and variables are used and
that it imports the definitions from the correct location. that it imports the definitions from the correct location.
""" """
src = readTestData("ipsec_Android.bp.input") src = read_test_data("ipsec_Android.bp.input")
expected = readTestData("ipsec_Android.bp.expected") expected = read_test_data("ipsec_Android.bp.expected")
module = MAINLINE_MODULES_BY_APEX["com.android.ipsec"] module = MAINLINE_MODULES_BY_APEX["com.android.ipsec"]
transformations = module.transformations() transformations = module.transformations()
@@ -197,9 +197,9 @@ class TestSoongConfigBoilerplateInserter(unittest.TestCase):
common mainline modules. This checks that the ART specific Soong config common mainline modules. This checks that the ART specific Soong config
module types, variable and imports are used. module types, variable and imports are used.
""" """
src = readTestData("art_Android.bp.input") src = read_test_data("art_Android.bp.input")
expected = readTestData("art_Android.bp.expected") expected = read_test_data("art_Android.bp.expected")
module = MAINLINE_MODULES_BY_APEX["com.android.art"] module = MAINLINE_MODULES_BY_APEX["com.android.art"]
transformations = module.transformations() transformations = module.transformations()