stubber.minify

Processing for createstubs.py Minimizes and cross-compiles a MicroPyton file.

Module Contents

Functions

get_whitespace_context(content, index)

Get whitespace count of lines surrounding index

edit_lines(content, edits[, diff])

Edit string by list of edits

minify_script(→ str)

Minifies createstubs.py and variants

reduce_log_print(keep_report, diff, source_content)

minify(source, target[, keep_report, diff])

Minifies and compiles a script

cross_compile(source, target[, version])

Runs mpy-cross on a (minified) script

pipx_mpy_cross(version, source_file, _target)

Run mpy-cross using pipx

write_to_temp_file(source)

Writes a string to a temp file and returns the Path object

get_temp_file([prefix, suffix])

Get temp file and returns the Path object

Attributes

StubSource

XCompileDest

LineEdits

stubber.minify.StubSource
stubber.minify.XCompileDest
stubber.minify.LineEdits
stubber.minify.get_whitespace_context(content: List[str], index: int)

Get whitespace count of lines surrounding index

Parameters:
  • content (List[str]) –

  • index (int) –

stubber.minify.edit_lines(content: str, edits: LineEdits, diff: bool = False)

Edit string by list of edits

Parameters:
  • content (str) – content to edit

  • edits ([(str, str)]) – List of edits to make. The first string in the tuple representsthe type of edit to make, can be either: - comment - comment text out (removed on minify) - rprint - replace text with print - rpass - replace text with pass The second string is the matching text to replace

  • diff (bool, optional) – Prints diff of each edit. Defaults to False.

Returns:

edited string

Return type:

str

stubber.minify.minify_script(source_script: StubSource, keep_report: bool = True, diff: bool = False) str

Minifies createstubs.py and variants

Args: source_script:

  • (str): content to edit

  • (Path): path to file to edit

  • (IOBase): file-like object to edit

keep_report (bool, optional): Keeps single report line in createstubs

Defaults to True.

diff (bool, optional): Print diff from edits. Defaults to False.

Returns:

minified source text

Return type:

str

Parameters:
stubber.minify.reduce_log_print(keep_report, diff, source_content)
stubber.minify.minify(source: StubSource, target: StubSource, keep_report: bool = True, diff: bool = False)

Minifies and compiles a script

Parameters:
stubber.minify.cross_compile(source: StubSource, target: XCompileDest, version: str = '')

Runs mpy-cross on a (minified) script

Parameters:
  • source (StubSource) –

  • target (XCompileDest) –

  • version (str) –

stubber.minify.pipx_mpy_cross(version: str, source_file, _target)

Run mpy-cross using pipx

Parameters:

version (str) –

stubber.minify.write_to_temp_file(source: str)

Writes a string to a temp file and returns the Path object

Parameters:

source (str) –

stubber.minify.get_temp_file(prefix: str = 'mpy_cross_', suffix: str = '.py')

Get temp file and returns the Path object

Parameters:
  • prefix (str) –

  • suffix (str) –