@@ -552,6 +552,50 @@ def load(filename):
552
552
with open ('compile_commands.json' , 'w' ) as f :
553
553
f .write (new_contents )
554
554
555
+ class concat_license_files ():
556
+ """Merge LICENSE and LICENSES_BUNDLED.txt as a context manager
557
+
558
+ LICENSE is the main PyTorch license, LICENSES_BUNDLED.txt is auto-generated
559
+ from all the licenses found in ./third_party/. We concatenate them so there
560
+ is a single license file in the sdist and wheels with all of the necessary
561
+ licensing info.
562
+ """
563
+ def __init__ (self ):
564
+ self .f1 = 'LICENSE'
565
+ self .f2 = 'third_party/LICENSES_BUNDLED.txt'
566
+
567
+ def __enter__ (self ):
568
+ """Concatenate files"""
569
+ with open (self .f1 , 'r' ) as f1 :
570
+ self .bsd_text = f1 .read ()
571
+
572
+ with open (self .f1 , 'a' ) as f1 :
573
+ with open (self .f2 , 'r' ) as f2 :
574
+ self .bundled_text = f2 .read ()
575
+ f1 .write ('\n \n ' )
576
+ f1 .write (self .bundled_text )
577
+
578
+ def __exit__ (self , exception_type , exception_value , traceback ):
579
+ """Restore content of f1"""
580
+ with open (self .f1 , 'w' ) as f :
581
+ f .write (self .bsd_text )
582
+
583
+
584
+ try :
585
+ from wheel .bdist_wheel import bdist_wheel
586
+ except ImportError :
587
+ # This is useful when wheel is not installed and bdist_wheel is not
588
+ # specified on the command line. If it _is_ specified, parsing the command
589
+ # line will fail before wheel_concatenate is needed
590
+ wheel_concatenate = None
591
+ else :
592
+ # Need to create the proper LICENSE.txt for the wheel
593
+ class wheel_concatenate (bdist_wheel ):
594
+ """ check submodules on sdist to prevent incomplete tarballs """
595
+ def run (self ):
596
+ with concat_license_files ():
597
+ super ().run ()
598
+
555
599
556
600
class install (setuptools .command .install .install ):
557
601
def run (self ):
@@ -724,6 +768,7 @@ def make_relative_rpath_args(path):
724
768
'build_ext' : build_ext ,
725
769
'clean' : clean ,
726
770
'install' : install ,
771
+ 'bdist_wheel' : wheel_concatenate ,
727
772
}
728
773
729
774
entry_points = {
0 commit comments