API

file_or_name

file_or_name.file_or_name.file_or_name(function, **kwargs)[source]

Transparently allow arguments to be either strings or open files.

Note

If there are no kwargs it is assumed the first argument is a file that will be opened in read mode "r"

Note

If you need a file to be opened with extra arguments, for example newline='' for files that will be used with the stdlib csv writer, you should manually open the file and pass the resulting file object in.

Parameters
  • function (Callable) – The user defined function that we will manager the file opening for.

  • kwargs (Dict[str, str]) – The parameters of function that are considered files to be opened. these are interpreted in the for name=mode and is used to create a mapping of parameters whose values should be opened as file with the provided mode. For example if the value of the wf parameter to your function should be opened in write mode you should decorate your function with @file_or_name(wf='w')

Returns

A decorated function where specified arguments are interpreted as file names and opened automatically.

Return type

Callable

file_or_name.utils

file_or_name.utils.parameterize(function)[source]

A decorator for decorators that allow them to be called without parentheses if no kwargs are given.

Parameters

function (Callable) – A decorator that we want to use with either @function or @function(kwarg=kwvalue)

Returns

A decorated decorator that can be used with or without parentheses

Return type

Callable

file_or_name.utils.get_first_parameter(function)[source]

Get the name of the first parameter of a function.

Parameters

function (Callable) – The function whose first parameter name we want.

Returns

The name of the first parameter.

Return type

str

class file_or_name.utils.ShadowPage(path, mode='wb', dir=None, encoding=None)[source]

Store updates to a copy of the output file and swing pointers for an atomic write.

Note

In some environments like Kubernetes this is not safe to use when the file we are shadowing is in a PersistentVolumeClaim. The temporary file lives in the containers file system and in some configurations Kubernetes will block copying files from the container local file system into the PVC file system.

Parameters
  • path – The file that we are shadowing.

  • mode – The mode we should open the shadow file in.

  • dir – The directory in which the shadow file should be created.

  • encoding – The file type encoding the shadow file should be opened in.

write(*args, **kwargs)[source]

Proxy writes to the temp file.

Module contents