| 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 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 # In a temporary environment where "sys.path" consists solely of our | 52 # In a temporary environment where "sys.path" consists solely of our |
| 53 # "third_party" directory, register the google namespace. By restricting the | 53 # "third_party" directory, register the google namespace. By restricting the |
| 54 # options in "sys.path", "pkg_resources" will not cache or prefer system | 54 # options in "sys.path", "pkg_resources" will not cache or prefer system |
| 55 # resources for this namespace or its derivatives. | 55 # resources for this namespace or its derivatives. |
| 56 sys.path = [THIRD_PARTY] | 56 sys.path = [THIRD_PARTY] |
| 57 pkg_resources.declare_namespace('google') | 57 pkg_resources.declare_namespace('google') |
| 58 pkg_resources.fixup_namespace_packages(THIRD_PARTY) | 58 pkg_resources.fixup_namespace_packages(THIRD_PARTY) |
| 59 | 59 |
| 60 # From here on out, we're back to normal imports. Let's assert that the we're | 60 # From here on out, we're back to normal imports. Let's assert that the we're |
| 61 # using the correct protobuf package, though. | 61 # using the correct protobuf package, though. |
| 62 # |
| 63 # We use "realpath" here because the importer may resolve the path differently |
| 64 # based on symlinks, and we want to make sure our calculated path matches the |
| 65 # impoter's path regardless. |
| 62 import google.protobuf | 66 import google.protobuf |
| 63 assert THIRD_PARTY in google.protobuf.__path__[0] | 67 assert (os.path.realpath(THIRD_PARTY) in |
| 68 os.path.realpath(google.protobuf.__path__[0])) |
| 64 | 69 |
| OLD | NEW |