OLD | NEW |
(Empty) | |
| 1 # Copyright (c) 2017 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 """ This code is imported with modifications from |
| 6 '//infra/recipes-py/recipe_engine/env.py' to import protobuf from third_party |
| 7 directory instead of the one installed with current python libraries.""" |
| 8 |
| 9 import contextlib |
| 10 import pkg_resources |
| 11 import os |
| 12 import sys |
| 13 |
| 14 |
| 15 def PrepareProtobuf(): |
| 16 CHROME_SRC = os.path.abspath( |
| 17 os.path.join(os.path.dirname(os.path.realpath(__file__)), |
| 18 "..", "..", "..")) |
| 19 THIRD_PARTY = os.path.join(CHROME_SRC, 'third_party') |
| 20 sys.path.insert(0, os.path.join(THIRD_PARTY, 'protobuf', 'python')) |
| 21 sys.path.insert( |
| 22 1, os.path.join(THIRD_PARTY, 'protobuf', 'third_party', 'six')) |
| 23 |
| 24 @contextlib.contextmanager |
| 25 def temp_sys_path(): |
| 26 orig_path = sys.path[:] |
| 27 try: |
| 28 yield |
| 29 finally: |
| 30 sys.path = orig_path |
| 31 |
| 32 with temp_sys_path(): |
| 33 sys.path = [THIRD_PARTY] |
| 34 sys.modules.pop('google', None) |
| 35 pkg_resources.declare_namespace('google') |
| 36 pkg_resources.fixup_namespace_packages(THIRD_PARTY) |
OLD | NEW |