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 <hedger@users.noreply.github.com>
This commit is contained in:
ghettorce 2022-09-24 14:30:19 +03:00 committed by GitHub
parent 6d2b0a3b6c
commit eadd7801af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 36 additions and 3 deletions

View File

@ -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")

View File

@ -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__":

View File

@ -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%"

View File

@ -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:-""}";

View File

@ -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