stubber.minify ============== .. py:module:: stubber.minify .. autoapi-nested-parse:: Processing for createstubs.py Minimizes and cross-compiles a MicroPyton file. Attributes ---------- .. autoapisummary:: stubber.minify.python_minifier stubber.minify.StubSource stubber.minify.XCompileDest stubber.minify.LineEdits Functions --------- .. autoapisummary:: stubber.minify.get_whitespace_context stubber.minify.edit_lines stubber.minify.minify_script stubber.minify.reduce_log_print stubber.minify.minify stubber.minify.cross_compile stubber.minify.locate_mpy_cross stubber.minify.run_mpy_cross stubber.minify.write_to_temp_file stubber.minify.get_temp_file Module Contents --------------- .. py:data:: python_minifier :value: None .. py:data:: StubSource .. py:data:: XCompileDest .. py:data:: LineEdits .. py:function:: get_whitespace_context(content: List[str], index: int) Get whitespace count of lines surrounding index .. py:function:: edit_lines(content: str, edits: LineEdits, diff: bool = False) Edit string by list of edits :param content: content to edit :type content: str :param edits: 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 :type edits: [(str, str)] :param diff: Prints diff of each edit. Defaults to False. :type diff: bool, optional :returns: edited string :rtype: str .. py:function:: 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 :rtype: str .. py:function:: reduce_log_print(keep_report, diff, source_content) .. py:function:: minify(source: StubSource, target: StubSource, keep_report: bool = True, diff: bool = False) Minifies and compiles a script .. py:function:: cross_compile(source: StubSource, target: XCompileDest, version: str = '') Runs mpy-cross on a (minified) script .. py:function:: locate_mpy_cross() Locate the path of the mpy-cross commandline tool in the active environment .. py:function:: run_mpy_cross(version: str, source_file, _target) Run mpy-cross using --compat if needed .. py:function:: write_to_temp_file(source: str) Writes a string to a temp file and returns the Path object .. py:function:: get_temp_file(prefix: str = 'mpy_cross_', suffix: str = '.py') Get temp file and returns the Path object