From 93e7a233f6e6c5137af01282a5c5bd1053592735 Mon Sep 17 00:00:00 2001 From: Charles Coggins Date: Fri, 3 Nov 2023 18:02:25 -0500 Subject: [PATCH] refactor: adhere to preview 'ruff' findings --- src/phylum/ci/ci_base.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/phylum/ci/ci_base.py b/src/phylum/ci/ci_base.py index 0cc1f649..7bbb0b71 100644 --- a/src/phylum/ci/ci_base.py +++ b/src/phylum/ci/ci_base.py @@ -8,6 +8,7 @@ from argparse import Namespace from collections import OrderedDict from functools import cached_property, lru_cache +from itertools import starmap import json import os from pathlib import Path @@ -114,8 +115,8 @@ def _find_potential_depfiles(self) -> None: msg = "Phylum `find-lockable-files` command failed" raise PhylumCalledProcessError(err, msg) from err lockable_files: dict = json.loads(result) - self._potential_manifests = [LockfileEntry(*entry) for entry in lockable_files.get("manifests", [])] - self._potential_lockfiles = [LockfileEntry(*entry) for entry in lockable_files.get("lockfiles", [])] + self._potential_manifests = list(starmap(LockfileEntry, lockable_files.get("manifests", []))) + self._potential_lockfiles = list(starmap(LockfileEntry, lockable_files.get("lockfiles", []))) @property def potential_manifests(self) -> LockfileEntries: @@ -141,7 +142,7 @@ def depfiles(self) -> Depfiles: # flatten the list of lists provided_arg_lockfiles = [LockfileEntry(path) for sub_list in arg_lockfiles for path in sub_list] LOG.debug("Dependency files provided as arguments: %s", provided_arg_lockfiles) - valid_depfiles = self.filter_depfiles(provided_arg_lockfiles) + valid_depfiles = self._filter_depfiles(provided_arg_lockfiles) if valid_depfiles: LOG.debug("Valid provided dependency files: %s", valid_depfiles) return valid_depfiles @@ -154,7 +155,7 @@ def depfiles(self) -> Depfiles: else: LOG.debug("Detected dependency files: %s", detected_depfiles) if detected_depfiles: - valid_depfiles = self.filter_depfiles(detected_depfiles) + valid_depfiles = self._filter_depfiles(detected_depfiles) if valid_depfiles: LOG.debug("Valid detected dependency files: %s", valid_depfiles) return valid_depfiles @@ -166,7 +167,7 @@ def depfiles(self) -> Depfiles: raise SystemExit(textwrap.dedent(msg)) @progress_spinner("Filtering dependency files") - def filter_depfiles(self, provided_depfiles: LockfileEntries) -> Depfiles: + def _filter_depfiles(self, provided_depfiles: LockfileEntries) -> Depfiles: """Filter potential dependency files and return the valid ones in sorted order.""" depfiles: Depfiles = [] for provided_depfile in provided_depfiles: @@ -541,9 +542,9 @@ def analyze(self) -> None: If the command was expected to succeed, please report this as a bug.""" raise PhylumCalledProcessError(err, textwrap.dedent(msg)) from err - self.parse_analysis_result(analysis_result) + self._parse_analysis_result(analysis_result) - def parse_analysis_result(self, analysis_result: str) -> None: + def _parse_analysis_result(self, analysis_result: str) -> None: """Parse the results of a Phylum analysis command output.""" analysis = JobPolicyEvalResult(**json.loads(analysis_result))