From 0f07afea4acda58443c7694105037756e41c0622 Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Tue, 30 May 2023 18:55:58 +0000 Subject: [PATCH] fix: make `import python.runfiles` work with `--experimental_python_import_all_repositories=false` Because `--experimental_python_import_all_repositories` defaults to true, every repository is added sys.path. This makes `import python.runfiles` work. However, reccomend wepople disable that behavior because it results in extremely long sys.path. With that flag disabled, we have to manually add the rules_python repo root back to sys.path so that `import python.runfiles` still works. --- python/runfiles/BUILD.bazel | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/python/runfiles/BUILD.bazel b/python/runfiles/BUILD.bazel index 3a93d40f32..c6cfc2fa94 100644 --- a/python/runfiles/BUILD.bazel +++ b/python/runfiles/BUILD.bazel @@ -27,6 +27,11 @@ py_library( "__init__.py", "runfiles.py", ], + imports = [ + # Add the repo root so `import python.runfiles.runfiles` works. This makes it agnostic + # to the --experimental_python_import_all_repositories setting. + "../..", + ], visibility = ["//visibility:public"], )