code: def git_version(cwd):
      def _minimal_ext_cmd(cmd):
          # construct minimal environment
          env = {}
          for k in ["SYSTEMROOT", "PATH"]:
              v = os.environ.get(k)
              if v is not None:
                  env[k] = v
          # LANGUAGE is used on win32
          env["LANGUAGE"] = "C"
          env["LANG"] = "C"
          env["LC_ALL"] = "C"
          out = subprocess.Popen(
              cmd, stdout=subprocess.PIPE, env=env, cwd=cwd
          ).communicate()[0]
          return out
  
      try:
          git_dir = os.path.abspath(
              os.path.dirname(os.path.dirname(__file__))
          )
          git_dir = os.path.join(git_dir, ".git")
          out = _minimal_ext_cmd(
              ["git", "--git-dir", git_dir, "rev-parse", "HEAD"]
          )
          GIT_REVISION = out.strip().decode("ascii")[:7]
  
          # We need a version number that's regularly incrementing for newer
          # commits, so the sort order in a wheelhouse of nightly builds is
          # correct (see https://github.com/MacPython/scipy-wheels/issues/114).
          # It should also be a reproducible version number, so don't rely on
          # date/time but base it on commit history. This gives the commit
          # count since the previous branch point from the current branch
          # (assuming a full `git clone`, it may be less if `--depth` was
          # used - commonly the default in CI):
          prev_version_tag = "^{}.{}.0".format(MAJOR, MINOR - 2)
          out = _minimal_ext_cmd(
              [
                  "git",
                  "--git-dir",
                  git_dir,
                  "rev-list",
                  "HEAD",
                  prev_version_tag,
                  "--count",
              ]
          )
          COMMIT_COUNT = out.strip().decode("ascii")
          COMMIT_COUNT = "0" if not COMMIT_COUNT else COMMIT_COUNT
      except OSError:
          GIT_REVISION = "Unknown"
          COMMIT_COUNT = "Unknown"
  
      return GIT_REVISION, COMMIT_COUNT
  
imports: import os
  import subprocess
  import argparse
label_desc: Use image node_id 3 for calling a global function with example usage: git_version(cwd) and returns: GIT_REVISION,  COMMIT_COUNT, out