============ Python Tools ============ .. default-domain:: bash .. file:: python_tools.bsh Functions to help communicate with python .. function:: array_to_python_ast_list_of_strings :Arguments: * ``$1`` - Variable to set result to. If the destination is an array, it will be unset (and become global) * [``$2``...] - Array elements (to be treated as strings) Set ``$1`` to a python ast.literal_eval compliant string for an list of strings .. rubric:: Example .. code-block:: bash array_to_python_ast_list_of_strings x 1 '1"1' "2'2" stuff # x=["1", "1\"1", "2'2", "stuff"] .. function:: array_to_python_ast_list_of_literals :Arguments: * ``$1`` - Variable to set result to. If the destination is an array, it will be unset (and become global) * [``$2``...] - Array elements (to be treated literally) Set ``$1`` to a python ast.literal_eval compliant string representing a "list of strings" .. rubric:: Example .. code-block:: bash array_to_python_ast_list_of_literals x 1 '"1\"1"' "\"2'2\"" 3.3 # x=[1, "1\"1", "2'2", 3.3] array_to_python_ast_list_of_literals x 1+1 # x=[1+1], valid for python eval, but not ast.literal_eval array_to_python_ast_list_of_literals x "$((1+1))" # x=[2], valid for ast.literal_eval .. function:: vsi::python::virtualenv_bin :Arguments: * ``$1`` - Virtual environment path, do not include ``bin`` or ``Scripts`` * ``$2`` - Name of binary to run, without ``.exe`` extension A cross-OS compatible function to call a binary in a virtual environment folder that handles the differences between Windows and Linux. .. rubric:: Example .. code-block:: bash "$(vsi::python::virtualenv_bin "${my_python_dir}" pip)" install numpy