reflection_commands.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # Copyright 2016 gRPC authors.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. """Provides distutils command classes for the GRPC Python setup process."""
  15. import os
  16. import shutil
  17. import setuptools
  18. ROOT_DIR = os.path.abspath(os.path.dirname(os.path.abspath(__file__)))
  19. REFLECTION_PROTO = os.path.join(
  20. ROOT_DIR, '../../proto/grpc/reflection/v1alpha/reflection.proto')
  21. LICENSE = os.path.join(ROOT_DIR, '../../../LICENSE')
  22. class Preprocess(setuptools.Command):
  23. """Command to copy proto modules from grpc/src/proto and LICENSE from
  24. the root directory"""
  25. description = ''
  26. user_options = []
  27. def initialize_options(self):
  28. pass
  29. def finalize_options(self):
  30. pass
  31. def run(self):
  32. if os.path.isfile(REFLECTION_PROTO):
  33. shutil.copyfile(
  34. REFLECTION_PROTO,
  35. os.path.join(ROOT_DIR,
  36. 'grpc_reflection/v1alpha/reflection.proto'))
  37. if os.path.isfile(LICENSE):
  38. shutil.copyfile(LICENSE, os.path.join(ROOT_DIR, 'LICENSE'))
  39. class BuildPackageProtos(setuptools.Command):
  40. """Command to generate project *_pb2.py modules from proto files."""
  41. description = 'build grpc protobuf modules'
  42. user_options = []
  43. def initialize_options(self):
  44. pass
  45. def finalize_options(self):
  46. pass
  47. def run(self):
  48. # due to limitations of the proto generator, we require that only *one*
  49. # directory is provided as an 'include' directory. We assume it's the '' key
  50. # to `self.distribution.package_dir` (and get a key error if it's not
  51. # there).
  52. from grpc_tools import command
  53. command.build_package_protos(self.distribution.package_dir[''])