ford.utils module#

class ford.utils.ProgressBar(description, iterable=None, total=None)#

Bases: object

Progress bar that can be used to wrap an iterable and include the current item in the bar, or used as a context manager if not using a simple iterable

An example:

for item in (bar := ProgressBar("Processing items", items)):
    bar.set_current(item.name)
    item.do_work()
Parameters:
  • description (str) – Description of task

  • iterable (Optional[Iterable]) – Collection to iterate over

  • total (Optional[int]) – Can be used if length of iterable is not known at start

set_current(current)#

Set name of current item

ford.utils.get_parens(line, retlevel=0, retblevel=0)#

By default takes a string starting with an open parenthesis and returns the portion of the string going to the corresponding close parenthesis. If retlevel != 0 then will return when that level (for parentheses) is reached. Same for retblevel.

Return type:

str

ford.utils.meta_preprocessor(lines)#

Extract metadata from start of lines

This is modified from the Meta-Data Python Markdown extension and uses the same syntax

Parameters:

lines (Union[str, List[str]]) – Text to process

Return type:

Tuple[Dict[str, Any], List[str]]

Returns:

  • meta – Dictionary of metadata, with lowercase keys

  • lines – Original text with metadata lines removed as list

Notes

Original code copyright 2007-2008 Waylan Limberg

Changes copyright 2008-2014 The Python Markdown Project

Further changes copyright 2023 Ford authors

License: BSD

ford.utils.normalise_path(base_dir, path)#

Tidy up path, making it absolute, relative to base_dir

Return type:

Path

ford.utils.paren_split(sep, string)#

Splits the string into pieces divided by sep, when sep is outside of parentheses.

ford.utils.quote_split(sep, string)#

Splits the strings into pieces divided by sep, when sep in not inside quotes.

ford.utils.str_to_bool(text)#

Convert string to bool. Only takes ‘true’/’false’, ignoring case

ford.utils.strip_paren(line, retlevel=0)#

Takes a string with parentheses and removes any of the contents inside or outside of the retlevel of parentheses. Additionally, whenever a scope of the retlevel is left, the string is split.

e.g. strip_paren(“foo(bar(quz) + faz) + baz(buz(cas))”, 1) -> [“(bar() + faz)”, “(buz())”]

Return type:

list

ford.utils.traverse(root, attrs)#

Traverse a tree of objects, returning a list of all objects found within the attributes attrs

Return type:

list