Python google.__path__() Examples

The following are 9 code examples for showing how to use google.__path__(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module google , or try the search function .

Example 1
Project: luci-py   Author: luci   File: utils.py    License: Apache License 2.0 6 votes vote down vote up
def fix_protobuf_package():
  """Modifies 'google' package to include path to 'google.protobuf' package.

  Prefer our own proto package on the server. Note that this functions is not
  used on the Swarming bot nor any other client.
  """
  if sys.version_info.major != 2:
    # Unnecessary on python3.
    return
  # google.__path__[0] will be google_appengine/google.
  import google
  if len(google.__path__) > 1:
    return

  # We do not mind what 'google' get used, inject protobuf in there.
  path = os.path.join(THIS_DIR, 'third_party', 'protobuf', 'google')
  google.__path__.append(path)

  # six is needed for oauth2client and webtest (local testing).
  six_path = os.path.join(THIS_DIR, 'third_party', 'six')
  if six_path not in sys.path:
    sys.path.insert(0, six_path) 
Example 2
Project: luci-py   Author: luci   File: __main__.py    License: Apache License 2.0 6 votes vote down vote up
def fix_protobuf_package():
  """Ensures that the bundled version of protobuf is used.

  Inspired by components/utils.py
  """
  # In some system, google is preloaded when using runit.py, which is implicitly
  # loaded by using the zip support, as used with swarming_bot.zip. Using
  # 'python -s -S' doesn't work to skip 'import site' in this case. So use the
  # nuclear option, unload the package if found.
  if 'google' in sys.modules:
    del sys.modules['google']
  # Completely zap out preinstalled google. This works because package google
  # itself has no functionality.
  path_to_google = os.path.join(THIS_FILE, 'third_party', 'google')
  import google
  google.__path__.insert(0, path_to_google)
  del google.__path__[1:]

  # Sanity check.
  import google.protobuf
  # pylint: disable=unused-variable
  from google.protobuf import symbol_database


# Then it's safe to import the rest. 
Example 3
Project: luci-py   Author: luci   File: utils.py    License: Apache License 2.0 6 votes vote down vote up
def fix_protobuf_package():
  """Modifies 'google' package to include path to 'google.protobuf' package.

  Prefer our own proto package on the server. Note that this functions is not
  used on the Swarming bot nor any other client.
  """
  if sys.version_info.major != 2:
    # Unnecessary on python3.
    return
  # google.__path__[0] will be google_appengine/google.
  import google
  if len(google.__path__) > 1:
    return

  # We do not mind what 'google' get used, inject protobuf in there.
  path = os.path.join(THIS_DIR, 'third_party', 'protobuf', 'google')
  google.__path__.append(path)

  # six is needed for oauth2client and webtest (local testing).
  six_path = os.path.join(THIS_DIR, 'third_party', 'six')
  if six_path not in sys.path:
    sys.path.insert(0, six_path) 
Example 4
Project: luci-py   Author: luci   File: utils.py    License: Apache License 2.0 6 votes vote down vote up
def fix_protobuf_package():
  """Modifies 'google' package to include path to 'google.protobuf' package.

  Prefer our own proto package on the server. Note that this functions is not
  used on the Swarming bot nor any other client.
  """
  if sys.version_info.major != 2:
    # Unnecessary on python3.
    return
  # google.__path__[0] will be google_appengine/google.
  import google
  if len(google.__path__) > 1:
    return

  # We do not mind what 'google' get used, inject protobuf in there.
  path = os.path.join(THIS_DIR, 'third_party', 'protobuf', 'google')
  google.__path__.append(path)

  # six is needed for oauth2client and webtest (local testing).
  six_path = os.path.join(THIS_DIR, 'third_party', 'six')
  if six_path not in sys.path:
    sys.path.insert(0, six_path) 
Example 5
Project: luci-py   Author: luci   File: utils.py    License: Apache License 2.0 6 votes vote down vote up
def fix_protobuf_package():
  """Modifies 'google' package to include path to 'google.protobuf' package.

  Prefer our own proto package on the server. Note that this functions is not
  used on the Swarming bot nor any other client.
  """
  if sys.version_info.major != 2:
    # Unnecessary on python3.
    return
  # google.__path__[0] will be google_appengine/google.
  import google
  if len(google.__path__) > 1:
    return

  # We do not mind what 'google' get used, inject protobuf in there.
  path = os.path.join(THIS_DIR, 'third_party', 'protobuf', 'google')
  google.__path__.append(path)

  # six is needed for oauth2client and webtest (local testing).
  six_path = os.path.join(THIS_DIR, 'third_party', 'six')
  if six_path not in sys.path:
    sys.path.insert(0, six_path) 
Example 6
Project: datastore-ndb-python   Author: GoogleCloudPlatform   File: google_imports.py    License: Apache License 2.0 5 votes vote down vote up
def set_appengine_imports():
  gae_path = os.getenv('GAE')
  if gae_path is None:
    return

  sys.path.insert(0, gae_path)
  sys.modules.pop('google', None)
  import dev_appserver
  dev_appserver.fix_sys_path()

  if GOOGLE_PACKAGE_PATH is not None:
    import google
    GOOGLE_PACKAGE_PATH.update(google.__path__)
    google.__path__ = list(GOOGLE_PACKAGE_PATH) 
Example 7
Project: luci-py   Author: luci   File: test_env_bot.py    License: Apache License 2.0 5 votes vote down vote up
def setup_test_env():
  """Sets up the environment for bot tests."""
  init_symlinks(BOT_DIR)
  client = os.path.normpath(os.path.join(BOT_DIR, '..', '..', '..', 'client'))
  client_tests = os.path.join(client, 'tests')
  sys.path.insert(0, client_tests)

  tp = os.path.join(BOT_DIR, 'third_party')
  if sys.platform == 'win32':
    # third_party is a symlink.
    with open(tp, 'rb') as f:
      tp = os.path.join(BOT_DIR, f.read())
  sys.path.insert(0, tp)

  # libusb1 expects to be directly in sys.path.
  sys.path.insert(0, os.path.join(BOT_DIR, 'python_libusb1'))

  # For python-rsa.
  sys.path.insert(0, os.path.join(tp, 'rsa'))
  sys.path.insert(0, os.path.join(tp, 'pyasn1'))

  # Protobuf is now used in the bot itself.
  # See fix_protobuf_package() in appengine/components/components/utils.py
  # but until this code, the version under client is used.
  if 'google' in sys.modules:
    # It may be in lib/python2.7/site-packages/google, take not chance and flush
    # it out.
    del sys.modules['google']
  # This should import client/third_party/google
  import google
  google_pkg = os.path.join(client, 'third_party', 'google')
  if google_pkg not in google.__path__:
    google.__path__.insert(0, google_pkg)
  six_path = os.path.join(client, 'third_party', 'six')
  if six_path not in sys.path:
    sys.path.insert(0, six_path)
  sys.path.insert(
      0,
      os.path.join(client, 'third_party', 'httplib2',
                   'python%d' % sys.version_info.major)) 
Example 8
Project: python-compat-runtime   Author: GoogleCloudPlatform   File: google_imports.py    License: Apache License 2.0 5 votes vote down vote up
def set_appengine_imports():
  gae_path = os.getenv('GAE')
  if gae_path is None:
    return

  sys.path.insert(0, gae_path)
  sys.modules.pop('google', None)
  import dev_appserver
  dev_appserver.fix_sys_path()

  if GOOGLE_PACKAGE_PATH is not None:
    import google
    GOOGLE_PACKAGE_PATH.update(google.__path__)
    google.__path__ = list(GOOGLE_PACKAGE_PATH) 
Example 9
Project: rules_pyz   Author: TriggerMail   File: import_site_packages.py    License: Apache License 2.0 5 votes vote down vote up
def fail(module_name):
    global _failed
    sys.stderr.write('FAIL: import %s: expected import error\n' % (module_name))
    print 'google:', google.__path__
    _failed = True