o
    joiH	                     @   sp   d Z ddlmZ ddlmZ ddlmZ ddlmZ edddZ	ej
Z
ejZd	eejgdf d
dfddZdS )a  Interface for generating a FAR file from a Pynini file.

Given an output FAR file (FST archive) via --output, a Pynini file produces this
FAR file by exporting a number of FSTs into this FAR file. To this end, a Pynini
file creates a generator_main file with the signature:

  def generator_main(exporter: grm.Exporter):

which can contain lines of the form

  exporter[fst_name] = fst

using the exporter argument in generator_main to export a given FST under a
corresponding name. The generator_main function must be referenced with

  if __name__ == '__main__':
    grm.run(generator_main)

and should be used in a compile_grm_py BUILD rule to build the FAR.

For an example, see grm_example.py.
    )Callable)app)flags)exportoutputNzThe output FAR file.generator_mainreturnc                    s*    fdd}t d dt_t| dS )a2  Executes the grm FAR export program to export exactly one FAR.

  Args:
    generator_main: The FAR generator_main function to execute. It takes a
      single argument "exporter", which is an export.Exporter object with a
      __setitem__ method used to save an FST with a named designator into a FAR.
  c                    sP   z |  d | rtd|  ttj} | |  W d S    dt_	 )Nr   z#Unexpected command line arguments: fatal)
popr   
UsageErrorr   Exporter_OUTPUTvaluecloseFLAGSstderrthreshold)unused_argvexporterr    E/home/ubuntu/.local/lib/python3.10/site-packages/pynini/export/grm.pymain<   s   
zrun.<locals>.mainr   warningN)r   mark_flag_as_requiredr   r   r   run)r   r   r   r   r   r   3   s   	
r   )__doc__typingr   abslr   r   pynini.exportr   DEFINE_stringr   r   r   r   r   r   r   r   <module>   s   "