From eadd7801afea681841ea1a2ba28e1e64d819977f Mon Sep 17 00:00:00 2001 From: ghettorce <799240+ghettorce@users.noreply.github.com> Date: Sat, 24 Sep 2022 14:30:19 +0300 Subject: [PATCH] fbt: exclude user site-packages directory from sys.path (#1778) * fbt: exclude user site-packages directory from sys.path * fbt: python path fixes for *nix * fbt: fixed cli target on Windows Co-authored-by: hedger --- scripts/flipper/utils/cdc.py | 2 +- scripts/serial_cli.py | 14 +++++++++++++- scripts/toolchain/fbtenv.cmd | 1 + scripts/toolchain/fbtenv.sh | 13 +++++++++++++ site_scons/environ.scons | 9 ++++++++- 5 files changed, 36 insertions(+), 3 deletions(-) diff --git a/scripts/flipper/utils/cdc.py b/scripts/flipper/utils/cdc.py index 081705cc..7047db2a 100644 --- a/scripts/flipper/utils/cdc.py +++ b/scripts/flipper/utils/cdc.py @@ -14,4 +14,4 @@ def resolve_port(logger, portname: str = "auto"): logger.error("Failed to find connected Flipper") elif len(flippers) > 1: logger.error("More than one Flipper is attached") - logger.error("Failed to guess which port to use. Specify --port") + logger.error("Failed to guess which port to use") diff --git a/scripts/serial_cli.py b/scripts/serial_cli.py index e07e6bfb..441bc7cc 100644 --- a/scripts/serial_cli.py +++ b/scripts/serial_cli.py @@ -1,13 +1,25 @@ import logging import subprocess from flipper.utils.cdc import resolve_port +import os +import sys def main(): logger = logging.getLogger() if not (port := resolve_port(logger, "auto")): + logger.error("Is Flipper connected over USB and isn't in DFU mode?") return 1 - subprocess.call(["python3", "-m", "serial.tools.miniterm", "--raw", port, "230400"]) + subprocess.call( + [ + os.path.basename(sys.executable), + "-m", + "serial.tools.miniterm", + "--raw", + port, + "230400", + ] + ) if __name__ == "__main__": diff --git a/scripts/toolchain/fbtenv.cmd b/scripts/toolchain/fbtenv.cmd index 1403837d..5eaf16f9 100644 --- a/scripts/toolchain/fbtenv.cmd +++ b/scripts/toolchain/fbtenv.cmd @@ -32,6 +32,7 @@ if not "%REAL_TOOLCHAIN_VERSION%" == "%FLIPPER_TOOLCHAIN_VERSION%" ( set "HOME=%USERPROFILE%" set "PYTHONHOME=%FBT_TOOLCHAIN_ROOT%\python" set "PYTHONPATH=" +set "PYTHONNOUSERSITE=1" set "PATH=%FBT_TOOLCHAIN_ROOT%\python;%FBT_TOOLCHAIN_ROOT%\bin;%FBT_TOOLCHAIN_ROOT%\protoc\bin;%FBT_TOOLCHAIN_ROOT%\openocd\bin;%PATH%" set "PROMPT=(fbt) %PROMPT%" diff --git a/scripts/toolchain/fbtenv.sh b/scripts/toolchain/fbtenv.sh index f68e4c0b..7c501803 100755 --- a/scripts/toolchain/fbtenv.sh +++ b/scripts/toolchain/fbtenv.sh @@ -40,6 +40,13 @@ fbtenv_restore_env() elif [ -n "${PROMPT:-""}" ]; then PROMPT="$(echo "$PROMPT" | sed 's/\[fbt\]//g')"; fi + + PYTHONNOUSERSITE="$SAVED_PYTHONNOUSERSITE"; + PYTHONPATH="$SAVED_PYTHONPATH"; + + unset SAVED_PYTHONNOUSERSITE; + unset SAVED_PYTHONPATH; + unset SCRIPT_PATH; unset FBT_TOOLCHAIN_VERSION; unset FBT_TOOLCHAIN_PATH; @@ -276,6 +283,12 @@ fbtenv_main() PATH="$TOOLCHAIN_ARCH_DIR/bin:$PATH"; PATH="$TOOLCHAIN_ARCH_DIR/protobuf/bin:$PATH"; PATH="$TOOLCHAIN_ARCH_DIR/openocd/bin:$PATH"; + + SAVED_PYTHONNOUSERSITE="${PYTHONNOUSERSITE:-""}"; + SAVED_PYTHONPATH="${PYTHONPATH:-""}"; + + PYTHONNOUSERSITE=1; + PYTHONPATH=; } fbtenv_main "${1:-""}"; diff --git a/site_scons/environ.scons b/site_scons/environ.scons index 99d4cc0b..c61f2961 100644 --- a/site_scons/environ.scons +++ b/site_scons/environ.scons @@ -12,7 +12,14 @@ forward_os_env = { "PATH": os.environ["PATH"], } # Proxying CI environment to child processes & scripts -for env_value_name in ("WORKFLOW_BRANCH_OR_TAG", "DIST_SUFFIX", "HOME", "APPDATA"): +for env_value_name in ( + "WORKFLOW_BRANCH_OR_TAG", + "DIST_SUFFIX", + "HOME", + "APPDATA", + "PYTHONHOME", + "PYTHONNOUSERSITE", +): if environ_value := os.environ.get(env_value_name, None): forward_os_env[env_value_name] = environ_value