mypythontools_cicd.build_app package

This module build the app via pyinstaller. It has presets to build applications build with eel.

There is one main function build_with_pyinstaller. Check it’s help for how to use it (should be very simple).

Note

You can run build for example from vs code tasks. Just create folder utils, create build_script.py inside, add

>>> import mypythontools
...
>>> if __name__ == "__main__":
...     mypythontools.build_app.build_with_pyinstaller()  # With all the params you need.

In VS Code you can add this task to global tasks.json to run it with anytime:

{
    "label": "Build app",
    "type": "shell",
    "command": "python",
    "args": ["${workspaceFolder}/utils/build_script.py"],
    "presentation": {
        "reveal": "always",
        "panel": "new"
    }
},
mypythontools_cicd.build_app.build_with_pyinstaller(root_path: None | str | Path = None, main_file: str | Path = 'app.py', preset: Literal['eel', None] = None, web_path: None | str | Path = None, build_web: bool | str = 'preset', virtualenv: None | PathLike = '/home/docs/checkouts/readthedocs.org/user_builds/mypythontools-cicd/envs/latest', sync_requirements: None | Literal['infer'] | PathLike | Sequence[PathLike] = 'infer', remove_last_build: bool = False, console: bool = True, debug: bool = False, icon: str | Path | None = None, hidden_imports: None | list[str] = None, ignored_packages: None | list[str] = None, datas: None | list[tuple[str, str]] = None, env_vars: None | dict = None, name: None | str = None, clean: bool = True, verbosity: Literal[0, 1, 2] = 1) None[source]

One script to build .exe app from source code on windows.

This script automatically generate .spec file, build node web files and add environment variables during build.

This script suppose some structure of the app (may have way different though). You can use project-starter from the same repository, if you start with application.

Parameters
  • root_path (None | str | Path, optional) – Path of root folder where build and dist folders will be placed. If None, path is inferred. Defaults to None.

  • main_file (str, optional) – Main file path or name with extension. Main file is found automatically and don’t have to be in root. Defaults to ‘app.py’.

  • preset (Literal['eel', None], optional) – Edit other params for specific use cases (append to hidden_imports, datas etc.). Defaults to None.

  • web_path (None | str | Path, optional) – If using eel preset it’s folder with index.html. If None, path is inferred. Defaults to None.

  • build_web (bool | str, optional) – If application contain package.json build node application. If ‘preset’ build automatically depending on preset. Defaults to ‘preset’.

  • virtualenv (None | PathLike, optional) – Whether run in virtualenv. If you want to use current venv, use sys.prefix. Defaults to sys.prefix.

  • sync_requirements (None | Literal["infer"] | PathLike | Sequence[PathLike], optional) – If using virtualenv define what libraries will be installed by path to requirements.txt. Can also be a list of more files e.g [“requirements.txt”, “requirements_dev.txt”]. If “infer”, autodetected (all requirements). Defaults to “infer”.

  • remove_last_build (bool, optional) – If some problems, it is possible to delete build and dist folders. Defaults to False.

  • console (bool, optional) – Before app run terminal window appears (good for debugging). Defaults to False.

  • debug (bool, optional) – If no console, then dialog window with traceback appears. Defaults to False.

  • icon (None | str | Path, optional) – Path or name with extension to .ico file (!no png!). Defaults to None.

  • hidden_imports (None | list, optional) – If app is not working, it can be because some library was not builded. Add such libraries into this list. Defaults to None.

  • ignored_packages (None | list, optional) – Libraries take space even if not necessary. Defaults to None.

  • datas (None | list[tuple[str, str], optional) – Add static files to build. Example: [(‘my_source_path, ‘destination_path’)]. Defaults to None.

  • env_vars (None | dict, optional) – Add some env vars during build. Mostly to tell main script that it’s production (ne development) mode. Defaults to None.

  • name (None | str, optional) – If name of app is different than main py file. Defaults to None.

  • clean (bool, optional) – Remove spec file and var env py hook. Defaults to True.

  • verbosity (Literal[0, 1, 2], optional) – How much information print to console. 0 prints just errors, 1 prints when starting new step, 2 prints every stdout to console. Defaults to 1.

Note

Build pyinstaller bootloader on your pc, otherwise antivirus can check the file for a while on first run and even alert false positive.

Download from github, cd to bootloader and:

python ./waf all

Back to pyinstaller folder and python setup.py