isolated_python¶
Intro¶
When python imports non-standard module, it must import it from the dedicated venv.
The protoprimer is designed to work in isolated environment sharing no non-standard packages.
This allows multiple independent deployments on the same host for the same user.
It covers both app & lib cases (see app_vs_lib) -
any import of non-standard python packages must be guaranteed to be from dedicated venv.
The only exception to this rule is proto_code (see proto_code) -
see CASE_3 below.
Approach¶
The general approach is to always switch python to isolated mode (see python -I).
This also solves the problem of unnecessary python restart to obtain the path to proto_code.
CASE_1: lib starting from entry_script¶
The protoprimer used as lib requires entry_script-s to be aware of the relative path to proto_code.
The entry_script imports proto_code module (file) via that relative path.
Then, it initiates python switch sequence.
See also lib_access_to_config_data.
CASE_2: app starting from entry_script¶
This is similar to CASE_1.
Apart from different main functions (they are different all lib and app cases),
the only difference from lib is that app properly bootstraps all states.
In particular, app creates and populates venv (if needed),
while lib assumes it is already bootstrapped and fails if not.
CASE_3: app starting directly from proto_code¶
This is an exception:
The
proto_codeis the opposite - it must not be fromvenv.Moreover, it must also not be from non-
venvsharedsite-packages(e.g.~/.local/lib).
Diagram¶
TODO: add mermaid diagram with transitions of python processes.