Example #1
0
def Main():
  """Main entry point."""
  app.FLAGS(['argv[0]', '--vmodule=*=5'])

  # Get the file path of the calling function. This is used to identify the
  # script to run the tests of.
  frame = inspect.stack()[1]
  module = inspect.getmodule(frame[0])
  file_path = module.__file__

  app.RunWithArgs(lambda argv: RunPytestOnFileAndExit(file_path, argv))
Example #2
0
      raise app.UsageError(
          f"Invalid --print_cache_path argument: '{FLAGS.print_cache_path}'")

    # The default action is to sample the model.
    if FLAGS.stop_after == 'corpus':
      instance.model.corpus.Create()
    elif FLAGS.stop_after == 'train':
      instance.m.Train()
      app.Log(1, 'Model: %s', instance.model.cache.path)
    elif FLAGS.stop_after:
      raise app.UsageError(
          f"Invalid --stop_after argument: '{FLAGS.stop_after}'")
    elif FLAGS.export_model:
      instance.ExportPretrainedModel(pathlib.Path(FLAGS.export_model))
    else:
      sample_observers = SampleObserversFromFlags()
      instance.Sample(sample_observers)


def main(argv):
  """Main entry point."""
  if len(argv) > 1:
    raise app.UsageError("Unrecognized command line options: '{}'".format(
        ' '.join(argv[1:])))

  RunWithErrorHandling(DoFlagsAction)


if __name__ == '__main__':
  app.RunWithArgs(main)