Skip to content

Commit

Permalink
chore: fix pylint message consider-using-any-or-all (#881)
Browse files Browse the repository at this point in the history
Signed-off-by: Jens Troeger <[email protected]>
  • Loading branch information
jenstroeger authored Oct 2, 2024
1 parent 94504d4 commit 6b9742d
Show file tree
Hide file tree
Showing 15 changed files with 16 additions and 65 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ ignore_missing_imports = true
fail-under = 10.0
suggestion-mode = true # Remove this setting when pylint v4 is released.
load-plugins = [
"pylint.extensions.for_any_all",
]
disable = [
"fixme",
Expand All @@ -230,7 +231,6 @@ disable = [
"too-many-public-methods",
"too-many-return-statements",
"too-many-statements",
"too-many-try-statements",
"duplicate-code",
]

Expand Down
6 changes: 1 addition & 5 deletions src/macaron/slsa_analyzer/build_tool/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ def is_detected(self, repo_path: str) -> bool:
bool
True if this build tool is detected, else False.
"""
for file in self.build_configs:
if file_exists(repo_path, file):
return True

return False
return any(file_exists(repo_path, file) for file in self.build_configs)

def prepare_config_files(self, wrapper_path: str, build_dir: str) -> bool:
"""Make necessary preparations for using this build tool.
Expand Down
6 changes: 1 addition & 5 deletions src/macaron/slsa_analyzer/build_tool/go.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ def is_detected(self, repo_path: str) -> bool:
True if this build tool is detected, else False.
"""
go_config_files = self.build_configs + self.entry_conf
for file in go_config_files:
if file_exists(repo_path, file):
return True

return False
return any(file_exists(repo_path, file) for file in go_config_files)

def prepare_config_files(self, wrapper_path: str, build_dir: str) -> bool:
"""Prepare the necessary wrapper files for running the build.
Expand Down
6 changes: 1 addition & 5 deletions src/macaron/slsa_analyzer/build_tool/gradle.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,7 @@ def is_detected(self, repo_path: str) -> bool:
True if this build tool is detected, else False.
"""
gradle_config_files = self.build_configs + self.entry_conf
for file in gradle_config_files:
if file_exists(repo_path, file):
return True

return False
return any(file_exists(repo_path, file) for file in gradle_config_files)

def prepare_config_files(self, wrapper_path: str, build_dir: str) -> bool:
"""Prepare the necessary wrapper files for running the build.
Expand Down
6 changes: 1 addition & 5 deletions src/macaron/slsa_analyzer/build_tool/maven.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,7 @@ def is_detected(self, repo_path: str) -> bool:
)
return False
maven_config_files = self.build_configs
for file in maven_config_files:
if file_exists(repo_path, file):
return True

return False
return any(file_exists(repo_path, file) for file in maven_config_files)

def prepare_config_files(self, wrapper_path: str, build_dir: str) -> bool:
"""Prepare the necessary wrapper files for running the build.
Expand Down
6 changes: 1 addition & 5 deletions src/macaron/slsa_analyzer/build_tool/npm.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,7 @@ def is_detected(self, repo_path: str) -> bool:
# cases like .npmrc existing but not package-lock.json and whether
# they would still count as "detected"
npm_config_files = self.build_configs + self.package_lock + self.entry_conf
for file in npm_config_files:
if file_exists(repo_path, file):
return True

return False
return any(file_exists(repo_path, file) for file in npm_config_files)

def prepare_config_files(self, wrapper_path: str, build_dir: str) -> bool:
"""Prepare the necessary wrapper files for running the build.
Expand Down
5 changes: 1 addition & 4 deletions src/macaron/slsa_analyzer/build_tool/pip.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@ def is_detected(self, repo_path: str) -> bool:
bool
True if this build tool is detected, else False.
"""
for file in self.build_configs:
if file_exists(repo_path, file):
return True
return False
return any(file_exists(repo_path, file) for file in self.build_configs)

def prepare_config_files(self, wrapper_path: str, build_dir: str) -> bool:
"""Prepare the necessary wrapper files for running the build.
Expand Down
6 changes: 1 addition & 5 deletions src/macaron/slsa_analyzer/build_tool/yarn.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,7 @@ def is_detected(self, repo_path: str) -> bool:
# cases like .yarnrc existing but not package-lock.json and whether
# they would still count as "detected"
yarn_config_files = self.build_configs + self.package_lock + self.entry_conf
for file in yarn_config_files:
if file_exists(repo_path, file):
return True

return False
return any(file_exists(repo_path, file) for file in yarn_config_files)

def prepare_config_files(self, wrapper_path: str, build_dir: str) -> bool:
"""Prepare the necessary wrapper files for running the build.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,7 @@ def is_detected(self, build_tool: BaseBuildTool) -> bool:
if not self.enabled:
return False
compatible_build_tool_classes = [Maven, Gradle]
for build_tool_class in compatible_build_tool_classes:
if isinstance(build_tool, build_tool_class):
return True
return False
return any(isinstance(build_tool, build_tool_class) for build_tool_class in compatible_build_tool_classes)

def construct_maven_repository_path(
self,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023 - 2023, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2023 - 2024, Oracle and/or its affiliates. All rights reserved.
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/.

"""The module provides abstractions for the Maven Central package registry."""
Expand Down Expand Up @@ -100,10 +100,7 @@ def is_detected(self, build_tool: BaseBuildTool) -> bool:
based on the given build tool.
"""
compatible_build_tool_classes = [Maven, Gradle]
for build_tool_class in compatible_build_tool_classes:
if isinstance(build_tool, build_tool_class):
return True
return False
return any(isinstance(build_tool, build_tool_class) for build_tool_class in compatible_build_tool_classes)

def find_publish_timestamp(self, group_id: str, artifact_id: str, version: str | None = None) -> datetime:
"""Make a search request to Maven Central to find the publishing timestamp of an artifact.
Expand Down
5 changes: 1 addition & 4 deletions src/macaron/slsa_analyzer/package_registry/npm_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,7 @@ def is_detected(self, build_tool: BaseBuildTool) -> bool:
logger.debug("Support for the npm registry is disabled.")
return False
compatible_build_tool_classes = [NPM, Yarn]
for build_tool_class in compatible_build_tool_classes:
if isinstance(build_tool, build_tool_class):
return True
return False
return any(isinstance(build_tool, build_tool_class) for build_tool_class in compatible_build_tool_classes)

def download_attestation_payload(self, url: str, download_path: str) -> bool:
"""Download the npm attestation from npm registry.
Expand Down
5 changes: 1 addition & 4 deletions src/macaron/slsa_analyzer/package_registry/pypi_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,7 @@ def is_detected(self, build_tool: BaseBuildTool) -> bool:
based on the given build tool.
"""
compatible_build_tool_classes = [Pip, Poetry]
for build_tool_class in compatible_build_tool_classes:
if isinstance(build_tool, build_tool_class):
return True
return False
return any(isinstance(build_tool, build_tool_class) for build_tool_class in compatible_build_tool_classes)

def download_package_json(self, url: str) -> dict:
"""Download the package JSON metadata from pypi registry.
Expand Down
5 changes: 1 addition & 4 deletions src/macaron/slsa_analyzer/provenance/intoto/v01/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,4 @@ def is_valid_digest_set(digest: dict[str, JsonType]) -> TypeGuard[dict[str, str]
``True`` if the digest set is valid according to the spec, in which case its type
is narrowed to a ``dict[str, str]``; ``False`` otherwise.
"""
for key in digest:
if not isinstance(digest[key], str):
return False
return True
return all(isinstance(digest[key], str) for key in digest)
5 changes: 1 addition & 4 deletions src/macaron/slsa_analyzer/provenance/intoto/v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,7 @@ def is_valid_digest_set(digest: JsonType) -> bool:
"""
if not isinstance(digest, dict):
return False
for key in digest:
if not isinstance(digest[key], str):
return False
return True
return all(isinstance(digest[key], str) for key in digest)


def _validate_property(
Expand Down
6 changes: 1 addition & 5 deletions src/macaron/slsa_analyzer/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,7 @@ def _validate_eval_reqs(eval_reqs: list[Any]) -> bool:
bool
True if all evaluated requirements are valid, else False.
"""
for req in eval_reqs:
if not isinstance(req, ReqName):
return False

return True
return all(isinstance(req, ReqName) for req in eval_reqs)

@staticmethod
def _validate_check_id_format(check_id: Any) -> bool:
Expand Down

0 comments on commit 6b9742d

Please sign in to comment.