Prevent Python from importing the host's pip packages
This patch prevents Python from searching the user's installed pip
packages as well as the host's `site` package. The host's `site`
package normally performs the setup necessary to allow importing
globally installed pip packages. We don't want that.
From the upstream documentation:
https://docs.python.org/3/using/cmdline.html
-s
Don’t add the user site-packages directory to sys.path.
See also PEP 370 – Per user site-packages directory
-S
Disable the import of the module site and the
site-dependent manipulations of sys.path that it
entails. Also disable these manipulations if site is
explicitly imported later (call site.main() if you
want them to be triggered).
Change-Id: I11a64c33920fc174dd8ac5d200e2e8550a3c084a
Signed-off-by: Philipp Schrader <philipp.schrader@gmail.com>
diff --git a/debian/opencv_python.BUILD b/debian/opencv_python.BUILD
index 5afa180..5074bd3 100644
--- a/debian/opencv_python.BUILD
+++ b/debian/opencv_python.BUILD
@@ -5,6 +5,9 @@
include = ["**/*"],
exclude = ["**/*.py"],
),
+ deps = [
+ "@python_repo//:numpy",
+ ],
imports = ["."],
visibility = ["//visibility:public"],
)
diff --git a/debian/python.BUILD b/debian/python.BUILD
index 17543df..009a7e2 100644
--- a/debian/python.BUILD
+++ b/debian/python.BUILD
@@ -55,11 +55,45 @@
visibility = ["//visibility:public"],
)
-filegroup(
+py_library(
name = "scipy",
srcs = glob([
- "usr/lib/python3/dist-packages/numpy",
- "usr/lib/python3/dist-packages/scipy",
+ "usr/lib/python3/dist-packages/scipy/**/*.py",
+ ]),
+ data = glob([
+ "usr/lib/python3/dist-packages/scipy/**/*",
+ ], exclude = [
+ "usr/lib/python3/dist-packages/scipy/**/*.py",
+ ]),
+ deps = [
+ ":numpy",
+ ],
+ visibility = ["//visibility:public"],
+ imports = [
+ "usr/lib/python3/dist-packages",
+ ],
+ target_compatible_with = [
+ "@platforms//os:linux",
+ "@platforms//cpu:x86_64",
+ ],
+)
+
+py_library(
+ name = "numpy",
+ srcs = glob([
+ "usr/lib/python3/dist-packages/numpy/**/*.py",
+ ]),
+ data = glob([
+ "usr/lib/python3/dist-packages/numpy/**/*",
+ ], exclude = [
+ "usr/lib/python3/dist-packages/numpy/**/*.py",
]),
visibility = ["//visibility:public"],
+ imports = [
+ "usr/lib/python3/dist-packages",
+ ],
+ target_compatible_with = [
+ "@platforms//os:linux",
+ "@platforms//cpu:x86_64",
+ ],
)