| OLD | NEW |
| 1 # Copyright 2016 The LUCI Authors. All rights reserved. | 1 # Copyright 2016 The LUCI Authors. All rights reserved. |
| 2 # Use of this source code is governed under the Apache License, Version 2.0 | 2 # Use of this source code is governed under the Apache License, Version 2.0 |
| 3 # that can be found in the LICENSE file. | 3 # that can be found in the LICENSE file. |
| 4 | 4 |
| 5 """Sets up recipe engine Python environment.""" | 5 """Sets up recipe engine Python environment.""" |
| 6 | 6 |
| 7 import contextlib | 7 import contextlib |
| 8 import os | 8 import os |
| 9 import sys | 9 import sys |
| 10 | 10 |
| 11 # Hook up our third party vendored packages. | 11 # Hook up our third party vendored packages. |
| 12 BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | 12 BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
| 13 THIRD_PARTY = os.path.join(BASE_DIR, 'recipe_engine', 'third_party') | 13 THIRD_PARTY = os.path.join(BASE_DIR, 'recipe_engine', 'third_party') |
| 14 | 14 |
| 15 # Real path manipulation. | 15 # Real path manipulation. |
| 16 sys.path = [ | 16 sys.path = [ |
| 17 os.path.join(THIRD_PARTY), | 17 os.path.join(THIRD_PARTY), |
| 18 os.path.join(THIRD_PARTY, 'requests'), | 18 os.path.join(THIRD_PARTY, 'requests'), |
| 19 os.path.join(THIRD_PARTY, 'six'), | 19 os.path.join(THIRD_PARTY, 'six'), |
| 20 os.path.join(THIRD_PARTY, 'client-py'), | 20 os.path.join(THIRD_PARTY, 'client-py'), |
| 21 os.path.join(THIRD_PARTY, 'mock-1.0.1'), | 21 os.path.join(THIRD_PARTY, 'mock-1.0.1'), |
| 22 os.path.join(THIRD_PARTY, 'astunparse'), |
| 22 ] + sys.path | 23 ] + sys.path |
| 23 | 24 |
| 24 # Hack up our "pkg_resources" to import our local protobuf instead of the system | 25 # Hack up our "pkg_resources" to import our local protobuf instead of the system |
| 25 # one. | 26 # one. |
| 26 # | 27 # |
| 27 # As per https://github.com/google/protobuf/issues/1484: | 28 # As per https://github.com/google/protobuf/issues/1484: |
| 28 # The protobuf library is meant to be installed. It is either a system library | 29 # The protobuf library is meant to be installed. It is either a system library |
| 29 # or a virtualenv library, but not something you can just point "sys.path" to | 30 # or a virtualenv library, but not something you can just point "sys.path" to |
| 30 # anymore ... well, not without hacks. | 31 # anymore ... well, not without hacks. |
| 31 # | 32 # |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 | 64 |
| 64 # From here on out, we're back to normal imports. Let's assert that the we're | 65 # From here on out, we're back to normal imports. Let's assert that the we're |
| 65 # using the correct protobuf package, though. | 66 # using the correct protobuf package, though. |
| 66 # | 67 # |
| 67 # We use "realpath" here because the importer may resolve the path differently | 68 # We use "realpath" here because the importer may resolve the path differently |
| 68 # based on symlinks, and we want to make sure our calculated path matches the | 69 # based on symlinks, and we want to make sure our calculated path matches the |
| 69 # impoter's path regardless. | 70 # impoter's path regardless. |
| 70 import google.protobuf | 71 import google.protobuf |
| 71 assert (os.path.realpath(THIRD_PARTY) in | 72 assert (os.path.realpath(THIRD_PARTY) in |
| 72 os.path.realpath(google.protobuf.__path__[0])) | 73 os.path.realpath(google.protobuf.__path__[0])) |
| OLD | NEW |