3434from nodescraper .models import TaskResult
3535from nodescraper .utils import get_exception_details
3636
37+ from .analyzer_args import PackageAnalyzerArgs
3738from .packagedata import PackageDataModel
3839
3940
40- class PackageCollector (InBandDataCollector [PackageDataModel , None ]):
41+ class PackageCollector (InBandDataCollector [PackageDataModel , PackageAnalyzerArgs ]):
4142 """Collecting Package information from the system"""
4243
4344 DATA_MODEL = PackageDataModel
@@ -181,9 +182,34 @@ def _handle_command_failure(self, command_artifact: CommandArtifact):
181182 self .result .message = "Failed to run Package Manager command"
182183 self .result .status = ExecutionStatus .EXECUTION_FAILURE
183184
184- def collect_data (self , args = None ) -> tuple [TaskResult , Optional [PackageDataModel ]]:
185+ def _filter_rocm_packages (self , packages : dict [str , str ], rocm_pattern : str ) -> dict [str , str ]:
186+ """Filter ROCm-related packages from a package dictionary.
187+
188+ This method searches package names for ROCm-related patterns and returns
189+ only the matching packages.
190+
191+ Args:
192+ packages (dict[str, str]): Dictionary with package names as keys and versions as values.
193+ rocm_pattern (str): Regex pattern to match ROCm-related package names.
194+
195+ Returns:
196+ dict[str, str]: Filtered dictionary containing only ROCm-related packages.
197+ """
198+ rocm_packages = {}
199+ pattern = re .compile (rocm_pattern , re .IGNORECASE )
200+ for package_name , version in packages .items ():
201+ if pattern .search (package_name ):
202+ rocm_packages [package_name ] = version
203+ return rocm_packages
204+
205+ def collect_data (
206+ self , args : Optional [PackageAnalyzerArgs ] = None
207+ ) -> tuple [TaskResult , Optional [PackageDataModel ]]:
185208 """Collect package information from the system.
186209
210+ Args:
211+ args (Optional[PackageAnalyzerArgs]): Optional arguments containing ROCm regex pattern.
212+
187213 Returns:
188214 tuple[TaskResult, Optional[PackageDataModel]]: tuple containing the task result and a PackageDataModel instance
189215 with the collected package information, or None if there was an error.
@@ -205,8 +231,36 @@ def collect_data(self, args=None) -> tuple[TaskResult, Optional[PackageDataModel
205231 self .result .message = "Unsupported OS"
206232 self .result .status = ExecutionStatus .NOT_RAN
207233 return self .result , None
234+
235+ # Filter and log ROCm packages if on Linux and rocm_regex is provided
236+ if self .system_info .os_family == OSFamily .LINUX and packages :
237+ # Get ROCm pattern from args if provided
238+ rocm_pattern = args .rocm_regex if args else None
239+ if rocm_pattern :
240+ self .logger .info ("Using rocm_pattern: %s" , rocm_pattern )
241+ rocm_packages = self ._filter_rocm_packages (packages , rocm_pattern )
242+ if rocm_packages :
243+ self .result .message = (
244+ f"Found { len (rocm_packages )} ROCm-related packages installed"
245+ )
246+ self .result .status = ExecutionStatus .OK
247+ self ._log_event (
248+ category = EventCategory .OS ,
249+ description = f"Found { len (rocm_packages )} ROCm-related packages installed" ,
250+ priority = EventPriority .INFO ,
251+ data = {"rocm_packages" : sorted (rocm_packages .keys ())},
252+ )
253+ else :
254+ self .logger .info ("No rocm_regex provided, skipping ROCm package filtering" )
255+
256+ # Extract rocm_regex and enable_rocm_regex from args if provided
257+ rocm_regex = args .rocm_regex if (args and args .rocm_regex ) else ""
258+ enable_rocm_regex = getattr (args , "enable_rocm_regex" , False ) if args else False
259+
208260 try :
209- package_model = PackageDataModel (version_info = packages )
261+ package_model = PackageDataModel (
262+ version_info = packages , rocm_regex = rocm_regex , enable_rocm_regex = enable_rocm_regex
263+ )
210264 except ValidationError as val_err :
211265 self ._log_event (
212266 category = EventCategory .RUNTIME ,
0 commit comments