@@ -1495,37 +1495,40 @@ def has_single_resource(self):
14951495 """
14961496 return self .resource_count == 1
14971497
1498- def get_policy_index (self ):
1498+ def get_policies_dict (self ):
14991499 """
1500- Return the policy index for this project instance.
1500+ Load and return the policies from the following locations in that order:
15011501
1502- The policies are loaded from the following locations in that order:
1503- 1. the project local settings
1504- 2. the "policies.yml" file in the project input/ directory
1505- 3. the global app settings license policies
1502+ 1. project local settings (stored in the database)
1503+ 2. "policies.yml" file in the project ``input/`` directory
1504+ 3. global app settings policies, from SCANCODEIO_POLICIES_FILE setting
15061505 """
15071506 if policies_from_settings := self .get_env ("policies" ):
15081507 policies_dict = policies_from_settings
15091508 if isinstance (policies_from_settings , str ):
15101509 policies_dict = policies .load_policies_yaml (policies_from_settings )
1511- return policies . make_license_policy_index ( policies_dict )
1510+ return policies_dict
15121511
1513- elif policies_file := self .get_input_policies_file ():
1514- policies_dict = policies .load_policies_file (policies_file )
1515- return policies .make_license_policy_index (policies_dict )
1512+ elif project_input_policies_file := self .get_input_policies_file ():
1513+ return policies .load_policies_file (project_input_policies_file )
15161514
1517- else :
1518- return scanpipe_app .license_policies_index
1515+ return scanpipe_app .policies
1516+
1517+ def get_license_policy_index (self ):
1518+ """Return the policy license index for this project instance."""
1519+ if policies_dict := self .get_policies_dict ():
1520+ return policies .make_license_policy_index (policies_dict )
1521+ return {}
15191522
15201523 @cached_property
1521- def policy_index (self ):
1522- """Return the cached policy index for this project instance."""
1523- return self .get_policy_index ()
1524+ def license_policy_index (self ):
1525+ """Return the cached license policy index for this project instance."""
1526+ return self .get_license_policy_index ()
15241527
15251528 @property
1526- def policies_enabled (self ):
1527- """Return True if the policies are enabled for this project."""
1528- return bool (self .policy_index )
1529+ def license_policies_enabled (self ):
1530+ """Return True if the license policies are available for this project."""
1531+ return bool (self .license_policy_index )
15291532
15301533
15311534class GroupingQuerySetMixin :
@@ -2540,7 +2543,7 @@ def save(self, codebase=None, *args, **kwargs):
25402543 ``codebase`` is not used in this context but required for compatibility
25412544 with the commoncode.resource.Codebase class API.
25422545 """
2543- if self .policies_enabled :
2546+ if self .license_policies_enabled :
25442547 loaded_license_expression = getattr (self , "_loaded_license_expression" , "" )
25452548 license_expression = getattr (self , self .license_expression_field , "" )
25462549 if license_expression != loaded_license_expression :
@@ -2566,28 +2569,29 @@ def from_db(cls, db, field_names, values):
25662569 return new
25672570
25682571 @property
2569- def policy_index (self ):
2570- return self .project .policy_index
2572+ def license_policy_index (self ):
2573+ return self .project .license_policy_index
25712574
25722575 @cached_property
2573- def policies_enabled (self ):
2574- return self .project .policies_enabled
2576+ def license_policies_enabled (self ):
2577+ return self .project .license_policies_enabled
25752578
25762579 def compute_compliance_alert (self ):
25772580 """
25782581 Compute and return the compliance_alert value from the license policies.
25792582 Chooses the most severe compliance_alert found among licenses.
25802583 """
25812584 license_expression = getattr (self , self .license_expression_field , "" )
2582- policy_index = self .policy_index
2583- if not license_expression or not policy_index :
2585+ license_policy_index = self .license_policy_index
2586+ if not license_expression or not license_policy_index :
25842587 return ""
25852588
25862589 licensing = get_licensing ()
25872590 parsed_symbols = licensing .parse (license_expression , simple = True ).symbols
25882591
25892592 alerts = [
2590- self .get_alert_for_symbol (policy_index , symbol ) for symbol in parsed_symbols
2593+ self .get_alert_for_symbol (license_policy_index , symbol )
2594+ for symbol in parsed_symbols
25912595 ]
25922596 most_severe_alert = max (alerts , key = self .COMPLIANCE_SEVERITY_MAP .get )
25932597 return most_severe_alert or self .Compliance .OK
0 commit comments