@@ -978,7 +978,10 @@ def get_license_detections_and_expression(self):
978
978
979
979
def get_default_relation_license (datasource_id ):
980
980
from packagedcode import HANDLER_BY_DATASOURCE_ID
981
- handler = HANDLER_BY_DATASOURCE_ID [datasource_id ]
981
+ handler = HANDLER_BY_DATASOURCE_ID .get (datasource_id , None )
982
+ if not handler :
983
+ return 'AND'
984
+
982
985
return handler .default_relation_license
983
986
984
987
@@ -1562,6 +1565,8 @@ class Package(PackageData):
1562
1565
)
1563
1566
1564
1567
def __attrs_post_init__ (self , * args , ** kwargs ):
1568
+ if not self .purl :
1569
+ self .purl = self .set_purl ()
1565
1570
if not self .package_uid :
1566
1571
self .package_uid = build_package_uid (self .purl )
1567
1572
@@ -1576,7 +1581,7 @@ def to_package_data(self):
1576
1581
return PackageData .from_dict (mapping )
1577
1582
1578
1583
@classmethod
1579
- def from_package_data (cls , package_data , datafile_path , package_only = False ):
1584
+ def from_package_data (cls , package_data , datafile_path = None , package_only = False ):
1580
1585
"""
1581
1586
Return a Package from a ``package_data`` PackageData object
1582
1587
or mapping. Or None.
@@ -1591,20 +1596,21 @@ def from_package_data(cls, package_data, datafile_path, package_only=False):
1591
1596
elif package_data :
1592
1597
raise Exception (f'Invalid type: { package_data !r} ' , package_data )
1593
1598
1594
- package_data_mapping ['datafile_paths' ] = [datafile_path ]
1595
1599
package_data_mapping ['datasource_ids' ] = [dsid ]
1596
1600
1597
- license_detections = package_data_mapping ['license_detections' ]
1598
- for detection in license_detections :
1599
- for license_match in detection ['matches' ]:
1600
- if not license_match ['from_file' ]:
1601
- license_match ['from_file' ] = datafile_path
1601
+ if datafile_path :
1602
+ package_data_mapping ['datafile_paths' ] = [datafile_path ]
1603
+ license_detections = package_data_mapping .get ('license_detections' , [])
1604
+ for detection in license_detections :
1605
+ for license_match in detection ['matches' ]:
1606
+ if not license_match ['from_file' ]:
1607
+ license_match ['from_file' ] = datafile_path
1602
1608
1603
1609
package = cls .from_dict (package_data_mapping )
1604
-
1610
+
1605
1611
if not package .package_uid :
1606
1612
package .package_uid = build_package_uid (package .purl )
1607
-
1613
+
1608
1614
if not package_only :
1609
1615
package .populate_license_fields ()
1610
1616
package .populate_holder_field ()
0 commit comments