parameters: ()
docstring: Main function
docstring_summary: Main function
docstring_tokens: Main function
function: def main():
      """Main function"""
  
      opts = None
      argv = None
      if "--" in sys.argv:
          _idx = sys.argv.index("--")
          _argv = sys.argv[(_idx + 1) :]  # noqa: E203
          opts, argv = parse_args(sys.argv[:_idx])
          argv = _argv
      else:
          if "-h" in sys.argv or "--help" in sys.argv:
              opts, argv = parse_args()
          else:
              argv = sys.argv[1:]
              opts, discard = parse_args()
              if len(argv) == 0 or not os.path.isfile(argv[0]):
                  raise RuntimeError(
                      "Could not determine input script. Use '--' before "
                      "the script and its arguments to ensure correct parsing. \nE.g. "
                      "python -m timemory.trace -- ./script.py"
                  )
  
      from ..libs.libpytimemory import initialize
      from ..libs.libpytimemory import settings
  
      if os.path.isfile(argv[0]):
          argv[0] = os.path.realpath(argv[0])
  
      settings.output_path = "timemory-{}-trace-output".format(
          os.path.basename(argv[0]).strip().replace("_", "-").replace("--", "-")
      )
      initialize(argv)
  
      from ..libs.libpytimemory.trace import config as _tracer_config
  
      _tracer_config.include_args = opts.include_args
      _tracer_config.include_line = opts.include_line
      _tracer_config.include_filename = opts.include_file
      _tracer_config.full_filepath = opts.full_filepath
      _tracer_config.skip_functions = opts.skip_funcs
      _tracer_config.skip_filenames = opts.skip_files
      _tracer_config.only_functions = opts.only_funcs
      _tracer_config.only_filenames = opts.only_files
      _tracer_config.verbosity = opts.verbosity
  
      print("[timemory]> tracing: {}".format(argv))
  
      sys.argv[:] = argv
      if opts.setup is not None:
          # Run some setup code outside of the tracer. This is good for large
          # imports.
          setup_file = find_script(opts.setup)
          __file__ = setup_file
          __name__ = "__main__"
          # Make sure the script's directory is on sys.path
          sys.path.insert(0, os.path.dirname(setup_file))
          ns = locals()
          execfile(setup_file, ns, ns)
  
      from . import Tracer, FakeTracer
  
      output_path = get_value(
          "TIMEMORY_OUTPUT_PATH", settings.output_path, str, opts.output_dir
      )
      settings.output_path = output_path
  
      # if len(argv) > 1 and argv[0] != "--"):
      #    raise RuntimeError("Specify command to run with -- <command-to-run>")
      script_file = find_script(sys.argv[0])
      __file__ = script_file
      __name__ = "__main__"
      # Make sure the script's directory is on sys.path
      sys.path.insert(0, os.path.dirname(script_file))
  
      tracer = Tracer(opts.components)
      fake = FakeTracer()
  
      if PY3:
          import builtins
      else:
          import __builtin__ as builtins
  
      builtins.__dict__["trace"] = tracer
      builtins.__dict__["notrace"] = fake
      builtins.__dict__["profile"] = tracer
      builtins.__dict__["noprofile"] = fake
  
      try:
          try:
              if not opts.builtin:
                  tracer.start()
              tracer._unset += 1
              execfile_ = execfile
              ns = locals()
              if opts.builtin:
                  execfile(script_file, ns, ns)
              else:
                  tracer.runctx(
                      "execfile_(%r, globals())" % (script_file,), ns, ns
                  )
          except (KeyboardInterrupt, SystemExit):
              pass
          finally:
              if not opts.builtin:
                  tracer.stop()
              tracer._unset -= 1
              del tracer
              del fake
      except Exception as e:
          exc_type, exc_value, exc_traceback = sys.exc_info()
          traceback.print_exception(exc_type, exc_value, exc_traceback, limit=10)
          print("Exception - {}".format(e))
function_tokens: def main ( ) : opts = None argv = None if "--" in sys . argv : _idx = sys . argv . index ( "--" ) _argv = sys . argv [ ( _idx + 1 ) : ] # noqa: E203 opts , argv = parse_args ( sys . argv [ : _idx ] ) argv = _argv else : if "-h" in sys . argv or "--help" in sys . argv : opts , argv = parse_args ( ) else : argv = sys . argv [ 1 : ] opts , discard = parse_args ( ) if len ( argv ) == 0 or not os . path . isfile ( argv [ 0 ] ) : raise RuntimeError ( "Could not determine input script. Use '--' before " "the script and its arguments to ensure correct parsing. \nE.g. " "python -m timemory.trace -- ./script.py" ) from . . libs . libpytimemory import initialize from . . libs . libpytimemory import settings if os . path . isfile ( argv [ 0 ] ) : argv [ 0 ] = os . path . realpath ( argv [ 0 ] ) settings . output_path = "timemory-{}-trace-output" . format ( os . path . basename ( argv [ 0 ] ) . strip ( ) . replace ( "_" , "-" ) . replace ( "--" , "-" ) ) initialize ( argv ) from . . libs . libpytimemory . trace import config as _tracer_config _tracer_config . include_args = opts . include_args _tracer_config . include_line = opts . include_line _tracer_config . include_filename = opts . include_file _tracer_config . full_filepath = opts . full_filepath _tracer_config . skip_functions = opts . skip_funcs _tracer_config . skip_filenames = opts . skip_files _tracer_config . only_functions = opts . only_funcs _tracer_config . only_filenames = opts . only_files _tracer_config . verbosity = opts . verbosity print ( "[timemory]> tracing: {}" . format ( argv ) ) sys . argv [ : ] = argv if opts . setup is not None : # Run some setup code outside of the tracer. This is good for large # imports. setup_file = find_script ( opts . setup ) __file__ = setup_file __name__ = "__main__" # Make sure the script's directory is on sys.path sys . path . insert ( 0 , os . path . dirname ( setup_file ) ) ns = locals ( ) execfile ( setup_file , ns , ns ) from . import Tracer , FakeTracer output_path = get_value ( "TIMEMORY_OUTPUT_PATH" , settings . output_path , str , opts . output_dir ) settings . output_path = output_path # if len(argv) > 1 and argv[0] != "--"): #    raise RuntimeError("Specify command to run with -- <command-to-run>") script_file = find_script ( sys . argv [ 0 ] ) __file__ = script_file __name__ = "__main__" # Make sure the script's directory is on sys.path sys . path . insert ( 0 , os . path . dirname ( script_file ) ) tracer = Tracer ( opts . components ) fake = FakeTracer ( ) if PY3 : import builtins else : import __builtin__ as builtins builtins . __dict__ [ "trace" ] = tracer builtins . __dict__ [ "notrace" ] = fake builtins . __dict__ [ "profile" ] = tracer builtins . __dict__ [ "noprofile" ] = fake try : try : if not opts . builtin : tracer . start ( ) tracer . _unset += 1 execfile_ = execfile ns = locals ( ) if opts . builtin : execfile ( script_file , ns , ns ) else : tracer . runctx ( "execfile_(%r, globals())" % ( script_file , ) , ns , ns ) except ( KeyboardInterrupt , SystemExit ) : pass finally : if not opts . builtin : tracer . stop ( ) tracer . _unset -= 1 del tracer del fake except Exception as e : exc_type , exc_value , exc_traceback = sys . exc_info ( ) traceback . print_exception ( exc_type , exc_value , exc_traceback , limit = 10 ) print ( "Exception - {}" . format ( e ) )