# Copyright 2015 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.
"""A setup module for the gRPC Python package."""

import os
import os.path
import sys

import setuptools

import grpc_tools.command

PY3 = sys.version_info.major == 3

# Ensure we're in the proper directory whether or not we're being used by pip.
os.chdir(os.path.dirname(os.path.abspath(__file__)))

# Break import-style to ensure we can actually find our in-repo dependencies.
import commands
import grpc_version

LICENSE = 'Apache License 2.0'

PACKAGE_DIRECTORIES = {
    '': '.',
}

INSTALL_REQUIRES = (
    'coverage>=4.0', 'enum34>=1.0.4',
    'grpcio>={version}'.format(version=grpc_version.VERSION),
    'grpcio-channelz>={version}'.format(version=grpc_version.VERSION),
    'grpcio-status>={version}'.format(version=grpc_version.VERSION),
    'grpcio-tools>={version}'.format(version=grpc_version.VERSION),
    'grpcio-health-checking>={version}'.format(version=grpc_version.VERSION),
    'oauth2client>=1.4.7', 'protobuf>=3.6.0', 'six>=1.10',
    'google-auth>=1.17.2', 'requests>=2.14.2')

if not PY3:
    INSTALL_REQUIRES += ('futures>=2.2.0',)

COMMAND_CLASS = {
    # Run `preprocess` *before* doing any packaging!
    'preprocess': commands.GatherProto,
    'build_package_protos': grpc_tools.command.BuildPackageProtos,
    'build_py': commands.BuildPy,
    'run_fork': commands.RunFork,
    'run_interop': commands.RunInterop,
    'test_lite': commands.TestLite,
    'test_gevent': commands.TestGevent,
    'test_aio': commands.TestAio,
    'test_py3_only': commands.TestPy3Only,
}

PACKAGE_DATA = {
    'tests.interop': [
        'credentials/ca.pem',
        'credentials/server1.key',
        'credentials/server1.pem',
    ],
    'tests.protoc_plugin.protos.invocation_testing': ['same.proto',],
    'tests.protoc_plugin.protos.invocation_testing.split_messages': [
        'messages.proto',
    ],
    'tests.protoc_plugin.protos.invocation_testing.split_services': [
        'services.proto',
    ],
    'tests.testing.proto': [
        'requests.proto',
        'services.proto',
    ],
    'tests.unit': [
        'credentials/ca.pem',
        'credentials/server1.key',
        'credentials/server1.pem',
    ],
    'tests': ['tests.json'],
}

TEST_SUITE = 'tests'
TEST_LOADER = 'tests:Loader'
TEST_RUNNER = 'tests:Runner'
TESTS_REQUIRE = INSTALL_REQUIRES

PACKAGES = setuptools.find_packages('.')

setuptools.setup(
    name='grpcio-tests',
    version=grpc_version.VERSION,
    license=LICENSE,
    packages=list(PACKAGES),
    package_dir=PACKAGE_DIRECTORIES,
    package_data=PACKAGE_DATA,
    install_requires=INSTALL_REQUIRES,
    cmdclass=COMMAND_CLASS,
    tests_require=TESTS_REQUIRE,
    test_suite=TEST_SUITE,
    test_loader=TEST_LOADER,
    test_runner=TEST_RUNNER,
)

@@ -621,16 +621,39 @@
 ge.%22%22%22%0A%0A
+import multiprocessing%0A
 import o
@@ -2920,16 +2920,84 @@
 s('.')%0A%0A
+if __name__ == %22__main__%22:%0A    multiprocessing.freeze_support()%0A    
 setuptoo
@@ -3006,16 +3006,20 @@
 .setup(%0A
+    
     name
@@ -3039,16 +3039,20 @@
 s',%0A    
+   
+ 
 version=
@@ -3073,16 +3073,20 @@
 ERSION,%0A
+    
     lice
@@ -3098,24 +3098,28 @@
 ICENSE,%0A    
+   
+ 
 packages=lis
@@ -3131,16 +3131,20 @@
 KAGES),%0A
+    
     pack
@@ -3172,24 +3172,28 @@
 TORIES,%0A    
+  
+  
 package_data
@@ -3207,16 +3207,20 @@
 E_DATA,%0A
+    
     inst
@@ -3254,16 +3254,20 @@
 ES,%0A    
+  
+  
 cmdclass
@@ -3282,16 +3282,20 @@
 _CLASS,%0A
+    
     test
@@ -3319,24 +3319,28 @@
 EQUIRE,%0A    
+ 
+   
 test_suite=T
@@ -3350,24 +3350,28 @@
 _SUITE,%0A    
+ 
+   
 test_loader=
@@ -3383,24 +3383,28 @@
 LOADER,%0A    
+ 
+   
 test_runner=
@@ -3416,10 +3416,14 @@
 RUNNER,%0A
+    
 )%0A

Fix subprocess tests on Mac Python 3.8