Skip to content

Commit abadde0

Browse files
authored
Fix install model_config_pb2.py (#1538)
We are generating the model_config_pb2.py file from a protobuf script, but doing this as part of the 'build_ext' phase - running at the same time as building our native extensions. This caused the build to not pick up the generated python file unless it already existed. Fix by moving the proto generation to the correct 'build_py' phase
1 parent c5176ca commit abadde0

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

setup.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
from pybind11.setup_helpers import Pybind11Extension
2222
from pybind11.setup_helpers import build_ext as build_pybind11
2323
from setuptools import find_namespace_packages, find_packages, setup
24+
from setuptools.command.build_py import build_py as _build_py
25+
from setuptools.command.develop import develop as _develop
2426

2527
try:
2628
import versioneer
@@ -33,9 +35,8 @@
3335
import versioneer
3436

3537

36-
class build_pybind_and_proto(build_pybind11):
38+
class build_proto(_build_py):
3739
def run(self):
38-
build_pybind11.run(self)
3940
protoc = None
4041
if "PROTOC" in os.environ and os.path.exists(os.environ["PROTOC"]):
4142
protoc = os.environ["PROTOC"]
@@ -61,6 +62,16 @@ def run(self):
6162
else:
6263
print("not regenerating", output, " - file exists and proto hasn't been updated")
6364

65+
super().run()
66+
67+
68+
class develop(_develop):
69+
def run(self):
70+
# running setup.py develop doesn't seem to run 'build_py' force this to run
71+
# so we get our proto files installed
72+
self.run_command("build_py")
73+
super().run()
74+
6475

6576
ext_modules = [
6677
Pybind11Extension(
@@ -78,7 +89,9 @@ def run(self):
7889

7990

8091
cmdclass = versioneer.get_cmdclass()
81-
cmdclass["build_ext"] = build_pybind_and_proto
92+
cmdclass["build_ext"] = build_pybind11
93+
cmdclass["build_py"] = build_proto
94+
cmdclass["develop"] = develop
8295

8396

8497
def parse_requirements(filename):

0 commit comments

Comments
 (0)