Use a (mostly) hermetic Python interpreter

It still requires python to be installed on the host to run the wrapper
scripts, but it's close to being fully hermetic.

This also requires/enables the following changes, unfortunately all at
the same time:
 * Use a downloaded f2py
 * Use a downloaded scipy/numpy/matplotlib
 * Fix a few things that don't run with the python version in their #!
 * Stop using bazel-generated __init__.py files, because those interfere
   with importing matplotlib nicely

Change-Id: Ife280464613d67cece9587b7d947f0b1d5466d7e
diff --git a/y2016/BUILD b/y2016/BUILD
index aaab30b..e10be44 100644
--- a/y2016/BUILD
+++ b/y2016/BUILD
@@ -1,139 +1,145 @@
-load('//aos/downloader:downloader.bzl', 'aos_downloader')
+load("//aos/downloader:downloader.bzl", "aos_downloader")
 
 cc_library(
-  name = 'constants',
-  visibility = ['//visibility:public'],
-  srcs = [
-    'constants.cc',
-  ],
-  hdrs = [
-    'constants.h',
-  ],
-  deps = [
-    '//aos/common/logging',
-    '//aos:once',
-    '//aos/common/network:team_number',
-    '//aos/common:mutex',
-    '//frc971/control_loops:state_feedback_loop',
-    '//frc971:shifter_hall_effect',
-    '//frc971:constants',
-    '//y2016/control_loops/drivetrain:polydrivetrain_plants',
-  ],
+    name = "constants",
+    srcs = [
+        "constants.cc",
+    ],
+    hdrs = [
+        "constants.h",
+    ],
+    visibility = ["//visibility:public"],
+    deps = [
+        "//aos:once",
+        "//aos/common:mutex",
+        "//aos/common/logging",
+        "//aos/common/network:team_number",
+        "//frc971:constants",
+        "//frc971:shifter_hall_effect",
+        "//frc971/control_loops:state_feedback_loop",
+        "//y2016/control_loops/drivetrain:polydrivetrain_plants",
+    ],
 )
 
 cc_binary(
-  name = 'joystick_reader',
-  srcs = [
-    'joystick_reader.cc',
-  ],
-  deps = [
-    ':constants',
-    '//aos/common/actions:action_lib',
-    '//aos/common/logging',
-    '//aos/common/util:log_interval',
-    '//aos/common:time',
-    '//aos/input:joystick_input',
-    '//aos/linux_code:init',
-    '//frc971/autonomous:auto_queue',
-    '//frc971/control_loops/drivetrain:drivetrain_queue',
-    '//frc971/queues:gyro',
-    '//y2016/actors:autonomous_action_lib',
-    '//y2016/actors:superstructure_action_lib',
-    '//y2016/actors:vision_align_action_lib',
-    '//y2016/control_loops/shooter:shooter_queue',
-    '//y2016/control_loops/superstructure:superstructure_lib',
-    '//y2016/control_loops/superstructure:superstructure_queue',
-    '//y2016/queues:ball_detector',
-  ],
+    name = "joystick_reader",
+    srcs = [
+        "joystick_reader.cc",
+    ],
+    deps = [
+        ":constants",
+        "//aos/common:time",
+        "//aos/common/actions:action_lib",
+        "//aos/common/logging",
+        "//aos/common/util:log_interval",
+        "//aos/input:joystick_input",
+        "//aos/linux_code:init",
+        "//frc971/autonomous:auto_queue",
+        "//frc971/control_loops/drivetrain:drivetrain_queue",
+        "//frc971/queues:gyro",
+        "//y2016/actors:autonomous_action_lib",
+        "//y2016/actors:superstructure_action_lib",
+        "//y2016/actors:vision_align_action_lib",
+        "//y2016/control_loops/shooter:shooter_queue",
+        "//y2016/control_loops/superstructure:superstructure_lib",
+        "//y2016/control_loops/superstructure:superstructure_queue",
+        "//y2016/queues:ball_detector",
+    ],
 )
 
 aos_downloader(
-  name = 'download',
-  start_srcs = [
-    ':joystick_reader',
-    ':wpilib_interface',
-    '//aos:prime_start_binaries',
-    '//y2016/control_loops/drivetrain:drivetrain',
-    '//y2016/control_loops/superstructure:superstructure',
-    '//y2016/control_loops/shooter:shooter',
-    '//y2016/dashboard:dashboard',
-    '//y2016/actors:autonomous_action',
-    '//y2016/actors:superstructure_action',
-    '//y2016/actors:vision_align_action',
-    '//y2016/vision:target_receiver',
-  ],
-  srcs = [
-    '//aos:prime_binaries',
-  ],
-  dirs = [
-    '//y2016/dashboard:www_files',
-  ],
-  restricted_to = ['//tools:roborio'],
+    name = "download",
+    srcs = [
+        "//aos:prime_binaries",
+    ],
+    dirs = [
+        "//y2016/dashboard:www_files",
+    ],
+    restricted_to = ["//tools:roborio"],
+    start_srcs = [
+        ":joystick_reader",
+        ":wpilib_interface",
+        "//aos:prime_start_binaries",
+        "//y2016/control_loops/drivetrain:drivetrain",
+        "//y2016/control_loops/superstructure:superstructure",
+        "//y2016/control_loops/shooter:shooter",
+        "//y2016/dashboard:dashboard",
+        "//y2016/actors:autonomous_action",
+        "//y2016/actors:superstructure_action",
+        "//y2016/actors:vision_align_action",
+        "//y2016/vision:target_receiver",
+    ],
 )
 
 aos_downloader(
-  name = 'download_stripped',
-  start_srcs = [
-    ':joystick_reader.stripped',
-    ':wpilib_interface.stripped',
-    '//aos:prime_start_binaries_stripped',
-    '//y2016/control_loops/drivetrain:drivetrain.stripped',
-    '//y2016/control_loops/superstructure:superstructure.stripped',
-    '//y2016/control_loops/shooter:shooter.stripped',
-    '//y2016/dashboard:dashboard.stripped',
-    '//y2016/actors:autonomous_action.stripped',
-    '//y2016/actors:superstructure_action.stripped',
-    '//y2016/actors:vision_align_action.stripped',
-    '//y2016/vision:target_receiver.stripped',
-  ],
-  srcs = [
-    '//aos:prime_binaries_stripped',
-  ],
-  dirs = [
-    '//y2016/dashboard:www_files',
-  ],
-  restricted_to = ['//tools:roborio'],
+    name = "download_stripped",
+    srcs = [
+        "//aos:prime_binaries_stripped",
+    ],
+    dirs = [
+        "//y2016/dashboard:www_files",
+    ],
+    restricted_to = ["//tools:roborio"],
+    start_srcs = [
+        ":joystick_reader.stripped",
+        ":wpilib_interface.stripped",
+        "//aos:prime_start_binaries_stripped",
+        "//y2016/control_loops/drivetrain:drivetrain.stripped",
+        "//y2016/control_loops/superstructure:superstructure.stripped",
+        "//y2016/control_loops/shooter:shooter.stripped",
+        "//y2016/dashboard:dashboard.stripped",
+        "//y2016/actors:autonomous_action.stripped",
+        "//y2016/actors:superstructure_action.stripped",
+        "//y2016/actors:vision_align_action.stripped",
+        "//y2016/vision:target_receiver.stripped",
+    ],
 )
 
 cc_binary(
-  name = 'wpilib_interface',
-  srcs = [
-    'wpilib_interface.cc',
-  ],
-  deps = [
-    ':constants',
-    '//aos/common:stl_mutex',
-    '//aos/common/logging',
-    '//aos/common:math',
-    '//aos/common/controls:control_loop',
-    '//aos/common/util:log_interval',
-    '//aos/common:time',
-    '//aos/common/logging:queue_logging',
-    '//aos/common/messages:robot_state',
-    '//aos/common/util:phased_loop',
-    '//aos/common/util:wrapping_counter',
-    '//aos/linux_code:init',
-    '//third_party:wpilib',
-    '//frc971/autonomous:auto_queue',
-    '//frc971/control_loops/drivetrain:drivetrain_queue',
-    '//frc971/control_loops:queues',
-    '//frc971/wpilib:joystick_sender',
-    '//frc971/wpilib:loop_output_handler',
-    '//frc971/wpilib:buffered_pcm',
-    '//frc971/wpilib:gyro_sender',
-    '//frc971/wpilib:dma_edge_counting',
-    '//frc971/wpilib:interrupt_edge_counting',
-    '//frc971/wpilib:wpilib_robot_base',
-    '//frc971/wpilib:encoder_and_potentiometer',
-    '//frc971/wpilib:logging_queue',
-    '//frc971/wpilib:wpilib_interface',
-    '//frc971/wpilib:pdp_fetcher',
-    '//frc971/wpilib:ADIS16448',
-    '//frc971/wpilib:dma',
-    '//y2016/control_loops/drivetrain:polydrivetrain_plants',
-    '//y2016/control_loops/shooter:shooter_queue',
-    '//y2016/control_loops/superstructure:superstructure_queue',
-    '//y2016/queues:ball_detector',
-  ],
-  restricted_to = ['//tools:roborio'],
+    name = "wpilib_interface",
+    srcs = [
+        "wpilib_interface.cc",
+    ],
+    restricted_to = ["//tools:roborio"],
+    deps = [
+        ":constants",
+        "//aos/common:math",
+        "//aos/common:stl_mutex",
+        "//aos/common:time",
+        "//aos/common/controls:control_loop",
+        "//aos/common/logging",
+        "//aos/common/logging:queue_logging",
+        "//aos/common/messages:robot_state",
+        "//aos/common/util:log_interval",
+        "//aos/common/util:phased_loop",
+        "//aos/common/util:wrapping_counter",
+        "//aos/linux_code:init",
+        "//frc971/autonomous:auto_queue",
+        "//frc971/control_loops:queues",
+        "//frc971/control_loops/drivetrain:drivetrain_queue",
+        "//frc971/wpilib:ADIS16448",
+        "//frc971/wpilib:buffered_pcm",
+        "//frc971/wpilib:dma",
+        "//frc971/wpilib:dma_edge_counting",
+        "//frc971/wpilib:encoder_and_potentiometer",
+        "//frc971/wpilib:gyro_sender",
+        "//frc971/wpilib:interrupt_edge_counting",
+        "//frc971/wpilib:joystick_sender",
+        "//frc971/wpilib:logging_queue",
+        "//frc971/wpilib:loop_output_handler",
+        "//frc971/wpilib:pdp_fetcher",
+        "//frc971/wpilib:wpilib_interface",
+        "//frc971/wpilib:wpilib_robot_base",
+        "//third_party:wpilib",
+        "//y2016/control_loops/drivetrain:polydrivetrain_plants",
+        "//y2016/control_loops/shooter:shooter_queue",
+        "//y2016/control_loops/superstructure:superstructure_queue",
+        "//y2016/queues:ball_detector",
+    ],
+)
+
+py_library(
+    name = "python_init",
+    srcs = ["__init__.py"],
+    visibility = ["//visibility:public"],
 )
