@@ -1085,13 +1085,13 @@ def dumps(self, licenses_dict=None):
10851085 license_file .append (lic )
10861086 else :
10871087 if isinstance (field .original_value , list ):
1088- license_file = field .value .keys ()
1088+ license_file = list ( field .value .keys () )
10891089 else :
10901090 # Restore the original license_file value
10911091 # See #444
10921092 license_file = [field .original_value ]
10931093 else :
1094- license_file = field .value .keys ()
1094+ license_file = list ( field .value .keys () )
10951095 elif field .name == 'license_url' and field .value :
10961096 license_url = field .value
10971097 elif field .name in file_fields and field .value :
@@ -1105,10 +1105,10 @@ def dumps(self, licenses_dict=None):
11051105 # Group the same license information in a list
11061106 # This `licenses_dict` is a dictionary with license key as the key and the
11071107 # value is the list of [license_name, license_context, license_url]
1108- lic_key_dup = license_key [:]
1108+ lic_key_copy = license_key [:]
1109+ lic_dict_list = []
11091110 for lic_key in license_key :
11101111 lic_dict = OrderedDict ()
1111-
11121112 if licenses_dict and lic_key in licenses_dict :
11131113 lic_dict ['key' ] = lic_key
11141114 lic_name = licenses_dict [lic_key ][0 ]
@@ -1120,30 +1120,43 @@ def dumps(self, licenses_dict=None):
11201120 lic_dict ['url' ] = lic_url
11211121
11221122 # Remove the license information if it has been handled
1123- #license_key.remove(lic_key)
1124- #print(license_key)
1125- lic_key_dup .remove (lic_key )
1123+ lic_key_copy .remove (lic_key )
11261124 if lic_name in license_name :
11271125 license_name .remove (lic_name )
11281126 if lic_url in license_url :
11291127 license_url .remove (lic_url )
11301128 if lic_file in license_file :
11311129 license_file .remove (lic_file )
1132- data . setdefault ( 'licenses' , []) .append (lic_dict )
1130+ lic_dict_list .append (lic_dict )
11331131
11341132 # Handle license information that have not been handled.
1135- license_group = list (zip_longest (lic_key_dup , license_name , license_file , license_url ))
1133+ license_group = list (zip_longest (lic_key_copy , license_name , license_file , license_url ))
11361134 for lic_group in license_group :
11371135 lic_dict = OrderedDict ()
11381136 if lic_group [0 ]:
11391137 lic_dict ['key' ] = lic_group [0 ]
11401138 if lic_group [1 ]:
11411139 lic_dict ['name' ] = lic_group [1 ]
1140+ else :
1141+ # If no name is given, treat the key as the name
1142+ if lic_group [0 ]:
1143+ lic_dict ['name' ] = lic_group [0 ]
11421144 if lic_group [2 ]:
11431145 lic_dict ['file' ] = lic_group [2 ]
11441146 if lic_group [3 ]:
11451147 lic_dict ['url' ] = lic_group [3 ]
1146- data .setdefault ('licenses' , []).append (lic_dict )
1148+ lic_dict_list .append (lic_dict )
1149+
1150+ # Format the license information in the same order of the license expression
1151+ if license_key :
1152+ for key in license_key :
1153+ for lic_dict in lic_dict_list :
1154+ if key == lic_dict ['key' ]:
1155+ data .setdefault ('licenses' , []).append (lic_dict )
1156+ break
1157+ else :
1158+ for lic_dict in lic_dict_list :
1159+ data .setdefault ('licenses' , []).append (lic_dict )
11471160
11481161 return saneyaml .dump (data )
11491162
@@ -1234,13 +1247,16 @@ def dump_lic(self, location, license_dict):
12341247
12351248 if self .license_expression .present :
12361249 special_char_in_expression , lic_list = parse_license_expression (self .license_expression .value )
1250+ self .license_key .value = lic_list
12371251 self .license_key .present = True
12381252 if not special_char_in_expression :
12391253 for lic_key in lic_list :
12401254 try :
12411255 if license_dict [lic_key ]:
1256+ """
12421257 if not lic_key in self.license_key.value:
12431258 self.license_key.value.append(lic_key)
1259+ """
12441260 license_path = posixpath .join (parent , lic_key )
12451261 license_path += u'.LICENSE'
12461262 license_path = add_unc (license_path )
0 commit comments