@@ -673,27 +673,60 @@ class ExpressionInfo:
673673 return data
674674
675675
676- def build_spdx_licensing (license_key_index_location = None ):
676+ def get_license_key_info (license_key_index_location = None ):
677677 """
678- Return a Licensing object that has been loaded with SPDX license keys
678+ Return a list of dictionaries that contain license key information from
679+ `license_key_index_location`
680+
681+ If `license_key_index_location` is not present, then we use a vendored copy
682+ of the license key index from https://scancode-licensedb.aboutcode.org/
679683 """
680684 if license_key_index_location :
681685 with open (license_key_index_location , 'r' ) as f :
682- license_info = json .load (f )
686+ license_key_info = json .load (f )
683687 else :
684- # Use vendored license key index if `license_key_index_location` has not been provided
685688 curr_dir = dirname (abspath (__file__ ))
686689 data_dir = join (curr_dir , 'data' )
687690 vendored_license_key_index_location = join (data_dir , 'license_key_index.json' )
688691 with open (vendored_license_key_index_location , 'r' ) as f :
689- license_info = json .load (f )
692+ license_key_info = json .load (f )
693+ return license_key_info
694+
695+
696+ def build_licensing (license_key_index_location = None ):
697+ """
698+ Return a Licensing object that has been loaded with license keys.
699+
700+ If `license_key_index_location` is present, then license key information
701+ will be loaded from `license_key_index_location`, otherwise license key
702+ information will come from a vendored license key index file.
703+ """
704+ license_key_info = get_license_key_info (license_key_index_location )
705+ lics = [
706+ {
707+ 'key' : l .get ('license_key' , '' ),
708+ 'is_exception' : l .get ('is_exception' , '' ),
709+ } for l in license_key_info
710+ ]
711+ syms = [LicenseSymbol (** l ) for l in lics ]
712+ return Licensing (syms )
713+
690714
715+ def build_spdx_licensing (license_key_index_location = None ):
716+ """
717+ Return a Licensing object that has been loaded with SPDX license keys.
718+
719+ If `license_key_index_location` is present, then license key information
720+ will be loaded from `license_key_index_location`, otherwise license key
721+ information will come from a vendored license key index file.
722+ """
723+ license_key_info = get_license_key_info (license_key_index_location )
691724 lics = [
692725 {
693726 'key' : l .get ('spdx_license_key' , '' ),
694727 'aliases' : l .get ('other_spdx_license_keys' , '' ),
695728 'is_exception' : l .get ('is_exception' , '' ),
696- } for l in license_info if l .get ('spdx_license_key' )
729+ } for l in license_key_info if l .get ('spdx_license_key' )
697730 ]
698731 syms = [LicenseSymbol (** l ) for l in lics ]
699732 return Licensing (syms )
0 commit comments