granola.utils module

granola.utils.add_created_at(init)

init decorator that adds _created_at attribute. May add future functionality later

granola.utils.check_min_package_version(package, minimum_version, should_trunc_to_same_len=True)

Helper to decide if the package you are using meets minimum version requirement for some feature.

granola.utils.decode_bytes(byte_string)

Helper function to decode a bytestring

granola.utils.decode_escape_char(string)

Helper function to decode escape character from either a string or a byte string

granola.utils.deprecation(message, version_to_remove=None)
granola.utils.deunicodify_hook(pairs)

Hook for json.load to convert unicode json to byte json for python 2

granola.utils.encode_escape_char(string)

Helper function to encode escape characters and non-unicode for printing to csv

granola.utils.encode_to_bytes(string, encoding='ascii')

Helper function to encode a string as a bytestring

granola.utils.fixpath(path)

On a linux like system (Posix system), it can’t handle windows file pathing, this is a way to resolve that. On a linux system it first converts it to a windows path (where it handles both and /, thus reading it as a valid path), and then when it is a valid path, convert it back to a linux path. On a windows system, it is just happy to read it as a pathlib.Path (which will use either a WindowsPath on windows systems) since , /, and \ are fine.

We then make sure to return a string.

granola.utils.get_path(path)

Helper function that if you pass in a path to a file or directory, returns the absolute path.

Parameters

path (str) – relative or absolute path to file or directory

Returns

absolute path to file or directory

Return type

str

granola.utils.int_to_char(int_)

Return an ascii character in byte string form for a given int

granola.utils.is_terminated_with(input, terminator)

Helper to check if a given input has ends with the given terminator

Parameters
  • input (str) – the input to check

  • terminator (str) – some termination sequence

Returns

whether the input ends with the terminator

Return type

bool

granola.utils.load_serial_df(path)

Load CSV into DataFrame.

Necessary columns -> cmd, response

granola.utils.make_path(path)

Make a path if the path does not already exist