
import os
import sys

# Add the third_party/ dir to our search path so that we can find the
# modules in there automatically.  This isn't normal, so don't replicate
# this pattern elsewhere.
_third_party = os.path.normpath(os.path.join(os.path.dirname(os.path.realpath(
    __file__)), 'third_party'))
sys.path.insert(0, _third_party)

# List of third_party packages that might need subpaths added to search.
_paths = [
    'pyelftools',
]
for _path in _paths:
  sys.path.insert(1, os.path.join(_third_party, _path))



import os
import sys

# Add the third_party/ dir to our search path so that we can find the
# modules in there automatically.  This isn't normal, so don't replicate
# this pattern elsewhere.
_chromite_dir = os.path.normpath(os.path.dirname(os.path.realpath(__file__)))
_containing_dir = os.path.dirname(_chromite_dir)
_third_party_dirs = [os.path.join(_chromite_dir, 'third_party')]
# If chromite is living inside the Chrome checkout under
# <chrome_root>/src/third_party/chromite, its dependencies will be checked out
# to <chrome_root>/src/third_party instead of the normal chromite/third_party
# location due to git-submodule limitations (a submodule cannot be contained
# inside another submodule's workspace), so we want to add that to the
# search path.
if os.path.basename(_containing_dir) == 'third_party':
  _third_party_dirs.append(_containing_dir)

# List of third_party packages that might need subpaths added to search.
_paths = [
   'pyelftools',
]

for _path in _paths:
  for _third_party in _third_party_dirs[:]:
    _component = os.path.join(_third_party, _path)
    if os.path.isdir(_component):
      _third_party_dirs.append(_component)
sys.path = _third_party_dirs + sys.path

Add <chrome>/src/third_party dir to PYTHONPATH for Chrome checkouts.
Add <chrome>/src/third_party dir to PYTHONPATH for Chrome checkouts.

If chromite is living inside the Chrome checkout under
<chrome_root>/src/third_party/chromite, its dependencies will be
checked out to <chrome_root>/src/third_party instead of the normal
chromite/third_party location due to git-submodule limitations (a
submodule cannot be contained inside another submodule's workspace),
so we want to add that to the search path.

BUG=None
TEST=Local

Change-Id: I10a12bcddc88e509c1c7015a95c54d578fb8b122
Reviewed-on: https://gerrit.chromium.org/gerrit/43066
Reviewed-by: Mike Frysinger <8f3f75c74bd5184edcfa6534cab3c13a00a2f794@chromium.org>
Commit-Queue: Ryan Cui <5ce1592d53754a87a44fc2eb7b63d5f77cf50fdb@chromium.org>
Tested-by: Ryan Cui <5ce1592d53754a87a44fc2eb7b63d5f77cf50fdb@chromium.org>

  
  import os
  import sys
  
  # Add the third_party/ dir to our search path so that we can find the
  # modules in there automatically.  This isn't normal, so don't replicate
  # this pattern elsewhere.
- _third_party = os.path.normpath(os.path.join(os.path.dirname(os.path.realpath(
-     __file__)), 'third_party'))
- sys.path.insert(0, _third_party)
+ _chromite_dir = os.path.normpath(os.path.dirname(os.path.realpath(__file__)))
+ _containing_dir = os.path.dirname(_chromite_dir)
+ _third_party_dirs = [os.path.join(_chromite_dir, 'third_party')]
+ # If chromite is living inside the Chrome checkout under
+ # <chrome_root>/src/third_party/chromite, its dependencies will be checked out
+ # to <chrome_root>/src/third_party instead of the normal chromite/third_party
+ # location due to git-submodule limitations (a submodule cannot be contained
+ # inside another submodule's workspace), so we want to add that to the
+ # search path.
+ if os.path.basename(_containing_dir) == 'third_party':
+   _third_party_dirs.append(_containing_dir)
  
  # List of third_party packages that might need subpaths added to search.
  _paths = [
-     'pyelftools',
+    'pyelftools',
  ]
+ 
  for _path in _paths:
-   sys.path.insert(1, os.path.join(_third_party, _path))
+   for _third_party in _third_party_dirs[:]:
+     _component = os.path.join(_third_party, _path)
+     if os.path.isdir(_component):
+       _third_party_dirs.append(_component)
+ sys.path = _third_party_dirs + sys.path
  
- 
Add <chrome>/src/third_party dir to PYTHONPATH for Chrome checkouts.
## Code Before:

import os
import sys

# Add the third_party/ dir to our search path so that we can find the
# modules in there automatically.  This isn't normal, so don't replicate
# this pattern elsewhere.
_third_party = os.path.normpath(os.path.join(os.path.dirname(os.path.realpath(
    __file__)), 'third_party'))
sys.path.insert(0, _third_party)

# List of third_party packages that might need subpaths added to search.
_paths = [
    'pyelftools',
]
for _path in _paths:
  sys.path.insert(1, os.path.join(_third_party, _path))


## Instruction:
Add <chrome>/src/third_party dir to PYTHONPATH for Chrome checkouts.
## Code After:

import os
import sys

# Add the third_party/ dir to our search path so that we can find the
# modules in there automatically.  This isn't normal, so don't replicate
# this pattern elsewhere.
_chromite_dir = os.path.normpath(os.path.dirname(os.path.realpath(__file__)))
_containing_dir = os.path.dirname(_chromite_dir)
_third_party_dirs = [os.path.join(_chromite_dir, 'third_party')]
# If chromite is living inside the Chrome checkout under
# <chrome_root>/src/third_party/chromite, its dependencies will be checked out
# to <chrome_root>/src/third_party instead of the normal chromite/third_party
# location due to git-submodule limitations (a submodule cannot be contained
# inside another submodule's workspace), so we want to add that to the
# search path.
if os.path.basename(_containing_dir) == 'third_party':
  _third_party_dirs.append(_containing_dir)

# List of third_party packages that might need subpaths added to search.
_paths = [
   'pyelftools',
]

for _path in _paths:
  for _third_party in _third_party_dirs[:]:
    _component = os.path.join(_third_party, _path)
    if os.path.isdir(_component):
      _third_party_dirs.append(_component)
sys.path = _third_party_dirs + sys.path
