Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix pylint message consider-using-any-or-all #881

Open
wants to merge 1 commit into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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)
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
Loading