From eb3a900c5c0917343400c34dd932af771ba725d1 Mon Sep 17 00:00:00 2001 From: Cole Faust Date: Thu, 22 Sep 2022 18:25:09 -0700 Subject: Add flag to not add directory of entrypoint to sys.path The python interpreter will by default add the directory of the entrypoint script to the beginning of sys.path. This can be disabled in python 3.11+ (which is not released yet) using the PYTHON_SAFE_PATH environment variable or the -P flag. As a workaround to have this behavior in older python versions, we can make an __soong_entrypoint_redirector__.py file at the root of the zip file that is the entrypoint, and then that file will redirect to the real entrypoint. This brings non-embedded-launcher python modules closer to the embedded launcher version. The embedded launcher binaries already act like this because they start at an __main__.py file at the root of the zip file. Bug: 245583294 Test: m py_dont_import_folder_of_entrypoint_test && out/host/linux-x86/nativetest64/py_dont_import_folder_of_entrypoint_test/py_dont_import_folder_of_entrypoint_test Change-Id: I39aaf04fb19c3ba7f5c9d98220872d6d08abf736 --- python/scripts/main_non_embedded.py | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 python/scripts/main_non_embedded.py (limited to 'python/scripts') diff --git a/python/scripts/main_non_embedded.py b/python/scripts/main_non_embedded.py new file mode 100644 index 000000000..ffbaaa8db --- /dev/null +++ b/python/scripts/main_non_embedded.py @@ -0,0 +1,6 @@ +import runpy + +# The purpose of this file is to implement python 3.11+'s +# PYTHON_SAFE_PATH / -P option on older python versions. + +runpy._run_module_as_main("ENTRY_POINT", alter_argv=False) -- cgit v1.2.3-59-g8ed1b