public void genPyFiles ( SoyFileSetNode soyTree , SoyPySrcOptions pySrcOptions , String outputPathFormat , ErrorReporter errorReporter ) throws IOException { ImmutableList < SoyFileNode > srcsToCompile = ImmutableList . copyOf ( soyTree . getChildren ( ) ) ; // Determine the output paths. List < String > soyNamespaces = getSoyNamespaces ( soyTree ) ; Multimap < String , Integer > outputs = MainEntryPointUtils . mapOutputsToSrcs ( null , outputPathFormat , srcsToCompile ) ; // Generate the manifest and add it to the current manifest. ImmutableMap < String , String > manifest = generateManifest ( soyNamespaces , outputs ) ; // Generate the Python source. List < String > pyFileContents = genPySrc ( soyTree , pySrcOptions , manifest , errorReporter ) ; if ( srcsToCompile . size ( ) != pyFileContents . size ( ) ) { throw new AssertionError ( String . format ( "Expected to generate %d code chunk(s), got %d" , srcsToCompile . size ( ) , pyFileContents . size ( ) ) ) ; } // Write out the Python outputs. for ( String outputFilePath : outputs . keySet ( ) ) { try ( Writer out = Files . newWriter ( new File ( outputFilePath ) , StandardCharsets . UTF_8 ) ) { for ( int inputFileIndex : outputs . get ( outputFilePath ) ) { out . write ( pyFileContents . get ( inputFileIndex ) ) ; } } } // Write out the manifest file. if ( pySrcOptions . namespaceManifestFile ( ) != null ) { try ( Writer out = Files . newWriter ( new File ( pySrcOptions . namespaceManifestFile ( ) ) , StandardCharsets . UTF_8 ) ) { Properties prop = new Properties ( ) ; for ( String namespace : manifest . keySet ( ) ) { prop . put ( namespace , manifest . get ( namespace ) ) ; } prop . store ( out , null ) ; } } }
Generates Python source files given a Soy parse tree an options object and information on where to put the output files .