Add flag to not add top-level modules to PYTHONPATH

stub_template_host.txt added all the top-level modules to the
PYTHONPATH, which isn't correct, and caused absl.logging to
override the built-in logging module.

Removing this also makes it more consistent with python binaries
built with embedded_launcher: true. embedded_launcher: true
binaries don't add the top-level modules.

Fixes: 245583294
Test: m py_dont_add_top_level_dirs_test && out/host/linux-x86/testcases/py_dont_add_top_level_dirs_test/x86_64/py_dont_add_top_level_dirs_test
Change-Id: Id3069565d2b2c4b2bda0ff5301e757a7b4201751
This commit is contained in:
Cole Faust
2022-09-14 15:25:15 -07:00
parent 9d75168276
commit af4b13dbe4
8 changed files with 68 additions and 80 deletions

View File

@@ -0,0 +1,17 @@
import unittest
import sys
print(sys.path, file=sys.stderr)
class TestProtoWithPkgPath(unittest.TestCase):
def test_cant_import_mymodule_directly(self):
with self.assertRaises(ImportError):
import mymodule
def test_can_import_mymodule_by_parent_package(self):
import mypkg.mymodule
if __name__ == '__main__':
unittest.main()