Fix matplotlib sandboxing

This appears to fix plotting with matplotlib in python3.  This lets
things like //y2020/control_loops/python:finisher --plot work.

Change-Id: I8ff1c91cf078e3aa8b4d5660881c22c8de66f051
Signed-off-by: Austin Schuh <austin.linux@gmail.com>
diff --git a/debian/matplotlib.BUILD b/debian/matplotlib.BUILD
index 881521c..ad44398 100644
--- a/debian/matplotlib.BUILD
+++ b/debian/matplotlib.BUILD
@@ -2,10 +2,5 @@
 
 build_matplotlib(
     "3",
-    tkinter_py_version = "3.5",
-)
-
-build_matplotlib(
-    "2.7",
-    copy_shared_files = False,
+    tkinter_py_version = "3.7",
 )
diff --git a/debian/matplotlib.bzl b/debian/matplotlib.bzl
index d94efd9..3ae0786 100644
--- a/debian/matplotlib.bzl
+++ b/debian/matplotlib.bzl
@@ -185,11 +185,19 @@
         name = "matplotlib" + version,
         srcs = _src_copied + [
             version + "/matplotlib/__init__.py",
-        ],
+        ] + native.glob(
+            include = ["usr/lib/python" + tkinter_py_version + "/**/*.py"],
+        ),
         data = _data_files + _builtin_so_copied + _system_so_copied + [
             ":usr/share/matplotlib/mpl-data/matplotlibrc",
-        ] + native.glob(["etc/**"]),
-        imports = ["usr/lib/python" + version + "/dist-packages", version, "."],
+        ] + native.glob(["etc/**", "usr/share/fonts/**"]),
+        imports = [
+            "rpathed3/usr/lib/python" + version + "/dist-packages",
+            "rpathed3/usr/lib/python" + version + ".7/lib-dynload",
+            version,
+            ".",
+            "usr/lib/python" + tkinter_py_version,
+        ],
         target_compatible_with = ["@platforms//cpu:x86_64"],
         visibility = ["//visibility:public"],
     )
diff --git a/debian/matplotlib_init.patch b/debian/matplotlib_init.patch
index 4cc155a..2818cd6 100644
--- a/debian/matplotlib_init.patch
+++ b/debian/matplotlib_init.patch
@@ -26,7 +26,7 @@
 +
 +# Tell fontconfig where to find matplotlib's sandboxed font files.
 +os.environ["FONTCONFIG_PATH"] = os.path.join(_matplotlib_base, "etc/fonts")
-+os.environ["FONTCONFIG_FILE"] = os.path.join(_matplotlib_base, "etc/fonts/fonts.conf")
++os.environ["FONTCONFIG_FILE"] = "fonts.conf"
 +os.environ["FONTCONFIG_SYSROOT"] = _matplotlib_base
 +
  try:
diff --git a/frc971/control_loops/python/BUILD b/frc971/control_loops/python/BUILD
index b6290d4..a4b8fb8 100644
--- a/frc971/control_loops/python/BUILD
+++ b/frc971/control_loops/python/BUILD
@@ -112,6 +112,7 @@
         ":drivetrain",
         ":python_init",
         "//external:python-glog",
+        "@matplotlib_repo//:matplotlib3",
     ],
 )
 
diff --git a/y2021_bot3/control_loops/python/BUILD b/y2021_bot3/control_loops/python/BUILD
index 7ade878..15dacaa 100644
--- a/y2021_bot3/control_loops/python/BUILD
+++ b/y2021_bot3/control_loops/python/BUILD
@@ -5,8 +5,10 @@
     srcs = [
         "drivetrain.py",
     ],
+    legacy_create_init = False,
     target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
+        ":python_init",
         "//external:python-gflags",
         "//external:python-glog",
         "//frc971/control_loops/python:drivetrain",
@@ -19,8 +21,10 @@
         "drivetrain.py",
         "polydrivetrain.py",
     ],
+    legacy_create_init = False,
     target_compatible_with = ["@platforms//cpu:x86_64"],
     deps = [
+        ":python_init",
         "//external:python-gflags",
         "//external:python-glog",
         "//frc971/control_loops/python:polydrivetrain",
@@ -43,3 +47,11 @@
         "//frc971/control_loops/python:polydrivetrain",
     ],
 )
+
+py_library(
+    name = "python_init",
+    srcs = ["__init__.py"],
+    target_compatible_with = ["@platforms//os:linux"],
+    visibility = ["//visibility:public"],
+    deps = ["//y2020/control_loops:python_init"],
+)
diff --git a/y2021_bot3/control_loops/python/__init__.py b/y2021_bot3/control_loops/python/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/y2021_bot3/control_loops/python/__init__.py