def runs_last(func):
  """Decorator to run a function only on the last invocation.
  We determine last by comparing the number times called with the size of env.hosts.
  Return None on all invocations but the last one where we return the function return value.
  """
  def Wrapper():
    calls = func.num_host_calls
    if calls >= len(env.hosts) - 1:
      return func()
    else:
      func.num_host_calls = calls + 1
      return None

  setattr(func, 'num_host_calls', 0)
  return Wrapper
dataset/ETHPy150Open viewfinderco/viewfinder/fabfile.py/runs_last/original