|  | @@ -0,0 +1,32 @@
 | 
	
		
			
				|  |  | +# Copyright 2019 The gRPC Authors
 | 
	
		
			
				|  |  | +#
 | 
	
		
			
				|  |  | +# Licensed under the Apache License, Version 2.0 (the "License");
 | 
	
		
			
				|  |  | +# you may not use this file except in compliance with the License.
 | 
	
		
			
				|  |  | +# You may obtain a copy of the License at
 | 
	
		
			
				|  |  | +#
 | 
	
		
			
				|  |  | +#     http://www.apache.org/licenses/LICENSE-2.0
 | 
	
		
			
				|  |  | +#
 | 
	
		
			
				|  |  | +# Unless required by applicable law or agreed to in writing, software
 | 
	
		
			
				|  |  | +# distributed under the License is distributed on an "AS IS" BASIS,
 | 
	
		
			
				|  |  | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
	
		
			
				|  |  | +# See the License for the specific language governing permissions and
 | 
	
		
			
				|  |  | +# limitations under the License.
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +import os
 | 
	
		
			
				|  |  | +import site
 | 
	
		
			
				|  |  | +import sys
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +# TODO(https://github.com/bazelbuild/bazel/issues/6844) Bazel failed to
 | 
	
		
			
				|  |  | +# interpret namespace packages correctly. This monkey patch will force the
 | 
	
		
			
				|  |  | +# Python process to parse the .pth file in the sys.path to resolve namespace
 | 
	
		
			
				|  |  | +# package in the right place.
 | 
	
		
			
				|  |  | +# Analysis in depth: https://github.com/bazelbuild/rules_python/issues/55
 | 
	
		
			
				|  |  | +def bazel_patch():
 | 
	
		
			
				|  |  | +    """Add valid sys.path item to site directory to parse the .pth files."""
 | 
	
		
			
				|  |  | +    for item in sys.path:
 | 
	
		
			
				|  |  | +        if os.path.exists(item):
 | 
	
		
			
				|  |  | +            # The only difference between sys.path and site-directory is
 | 
	
		
			
				|  |  | +            # whether the .pth file will be parsed or not. A site-directory
 | 
	
		
			
				|  |  | +            # will always exist in sys.path, but not another way around.
 | 
	
		
			
				|  |  | +            site.addsitedir(item)
 |