1- # Copyright (c) 2024 CRS4
1+ # Copyright (c) 2024-2025 CRS4
22#
33# Licensed under the Apache License, Version 2.0 (the "License");
44# you may not use this file except in compliance with the License.
@@ -369,6 +369,13 @@ def validate(ctx,
369369 report_layout = ValidationReportLayout (console , validation_settings ,
370370 profile_stats , None , profile_autodetected = autodetection )
371371
372+ # set target profile for the progress monitor
373+ severity_validation = Severity .get (validation_settings .get ("requirement_severity" ))
374+ target_profile = services .get_profile (profile ,
375+ validation_settings .get ("profiles_path" ),
376+ severity = severity_validation )
377+ report_layout .progress_monitor .target_validation_profile = target_profile
378+
372379 # Validate RO-Crate against the profile and get the validation result
373380 result : ValidationResult = None
374381 if output_format == "text" :
@@ -389,6 +396,15 @@ def validate(ctx,
389396 # store the cumulative validation result
390397 is_valid = is_valid and result .passed (LevelCollection .get (requirement_severity ).severity )
391398
399+ # Uncomment the following lines to debug the validation process
400+ # for c in profile_stats["checks"]:
401+ # logger.debug("Check: %s", c)
402+ # logger.debug("Failed checks: %r", profile_stats["failed_checks"])
403+ # logger.debug("Passed checks: %r", profile_stats["passed_checks"])
404+ # if c.identifier not in [_.identifier for _ in profile_stats["failed_checks"]] and \
405+ # c.identifier not in [_.identifier for _ in profile_stats["passed_checks"]]:
406+ # logger.debug("Skipped check : %s", c.identifier)
407+
392408 # Print the validation result
393409 if output_format == "text" and not output_file :
394410 if not result .passed ():
@@ -481,21 +497,23 @@ class ProgressMonitor(Subscriber):
481497 REQUIREMENT_VALIDATION = "Requirements"
482498 REQUIREMENT_CHECK_VALIDATION = "Requirements Checks"
483499
484- def __init__ (self , layout : ValidationReportLayout , stats : dict ):
500+ def __init__ (self , settings : dict , layout : ValidationReportLayout , stats : dict ):
485501 self .__progress = Progress (
486502 TextColumn ("[progress.description]{task.description}" ),
487503 BarColumn (),
488504 TextColumn ("{task.completed}/{task.total}" ),
489505 TimeElapsedColumn (),
490506 expand = True )
491507 self ._stats = stats
508+ self .settings = settings
492509 self .profile_validation = self .progress .add_task (
493510 self .PROFILE_VALIDATION , total = len (stats .get ("profiles" )))
494511 self .requirement_validation = self .progress .add_task (
495512 self .REQUIREMENT_VALIDATION , total = stats .get ("total_requirements" ))
496513 self .requirement_check_validation = self .progress .add_task (
497514 self .REQUIREMENT_CHECK_VALIDATION , total = stats .get ("total_checks" ))
498515 self .__layout = layout
516+ self ._target_validation_profile = None
499517 super ().__init__ ("ProgressMonitor" )
500518
501519 def start (self ):
@@ -504,6 +522,14 @@ def start(self):
504522 def stop (self ):
505523 self .progress .stop ()
506524
525+ @property
526+ def target_validation_profile (self ) -> Profile :
527+ return self ._target_validation_profile
528+
529+ @target_validation_profile .setter
530+ def target_validation_profile (self , profile : Profile ):
531+ self ._target_validation_profile = profile
532+
507533 @property
508534 def layout (self ) -> ValidationReportLayout :
509535 return self .__layout
@@ -521,7 +547,10 @@ def update(self, event: Event):
521547 elif event .event_type == EventType .REQUIREMENT_CHECK_VALIDATION_START :
522548 logger .debug ("Requirement check validation start" )
523549 elif event .event_type == EventType .REQUIREMENT_CHECK_VALIDATION_END :
524- if not event .requirement_check .requirement .hidden :
550+ target_profile = self .target_validation_profile
551+ if not event .requirement_check .requirement .hidden and \
552+ (not event .requirement_check .overridden
553+ or target_profile .identifier == event .requirement_check .requirement .profile .identifier ):
525554 self .progress .update (task_id = self .requirement_check_validation , advance = 1 )
526555 if event .validation_result is not None :
527556 if event .validation_result :
@@ -574,7 +603,7 @@ def validation_checks_progress(self):
574603 @property
575604 def progress_monitor (self ) -> ProgressMonitor :
576605 if not self .__progress_monitor :
577- self .__progress_monitor = ProgressMonitor (self , self .profile_stats )
606+ self .__progress_monitor = ProgressMonitor (self . validation_settings , self , self .profile_stats )
578607 return self .__progress_monitor
579608
580609 def live (self , update_callable : callable ) -> any :
@@ -810,6 +839,7 @@ def __compute_profile_stats__(validation_settings: dict):
810839 profile = services .get_profile (validation_settings .get ("profile_identifier" ),
811840 validation_settings .get ("profiles_path" ),
812841 severity = severity_validation )
842+ target_profile_identifier = profile .identifier
813843 # initialize the profiles list
814844 profiles = [profile ]
815845
@@ -827,6 +857,8 @@ def __compute_profile_stats__(validation_settings: dict):
827857 for severity in (Severity .REQUIRED , Severity .RECOMMENDED , Severity .OPTIONAL ):
828858 check_count_by_severity [severity ] = 0
829859
860+ checks = []
861+
830862 # Process the requirements and checks
831863 processed_requirements = []
832864 for profile in profiles :
@@ -843,11 +875,13 @@ def __compute_profile_stats__(validation_settings: dict):
843875 if severity < severity_validation :
844876 continue
845877 # count the checks
846- num_checks = len (
847- [_ for _ in requirement .get_checks_by_level (LevelCollection .get (severity .name ))
848- if not _ .overridden ])
878+ requirement_checks = [_ for _ in requirement .get_checks_by_level (LevelCollection .get (severity .name ))
879+ if not _ .overridden or
880+ _ .requirement .profile .identifier == target_profile_identifier ]
881+ num_checks = len (requirement_checks )
849882 check_count_by_severity [severity ] += num_checks
850883 requirement_checks_count += num_checks
884+ checks .extend (requirement_checks )
851885
852886 # count the requirements and checks
853887 if requirement_checks_count == 0 :
@@ -872,7 +906,9 @@ def __compute_profile_stats__(validation_settings: dict):
872906 "failed_requirements" : [],
873907 "failed_checks" : [],
874908 "passed_requirements" : [],
875- "passed_checks" : []
909+ "passed_checks" : [],
910+ "checks" : checks
911+
876912 }
877913 logger .debug (result )
878914 return result
0 commit comments