diff --git a/y2016/__init__.py b/y2016/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/y2016/__init__.py
diff --git a/y2016/control_loops/BUILD b/y2016/control_loops/BUILD
new file mode 100644
index 0000000..de3bfeb
--- /dev/null
+++ b/y2016/control_loops/BUILD
@@ -0,0 +1,6 @@
+py_library(
+    name = "python_init",
+    srcs = ["__init__.py"],
+    visibility = ["//visibility:public"],
+    deps = ["//y2016:python_init"],
+)
diff --git a/y2016/control_loops/__init__.py b/y2016/control_loops/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/y2016/control_loops/__init__.py
diff --git a/y2016/control_loops/python/BUILD b/y2016/control_loops/python/BUILD
index d2a5905..adb3150 100644
--- a/y2016/control_loops/python/BUILD
+++ b/y2016/control_loops/python/BUILD
@@ -1,156 +1,184 @@
-package(default_visibility = ['//y2016:__subpackages__'])
+package(default_visibility = ["//y2016:__subpackages__"])
 
 py_binary(
-  name = 'drivetrain',
-  srcs = [
-    'drivetrain.py',
-  ],
-  deps = [
-    '//external:python-gflags',
-    '//external:python-glog',
-    '//frc971/control_loops/python:drivetrain',
-  ],
-  restricted_to = ['//tools:k8'],
+    name = "drivetrain",
+    srcs = [
+        "drivetrain.py",
+    ],
+    legacy_create_init = False,
+    restricted_to = ["//tools:k8"],
+    deps = [
+        ":python_init",
+        "//external:python-gflags",
+        "//external:python-glog",
+        "//frc971/control_loops/python:drivetrain",
+    ],
 )
 
 py_binary(
-  name = 'polydrivetrain',
-  srcs = [
-    'polydrivetrain.py',
-    'drivetrain.py',
-  ],
-  deps = [
-    '//external:python-gflags',
-    '//external:python-glog',
-    '//frc971/control_loops/python:polydrivetrain',
-  ],
-  restricted_to = ['//tools:k8'],
+    name = "polydrivetrain",
+    srcs = [
+        "drivetrain.py",
+        "polydrivetrain.py",
+    ],
+    legacy_create_init = False,
+    restricted_to = ["//tools:k8"],
+    deps = [
+        ":python_init",
+        "//external:python-gflags",
+        "//external:python-glog",
+        "//frc971/control_loops/python:polydrivetrain",
+    ],
 )
 
 py_library(
-  name = 'polydrivetrain_lib',
-  srcs = [
-    'polydrivetrain.py',
-    'drivetrain.py',
-  ],
-  deps = [
-    '//external:python-gflags',
-    '//external:python-glog',
-    '//frc971/control_loops/python:controls',
-  ],
-  restricted_to = ['//tools:k8'],
+    name = "polydrivetrain_lib",
+    srcs = [
+        "drivetrain.py",
+        "polydrivetrain.py",
+    ],
+    restricted_to = ["//tools:k8"],
+    deps = [
+        "//external:python-gflags",
+        "//external:python-glog",
+        "//frc971/control_loops/python:controls",
+    ],
 )
 
 py_binary(
-  name = 'shooter',
-  srcs = [
-    'shooter.py',
-  ],
-  deps = [
-    '//external:python-gflags',
-    '//external:python-glog',
-    '//frc971/control_loops/python:controls',
-  ],
-  restricted_to = ['//tools:k8'],
+    name = "shooter",
+    srcs = [
+        "shooter.py",
+    ],
+    legacy_create_init = False,
+    restricted_to = ["//tools:k8"],
+    deps = [
+        ":python_init",
+        "//external:python-gflags",
+        "//external:python-glog",
+        "//frc971/control_loops/python:controls",
+        "@matplotlib",
+    ],
 )
 
 py_binary(
-  name = 'intake',
-  srcs = [
-    'intake.py',
-  ],
-  deps = [
-    '//aos/common/util:py_trapezoid_profile',
-    '//external:python-gflags',
-    '//external:python-glog',
-    '//frc971/control_loops/python:controls',
-  ],
-  restricted_to = ['//tools:k8'],
+    name = "intake",
+    srcs = [
+        "intake.py",
+    ],
+    legacy_create_init = False,
+    restricted_to = ["//tools:k8"],
+    deps = [
+        ":python_init",
+        "//aos/common/util:py_trapezoid_profile",
+        "//external:python-gflags",
+        "//external:python-glog",
+        "//frc971/control_loops/python:controls",
+        "@matplotlib",
+    ],
 )
 
 py_binary(
-  name = 'shoulder',
-  srcs = [
-    'shoulder.py',
-  ],
-  deps = [
-    '//aos/common/util:py_trapezoid_profile',
-    '//external:python-gflags',
-    '//external:python-glog',
-    '//frc971/control_loops/python:controls',
-  ],
-  restricted_to = ['//tools:k8'],
+    name = "shoulder",
+    srcs = [
+        "shoulder.py",
+    ],
+    legacy_create_init = False,
+    restricted_to = ["//tools:k8"],
+    deps = [
+        ":python_init",
+        "//aos/common/util:py_trapezoid_profile",
+        "//external:python-gflags",
+        "//external:python-glog",
+        "//frc971/control_loops/python:controls",
+        "@matplotlib",
+    ],
 )
 
 py_binary(
-  name = 'wrist',
-  srcs = [
-    'wrist.py',
-  ],
-  deps = [
-    '//aos/common/util:py_trapezoid_profile',
-    '//external:python-gflags',
-    '//external:python-glog',
-    '//frc971/control_loops/python:controls',
-  ],
-  restricted_to = ['//tools:k8'],
+    name = "wrist",
+    srcs = [
+        "wrist.py",
+    ],
+    legacy_create_init = False,
+    restricted_to = ["//tools:k8"],
+    deps = [
+        ":python_init",
+        "//aos/common/util:py_trapezoid_profile",
+        "//external:python-gflags",
+        "//external:python-glog",
+        "//frc971/control_loops/python:controls",
+        "@matplotlib",
+    ],
 )
 
 py_library(
-  name = 'wrist_lib',
-  srcs = [
-    'wrist.py',
-  ],
-  deps = [
-    '//aos/common/util:py_trapezoid_profile',
-    '//external:python-gflags',
-    '//external:python-glog',
-    '//frc971/control_loops/python:controls',
-  ],
-  restricted_to = ['//tools:k8'],
+    name = "wrist_lib",
+    srcs = [
+        "wrist.py",
+    ],
+    restricted_to = ["//tools:k8"],
+    deps = [
+        "//aos/common/util:py_trapezoid_profile",
+        "//external:python-gflags",
+        "//external:python-glog",
+        "//frc971/control_loops/python:controls",
+    ],
 )
 
 py_library(
-  name = 'shoulder_lib',
-  srcs = [
-    'shoulder.py',
-  ],
-  deps = [
-    '//aos/common/util:py_trapezoid_profile',
-    '//external:python-gflags',
-    '//external:python-glog',
-    '//frc971/control_loops/python:controls',
-  ],
-  restricted_to = ['//tools:k8'],
+    name = "shoulder_lib",
+    srcs = [
+        "shoulder.py",
+    ],
+    restricted_to = ["//tools:k8"],
+    deps = [
+        "//aos/common/util:py_trapezoid_profile",
+        "//external:python-gflags",
+        "//external:python-glog",
+        "//frc971/control_loops/python:controls",
+        "@matplotlib",
+    ],
 )
 
 py_library(
-  name = 'arm_lib',
-  srcs = [
-    'arm.py',
-  ],
-  deps = [
-    ':wrist_lib',
-    ':shoulder_lib',
-    '//external:python-gflags',
-    '//external:python-glog',
-    '//frc971/control_loops/python:controls',
-    '//aos/common/util:py_trapezoid_profile',
-  ],
-  restricted_to = ['//tools:k8'],
+    name = "arm_lib",
+    srcs = [
+        "arm.py",
+    ],
+    restricted_to = ["//tools:k8"],
+    deps = [
+        ":shoulder_lib",
+        ":wrist_lib",
+        "//aos/common/util:py_trapezoid_profile",
+        "//external:python-gflags",
+        "//external:python-glog",
+        "//frc971/control_loops/python:controls",
+        "@matplotlib",
+    ],
 )
