1212from  io  import  BytesIO 
1313from  io  import  StringIO 
1414
15- from  spdx .checksum  import  Algorithm 
15+ from  spdx .checksum  import  Checksum 
16+ from  spdx .checksum  import  ChecksumAlgorithm 
1617from  spdx .creationinfo  import  Tool 
1718from  spdx .document  import  ExtractedLicense 
1819from  spdx .document  import  Document 
19- from  spdx .document  import  License 
20+ from  spdx .license  import  License 
2021from  spdx .file  import  File 
2122from  spdx .package  import  Package 
23+ from  spdx .relationship  import  Relationship 
24+ from  spdx .utils  import  calc_verif_code 
2225from  spdx .utils  import  NoAssert 
2326from  spdx .utils  import  SPDXNone 
2427from  spdx .version  import  Version 
@@ -280,9 +283,8 @@ def write_spdx(
280283        name  =  './'  +  file_data .get ('path' )
281284        file_entry  =  File (
282285            spdx_id = f'SPDXRef-{ sid }  ,
283-             name = name ,
284-             chk_sum = Algorithm ('SHA1' , file_data .get ('sha1' ) or  '' )
285-         )
286+             name = name )
287+         file_entry .set_checksum (Checksum (ChecksumAlgorithm .SHA1 , file_data .get ('sha1' ) or  '' ))
286288
287289        file_license_detections  =  file_data .get ('license_detections' )
288290        license_matches  =  get_matches_from_detection_mappings (file_license_detections )
@@ -357,9 +359,11 @@ def write_spdx(
357359        else :
358360            file_entry .copyright  =  SPDXNone ()
359361
360-         package .add_file (file_entry )
362+         doc .add_file (file_entry )
363+         relationship  =  Relationship (f'{ package .spdx_id } { file_entry .spdx_id }  )
364+         doc .add_relationship (relationship )
361365
362-     if  len ( package .files )  ==   0 :
366+     if  not   doc .files :
363367        if  as_tagvalue :
364368            msg  =  "# No results for package '{}'.\n " .format (package .name )
365369        else :
@@ -392,7 +396,7 @@ def write_spdx(
392396        # statements for the package. 
393397        package .cr_text  =  '\n ' .join (sorted (package .cr_text )) +  '\n ' 
394398
395-     package .verif_code  =  doc . package . calc_verif_code ()
399+     package .verif_code  =  calc_verif_code (doc . files )
396400    package .license_declared  =  NoAssert ()
397401    package .conc_lics  =  NoAssert ()
398402
@@ -404,7 +408,7 @@ def write_spdx(
404408    # one case we do need to deal with bytes and decode before writing (rdf) and 
405409    # in the other case we deal with text all the way. 
406410
407-     if  package .files :
411+     if  doc .files :
408412
409413        if  as_tagvalue :
410414            from  spdx .writers .tagvalue  import  write_document   # NOQA 
0 commit comments