evariste.utils¶
A rag-bag of utility functions that did not fit anywhere else.
- class evariste.utils.DeepDict(depth, dictionary=None)[source]¶
Dictionary of dictionary of … of dictionaries.
All the dictionaries (expeted the last one) are
collections.defaultdictobjects.- fill_blanks(other: dict)[source]¶
Recursively copy values of
otherintoself.The values are copied only if those of
selfare not defined.
- classmethod from_configparser(config: ConfigParser) DeepDict[source]¶
Create a
DeepDictobject from aconfigparser.ConfigParserobject.
- evariste.utils.smart_open(filename, mode='w', encoding='utf8')[source]¶
Open filename, standard output, or nothing.
- Parameters:
filename (str) –
If
filenameis:""(the empty string): return a fake file object,which is empty if file is open for reading, and can be written in if file is open for writing (but content is then discarded);
"-"(a dash):read from standard input, or write to standard output (depending on mode);
any other: open the given file.
- evariste.utils.yesno(arg: bool | str | int | None) bool[source]¶
Interpret some (mostly
str) variable as a boolean.>>> yesno("y") True >>> yesno("0") False >>> yesno("1") True >>> yesno("Yes") True >>> yesno("True") True >>> yesno("something senseless") False >>> yesno(None) False
- evariste.utils.expand_path(path)[source]¶
Return
pathwhere environment variables and user directory have been expanded.
- class evariste.utils.ChangeDir(directory)[source]¶
Context manager to change and restore current directory.
- evariste.utils.cached_iterator(func)[source]¶
Like
functools.cache(), but for iterators.That is, the first time the function is run, the returned iterable is stored (as a tuple), and next calls to the function return this tuple.