Skip to content

Commit

Permalink
move proto build inside setup.py
Browse files Browse the repository at this point in the history
Signed-off-by: Oleksii Moskalenko <moskalenko.alexey@gmail.com>
  • Loading branch information
pyalex committed Mar 24, 2021
1 parent a139916 commit a6e3287
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 25 deletions.
9 changes: 1 addition & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,8 @@ format-python:
install-python-ci-dependencies:
pip install -U --no-cache-dir -r python/requirements-ci.txt

compile-protos-python:
$(MAKE) install-python-ci-dependencies || true
@$(eval FEAST_PATH=`python -c "import feast; import os; print(os.path.dirname(feast.__file__))"`)
@$(foreach dir,$(PROTO_TYPE_SUBDIRS),cd ${ROOT_DIR}/protos; python -m grpc_tools.protoc -I. -I$(FEAST_PATH)/protos/ --python_out=../python/ --mypy_out=../python/ feast_spark/$(dir)/*.proto;)
@$(foreach dir,$(PROTO_SERVICE_SUBDIRS),cd ${ROOT_DIR}/protos; python -m grpc_tools.protoc -I. -I$(FEAST_PATH)/protos/ --grpc_python_out=../python/ feast_spark/$(dir)/*.proto;)
cd ${ROOT_DIR}/protos; python -m grpc_tools.protoc -I. --python_out=../python/ --grpc_python_out=../python/ --mypy_out=../python/ feast_spark/third_party/grpc/health/v1/*.proto

# Supports feast-dev repo master branch
install-python: compile-protos-python
install-python: install-python-ci-dependencies
cd ${ROOT_DIR}; python -m pip install -e python

lint-python:
Expand Down
45 changes: 28 additions & 17 deletions python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
import re
import subprocess

from distutils.cmd import Command
from distutils.command.build import build # pylint: disable=g-importing-member
from distutils.spawn import find_executable

from setuptools import find_packages, setup

try:
Expand Down Expand Up @@ -67,27 +71,36 @@
)


def pre_install_build():
subprocess.check_call("make compile-protos-python", shell=True, cwd=f"{repo_root}", executable='/bin/bash')

class BuildProtoCommand(Command):
description = "Builds the proto files into python files."

class CustomInstallCommand(install):
def do_egg_install(self):
pre_install_build()
install.do_egg_install(self)
def initialize_options(self):
self.protoc = find_executable("protoc")
self.proto_folder = os.path.join(repo_root, "protos")
self.this_package = os.path.dirname(__file__)
self.sub_folders = ["api"]

def finalize_options(self):
pass

class CustomDevelopCommand(develop):
def run(self):
pre_install_build()
develop.run(self)
for sub_folder in self.sub_folders:
subprocess.check_call([self.protoc,
'-I', '.',
'--python_out', self.this_package,
'--grpc_python_our', self.this_package,
'--mypy_out', self.this_package,
f'feast_spark/{sub_folder}/*.proto'], cwd=self.proto_folder)

subprocess.check_call([self.protoc,
'-I', '.',
'--python_out', self.this_package,
'--grpc_python_our', self.this_package,
'--mypy_out', self.this_package,
'feast_spark/third_party/grpc/health/v1/*.proto'], cwd=self.proto_folder)

class CustomEggInfoCommand(egg_info):
def run(self):
pre_install_build()
egg_info.run(self)

build.sub_commands.insert(0, ('build_proto', None))

setup(
name=NAME,
Expand Down Expand Up @@ -119,8 +132,6 @@ def run(self):
use_scm_version={"root": "../", "relative_to": __file__, "tag_regex": TAG_REGEX},
setup_requires=["setuptools_scm", "grpcio-tools", "feast", "mypy-protobuf"],
cmdclass={
"install": CustomInstallCommand,
"develop": CustomDevelopCommand,
"egg_info": CustomEggInfoCommand,
"build_proto": BuildProtoCommand,
},
)

0 comments on commit a6e3287

Please sign in to comment.