+
 py_binary(
-  name = 'arm',
-  srcs = [
-    'arm.py',
-  ],
-  deps = [
-    ':wrist_lib',
-    ':shoulder_lib',
-    '//external:python-gflags',
-    '//external:python-glog',
-    '//frc971/control_loops/python:controls',
-    '//aos/common/util:py_trapezoid_profile',
-  ],
-  restricted_to = ['//tools:k8'],
+    name = "arm",
+    srcs = [
+        "arm.py",
+    ],
+    legacy_create_init = False,
+    restricted_to = ["//tools:k8"],
+    deps = [
+        ":python_init",
+        ":shoulder_lib",
+        ":wrist_lib",
+        "//aos/common/util:py_trapezoid_profile",
+        "//external:python-gflags",
+        "//external:python-glog",
+        "//frc971/control_loops/python:controls",
+    ],
+)
+
+py_library(
+    name = "python_init",
+    srcs = ["__init__.py"],
+    visibility = ["//visibility:public"],
+    deps = ["//y2016/control_loops:python_init"],
 )
diff --git a/y2016/control_loops/python/__init__.py b/y2016/control_loops/python/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/y2016/control_loops/python/__init__.py
diff --git a/y2016/control_loops/python/intake.py b/y2016/control_loops/python/intake.py
index d99160d..02c1ada 100755
--- a/y2016/control_loops/python/intake.py
+++ b/y2016/control_loops/python/intake.py
@@ -5,7 +5,6 @@
 from frc971.control_loops.python import controls
 import numpy
 import sys
-import matplotlib
 from matplotlib import pylab
 import gflags
 import glog
diff --git a/y2016/control_loops/python/wrist.py b/y2016/control_loops/python/wrist.py
index f08f1a2..6de8551 100755
--- a/y2016/control_loops/python/wrist.py
+++ b/y2016/control_loops/python/wrist.py
@@ -4,7 +4,6 @@
 from frc971.control_loops.python import controls
 import numpy
 import sys
-import matplotlib
 from matplotlib import pylab
 import gflags
 import glog