parameters: (directory)
docstring: Returns a string describing the current Git HEAD version as descriptively
      as possible.
  
      Runs 'git describe', or alternately 'git rev-parse HEAD', in directory.  If
      successful, returns the output; otherwise returns 'unknown hash, <date>'.
docstring_summary: Returns a string describing the current Git HEAD version as descriptively
      as possible.
docstring_tokens: Returns a string describing the current Git HEAD version as descriptively as possible .
function: def describe(directory):
      """Returns a string describing the current Git HEAD version as descriptively
      as possible.
  
      Runs 'git describe', or alternately 'git rev-parse HEAD', in directory.  If
      successful, returns the output; otherwise returns 'unknown hash, <date>'."""
      try:
          # decode() is needed here for Python3 compatibility. In Python2,
          # str and bytes are the same type, but not in Python3.
          # Popen.communicate() returns a bytes instance, which needs to be
          # decoded into text data first in Python3. And this decode() won't
          # hurt Python2.
          return command_output(['git', 'describe'], directory).rstrip().decode()
      except:
          try:
              return command_output(
                  ['git', 'rev-parse', 'HEAD'], directory).rstrip().decode()
          except:
              # This is the fallback case where git gives us no information,
              # e.g. because the source tree might not be in a git tree.
              # In this case, usually use a timestamp.  However, to ensure
              # reproducible builds, allow the builder to override the wall
              # clock time with environment variable SOURCE_DATE_EPOCH
              # containing a (presumably) fixed timestamp.
              timestamp = int(os.environ.get('SOURCE_DATE_EPOCH', time.time()))
              formatted = datetime.datetime.utcfromtimestamp(timestamp).isoformat()
              return 'unknown hash, {}'.format(formatted)
function_tokens: def describe ( directory ) : try : # decode() is needed here for Python3 compatibility. In Python2, # str and bytes are the same type, but not in Python3. # Popen.communicate() returns a bytes instance, which needs to be # decoded into text data first in Python3. And this decode() won't # hurt Python2. return command_output ( [ 'git' , 'describe' ] , directory ) . rstrip ( ) . decode ( ) except : try : return command_output ( [ 'git' , 'rev-parse' , 'HEAD' ] , directory ) . rstrip ( ) . decode ( ) except : # This is the fallback case where git gives us no information, # e.g. because the source tree might not be in a git tree. # In this case, usually use a timestamp.  However, to ensure # reproducible builds, allow the builder to override the wall # clock time with environment variable SOURCE_DATE_EPOCH # containing a (presumably) fixed timestamp. timestamp = int ( os . environ . get ( 'SOURCE_DATE_EPOCH' , time . time ( ) ) ) formatted = datetime . datetime . utcfromtimestamp ( timestamp ) . isoformat ( ) return 'unknown hash, {}' . format ( formatted )