class_docstr: Wraps a command as a function in order to make sure it goes through the
  pipeline and notify when it is finished.
  The output is a string containing everything that has been sent to stdout.
  WARNING: use CommandFunction only if you know the output won't be too big !
  Otherwise use subprocess.run() that also streams the outputto stdout/stderr.
  
  Parameters
  ----------
  command: list
      command to run, as a list
  verbose: bool
      prints the command and stdout at runtime
  cwd: Path/str
      path to the location where the command must run from
  
  Returns
  -------
  str
     Everything that has been sent to stdout
class_docstr_tok: ["Wraps","a","command","as","a","function","in","order","to","make","sure","it","goes","through","the","pipeline","and","notify","when","it","is","finished",".","The","output","is","a","string","containing","everything","that","has","been","sent","to","stdout",".","WARNING",":","use","CommandFunction","only","if","you","know","the","output","wo","n't","be","too","big","!","Otherwise","use","subprocess.run","(",")","that","also","streams","the","outputto","stdout\/stderr",".","Parameters","--","--","--","--","--","command",":","list","command","to","run",",","as","a","list","verbose",":","bool","prints","the","command","and","stdout","at","runtime","cwd",":","Path\/str","path","to","the","location","where","the","command","must","run","from","Returns","--","--","--","-","str","Everything","that","has","been","sent","to","stdout"]
docstr: Call the cammand line with addidional arguments
  The keyword arguments will be sent as --{key}={val}
  The logs bufferized. They will be printed if the job fails, or sent as output of the function
  Errors are provided with the internal stderr.
docstr_tok: ["Call","the","cammand","line","with","addidional","arguments","The","keyword","arguments","will","be","sent","as","--","{","key","}","=","{","val","}","The","logs","bufferized",".","They","will","be","printed","if","the","job","fails",",","or","sent","as","output","of","the","function","Errors","are","provided","with","the","internal","stderr","."]
code: def __call__(self, *args: tp.Any, **kwargs: tp.Any) -> str:
      """Call the cammand line with addidional arguments
      The keyword arguments will be sent as --{key}={val}
      The logs bufferized. They will be printed if the job fails, or sent as output of the function
      Errors are provided with the internal stderr.
      """
      full_command = (
          self.command
          + [str(x) for x in args]
          + [f"--{x}={y}" for x, y in kwargs.items()]
      )  # TODO bad parsing
      if self.verbose:
          print(
              f"The following command is sent: \"{' '.join(full_command)}\""
          )
      with subprocess.Popen(
          full_command,
          stdout=subprocess.PIPE,
          stderr=subprocess.PIPE,
          shell=False,
          cwd=self.cwd,
          env=self.env,
      ) as process:
          stdout_buffer = io.StringIO()
          stderr_buffer = io.StringIO()
  
          try:
              copy_process_streams(
                  process, stdout_buffer, stderr_buffer, self.verbose
              )
          except Exception as e:
              process.kill()
              process.wait()
              raise FailedJobError(
                  "Job got killed for an unknown reason."
              ) from e
          stdout = stdout_buffer.getvalue().strip()
          stderr = stderr_buffer.getvalue().strip()
          retcode = process.wait()
          if stderr and (retcode and not self.verbose):
              # We don't print is self.verbose, as it already happened before.
              print(stderr, file=sys.stderr)
          if retcode:
              subprocess_error = subprocess.CalledProcessError(
                  retcode, process.args, output=stdout, stderr=stderr
              )
              raise FailedJobError(stderr) from subprocess_error
      return stdout
  
imports: import contextlib
  import io
  import itertools
  import os
  import pickle
  import select
  import shutil
  import subprocess
  import sys
  import tarfile
  import typing
  from pathlib import Path
  import cloudpickle
label_desc: Use image node_id 2 for calling the CommandFunction obj's underlying member method code with example usage: obj.__call__() and returns: stdout