code: def main(argv=None):
      import os
      import getopt
  
      if argv is None:
          argv = sys.argv
  
      try:
          opts, prog_argv = getopt.getopt(
              argv[1:], "", ["help", "version"]
          )
          # TODO: support options for whatever we would support ;)
          # probably needs to hook in somehow into commands/options available
          # under cmdline/
      except getopt.error as msg:
          sys.stderr.write("%s: %s\n" % (sys.argv[0], msg))
          sys.stderr.write(
              "Try `%s --help' for more information\n" % sys.argv[0]
          )
          sys.exit(1)
  
      # and now we need to execute target script "manually"
      # Borrowing up on from trace.py
      for opt, val in opts:
          if opt == "--help":
              usage(sys.stdout, executable=argv[0])
              sys.exit(0)
  
          if opt == "--version":
              sys.stdout.write("datalad %s\n" % __version__)
              sys.exit(0)
  
      try:
          from datalad_deprecated.auto import AutomagicIO
      except Exception as e:
          # we could just test for ModuleNotFoundError (which should be
          # all that would happen with PY3.6+, but be a little more robust
          # and use the pattern from duecredit
          if type(e).__name__ not in (
              "ImportError",
              "ModuleNotFoundError",
          ):
              lgr.error(
                  "Failed to import datalad_deprecated.auto "
                  "due to %s",
                  str(e),
              )
          sys.stderr.write(
              "{}\n".format(
                  "The DataLad AutomagicIO functionality has been moved to an "
                  "extension package. Please install the Python package "
                  "`datalad_deprecated` to be able to use it."
              )
          )
          sys.exit(1)
  
      sys.argv = prog_argv
      progname = prog_argv[0]
      sys.path[0] = os.path.split(progname)[0]
  
      try:
          with open(progname) as fp:
              code = compile(fp.read(), progname, "exec")
          # try to emulate __main__ namespace as much as possible
          globs = {
              "__file__": progname,
              "__name__": "__main__",
              "__package__": None,
              "__cached__": None,
          }
          # Since used explicitly -- activate the beast
          aio = AutomagicIO(activate=True)
          lgr.info("Running code of %s", progname)
          runctx(code, globs, globs)
          # TODO: see if we could hide our presence from the final tracebacks if execution fails
      except IOError as err:
          lgr.error("Cannot run file %r because: %s", sys.argv[0], err)
          sys.exit(1)
      except SystemExit:
          pass
  
imports: import sys
  from .None import __version__
  from .log import lgr
label_desc: Use image node_id 3 for calling a global function with example usage: main(argv) without return types