44import os
55import subprocess
66import sys
7+ import re
78from distutils .spawn import find_executable
89
910from setuptools import setup
10- from setuptools .command .install import install
11+ from setuptools .command .build_py import build_py
1112
1213# configure the version number
1314from shutil import copyfile
2425package_name = 'osi3'
2526package_path = os .path .join (os .getcwd (), package_name )
2627
27- class GenerateProtobuf ( install ):
28+ class GenerateProtobufCommand ( build_py ):
2829
2930 @staticmethod
3031 def find_protoc ():
@@ -71,14 +72,23 @@ def find_protoc():
7172 """ Generate Protobuf Messages """
7273
7374 def run (self ):
75+ if sys .hexversion >= 0x3000000 :
76+ pattern = re .compile ('^import "osi_' )
77+ for source in self .osi_files :
78+ with open (source ) as src_file :
79+ with open (os .path .join (package_path , source ),"w" ) as dst_file :
80+ for line in src_file :
81+ dst_file .write (pattern .sub ('import "osi3/osi_' ,line ))
7482 for source in self .osi_files :
7583 sys .stdout .write ('Protobuf-compiling ' + source + '\n ' )
84+ source_path = os .path .join (package_path , source ) if sys .hexversion >= 0x3000000 else './' + source
7685 subprocess .check_call ([self .find_protoc (),
86+ '--proto_path=' + package_path ,
7787 '--proto_path=.' ,
7888 '--python_out=' + package_path ,
79- './' + source ])
89+ source_path ])
8090
81- install .run (self )
91+ build_py .run (self )
8292
8393try :
8494 os .mkdir (package_path )
@@ -103,7 +113,7 @@ def run(self):
103113 packages = [package_name ],
104114 install_requires = ['protobuf' ],
105115 cmdclass = {
106- 'install ' : GenerateProtobuf ,
116+ 'build_py ' : GenerateProtobufCommand ,
107117 },
108118 url = 'https://github.com/OpenSimulationInterface/open-simulation-interface' ,
109119 license = "MPL 2.0" ,
0 commit comments