flowtool.python

Some pythonic helper functions and general purpose cornercutting.

flowtool.python.read_stdin_nonblocking(**kwd)[source]

If there’s input ready, do something, else do something else. Note timeout is zero so select won’t block at all.

For test cases it will return the (to be deprecated) environment variable TEST_STDIN_VALUE. But it turns out, that monkey patching sys.stdin works a lot better in this scenario, and thus will be migrated to in the future.

flowtool.python.startingwith(prefixes='', lst=())[source]

Filter an iterable for elements starting with prefix.

>>> startingwith(('feature/', 'footure/'), ['feature/something', 'release/somethingelse'])
['feature/something']
flowtool.python.endingwith(suffixes='', lst=())[source]

Filter an iterable for elements ending with suffix.

>>> endingwith(('.py', 'xxx', '.sh'), ['something.py', 'somethingelse.sh'])
['something.py', 'somethingelse.sh']
flowtool.python.containing(parts='', lst=())[source]

Filter an iterable for elements containing the given parts.

>>> containing(('ing', 'xxx', 'e'), ['something', 'somethingelse', 'morestuff'])
['something', 'somethingelse', 'something', 'somethingelse', 'morestuff']
flowtool.python.contains_any(container, *elems)[source]

Return the first elem, that is in container.

>>> contains_any('something', 'sum', 'somethingelse', 'ing', 'ong')
'ing'
>>> contains_any('something', 'sum', 'somethingelse', 'ong') is None
True
flowtool.python.contains_any_filter(containers, *elems)[source]

Return those containers that contain at least one elem.

>>> contains_any_filter(['something', 'thumethong', 'butter'], 'sum', 'somethingelse', 'ing', 'ong')
['something', 'thumethong']
flowtool.python.get_configparser()[source]

Get a ConfigParser. Across python versions.

>>> bool(get_configparser())
True
flowtool.python.import_file(name, path)[source]

A compatible way to import a module from its file name.

>>> module = import_file('import_file_test', __file__)