Skip to content

Commit

Permalink
fix: break indirect dep cycles / removed gc
Browse files Browse the repository at this point in the history
  • Loading branch information
dervoeti committed Nov 19, 2024
1 parent e39ea18 commit e5f14bd
Show file tree
Hide file tree
Showing 14 changed files with 952 additions and 255 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def check_format(self, file: File) -> tuple[bool, list[str], dict | list]:
return True, [], rows

def get_observations(
self, data: list[dict], branch: Optional[Branch]
self, data: list[dict]
) -> list[Observation]:
observations = []

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def get_type(cls) -> str:
raise NotImplementedError("get_type() must be overridden")

def get_observations(
self, data: Any, branch: Optional[Branch]
self, data: Any
) -> list[Observation]:
raise NotImplementedError("get_observations() must be overridden")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def check_format(self, file: File) -> tuple[bool, list[str], dict]:
return True, [], data

def get_observations(
self, data: dict, branch: Optional[Branch]
self, data: dict
) -> list[Observation]:
observations = []

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def check_format(self, file: File) -> tuple[bool, list[str], dict]:
return True, [], data

def get_observations(
self, data: dict, branch: Optional[Branch]
self, data: dict
) -> list[Observation]:
self.metadata = self._get_metadata(data)
sbom_data = None
Expand Down Expand Up @@ -239,9 +239,14 @@ def _create_observations( # pylint: disable=too-many-locals
# Traverse the dependency tree from each root component
# While doing that, accumulate all paths from each root to each leaf
def traverse(node, path):
# Avoid indirect cycles
if node in path:
return

print(f"Traversing {node} with path {path}")
dependency_paths[node].append(path)
for dep in dep_map.get(node, []):
if dep not in path: # Avoid cycles
if dep not in path: # Avoid direct cycles
traverse(dep, path + [dep])

for root in roots:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def check_connection(
return True, [], response.json()

def get_observations(
self, data: list[dict], branch: Optional[Branch]
self, data: list[dict]
) -> list[Observation]:
observations = []

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def check_format(self, file: File) -> tuple[bool, list[str], dict | list]:
return True, [], data

def get_observations(
self, data: list, branch: Optional[Branch]
self, data: list
) -> list[Observation]:
observations = []

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def check_format(self, file: File) -> tuple[bool, list[str], dict | list]:
return True, [], data

def get_observations(
self, data: list, branch: Optional[Branch]
self, data: list
) -> list[Observation]:
observations = []

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def check_format(self, file: File) -> tuple[bool, list[str], dict | list]:
return True, [], data

def get_observations(
self, data: list[dict], branch: Optional[Branch]
self, data: list[dict]
) -> list[Observation]:
observations = []

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def check_format(self, file: File) -> tuple[bool, list[str], dict]:
return True, [], data

def get_observations(
self, data: dict, branch: Optional[Branch]
self, data: dict
) -> list[Observation]:
observations: list[Observation] = []

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def check_format(self, file: File) -> tuple[bool, list[str], dict]:
return True, [], data

def get_observations(
self, data: dict, branch: Optional[Branch]
self, data: dict
) -> list[Observation]:
observations = []

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def check_format(self, import_data) -> tuple[bool, list[str], dict]:
return True, [], data

def get_observations(
self, data: dict, branch: Optional[Branch]
self, data: dict
) -> list[Observation]:
observations = []
for finding in data.get("data", {}).get("result"):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def check_format(self, file: File) -> tuple[bool, list[str], dict]:
return True, [], data

def get_observations(
self, data: dict, branch: Optional[Branch]
self, data: dict
) -> list[Observation]:
observations = []

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import gc
import os
from dataclasses import dataclass
from typing import Optional, Tuple
Expand Down Expand Up @@ -109,7 +108,7 @@ def file_upload_observations(
raise ValidationError("File format is not valid: " + " / ".join(errors))

imported_observations = parser_instance.get_observations(
data, file_upload_parameters.branch
data
)

filename = (
Expand Down Expand Up @@ -177,11 +176,6 @@ def file_upload_observations(
vulnerability_check.last_import_licenses_deleted = None
vulnerability_check.save()

del vulnerability_check
del import_parameters
del data
gc.collect()

return (
numbers_observations[0],
numbers_observations[1],
Expand Down Expand Up @@ -213,7 +207,7 @@ def api_import_observations(
)

imported_observations = parser_instance.get_observations(
data, api_import_parameters.branch
data
)

import_parameters = ImportParameters(
Expand Down Expand Up @@ -243,11 +237,6 @@ def api_import_observations(
},
)

del imported_observations
del import_parameters
del data
gc.collect()

return numbers[0], numbers[1], numbers[2]


Expand Down
Loading

0 comments on commit e5f14bd

Please sign in to comment.