From 12988dac750d1ba7a84511eb8f5a7de77901877d Mon Sep 17 00:00:00 2001 From: Brian Patton Date: Mon, 9 Sep 2019 13:01:38 -0700 Subject: [PATCH] Pop the script directory from sys.path. Quoting http://python-notes.curiousefficiency.org/en/latest/python_concepts/import_traps.html#the-double-import-trap: """ There?s a reason the general ?no package directories on sys.path? guideline exists, and the fact that the interpreter itself doesn?t follow it when determining sys.path[0] is the root cause of all sorts of grief. """ Also relevant: https://github.com/bazelbuild/bazel/issues/7091 This is addressed toward issue #539 PiperOrigin-RevId: 268058051 --- .../python/experimental/substrates/numpy/rewrite.py | 6 ++++++ .../python/internal/backend/numpy/gen_linear_operators.py | 8 ++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/tensorflow_probability/python/experimental/substrates/numpy/rewrite.py b/tensorflow_probability/python/experimental/substrates/numpy/rewrite.py index a138b844c3..f7a1c742fc 100644 --- a/tensorflow_probability/python/experimental/substrates/numpy/rewrite.py +++ b/tensorflow_probability/python/experimental/substrates/numpy/rewrite.py @@ -18,11 +18,17 @@ from __future__ import division from __future__ import print_function +import sys +if not sys.path[0].endswith('.runfiles'): + sys.path.pop(0) + +# pylint: disable=g-import-not-at-top,g-bad-import-order import collections # Dependency imports from absl import app from absl import flags +# pylint: enable=g-import-not-at-top,g-bad-import-order flags.DEFINE_boolean('numpy_to_jax', False, 'Whether or not to rewrite numpy imports to jax.numpy') diff --git a/tensorflow_probability/python/internal/backend/numpy/gen_linear_operators.py b/tensorflow_probability/python/internal/backend/numpy/gen_linear_operators.py index 6c9b11202d..8eb9943b84 100644 --- a/tensorflow_probability/python/internal/backend/numpy/gen_linear_operators.py +++ b/tensorflow_probability/python/internal/backend/numpy/gen_linear_operators.py @@ -18,14 +18,18 @@ from __future__ import division from __future__ import print_function +import sys +if not sys.path[0].endswith('.runfiles'): + sys.path.pop(0) + +# pylint: disable=g-import-not-at-top,g-bad-import-order import importlib import inspect import re -# Dependency imports - from absl import app from absl import flags +# pylint: enable=g-import-not-at-top,g-bad-import-order FLAGS = flags.FLAGS