Skip to content

Commit

Permalink
Pop the script directory from sys.path.
Browse files Browse the repository at this point in the history
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: bazelbuild/bazel#7091

This is addressed toward issue tensorflow#539

PiperOrigin-RevId: 268058051
  • Loading branch information
brianwa84 committed Sep 30, 2019
1 parent cf6a559 commit 12988da
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 12988da

Please sign in to comment.