77import re
88from distutils .spawn import find_executable
99
10- # setuptool is dependend on wheel package
1110from setuptools import setup
11+ from setuptools .command .sdist import sdist
1212from setuptools .command .build_py import build_py
1313
14- # configure the version number
15- from shutil import copyfile
16-
17- copyfile ("VERSION" , "version.py" )
18- from version import *
14+ # protoc
15+ from protoc import PROTOC_EXE
1916
20- with open ("osi_version.proto.in" , "rt" ) as fin :
21- with open ("osi_version.proto" , "wt" ) as fout :
22- for line in fin :
23- lineConfigured = line .replace ("@VERSION_MAJOR@" , str (VERSION_MAJOR ))
24- lineConfigured = lineConfigured .replace (
25- "@VERSION_MINOR@" , str (VERSION_MINOR )
26- )
27- lineConfigured = lineConfigured .replace (
28- "@VERSION_PATCH@" , str (VERSION_PATCH )
29- )
30- fout .write (lineConfigured )
17+ # configure the version number
18+ VERSION_MAJOR = None
19+ VERSION_MINOR = None
20+ VERSION_PATCH = None
21+ VERSION_SUFFIX = None
22+ with open ("VERSION" , "rt" ) as versionin :
23+ for line in versionin :
24+ if line .startswith ("VERSION_MAJOR" ):
25+ VERSION_MAJOR = int (line .split ("=" )[1 ].strip ())
26+ if line .startswith ("VERSION_MINOR" ):
27+ VERSION_MINOR = int (line .split ("=" )[1 ].strip ())
28+ if line .startswith ("VERSION_PATCH" ):
29+ VERSION_PATCH = int (line .split ("=" )[1 ].strip ())
30+ if line .startswith ("VERSION_SUFFIX" ):
31+ VERSION_SUFFIX = line .split ("=" )[1 ].strip ()
3132
3233package_name = "osi3"
3334package_path = os .path .join (os .getcwd (), package_name )
3435
3536
36- class GenerateProtobufCommand ( build_py ) :
37+ class ProtobufGenerator :
3738 @staticmethod
3839 def find_protoc ():
3940 """Locates protoc executable"""
4041
41- if "PROTOC" in os .environ and os .path .exists (os .environ ["PROTOC" ]):
42+ if os .path .exists (PROTOC_EXE ):
43+ protoc = PROTOC_EXE
44+ elif "PROTOC" in os .environ and os .path .exists (os .environ ["PROTOC" ]):
4245 protoc = os .environ ["PROTOC" ]
4346 else :
4447 protoc = find_executable ("protoc" )
@@ -89,7 +92,19 @@ def find_protoc():
8992
9093 """ Generate Protobuf Messages """
9194
92- def run (self ):
95+ def generate (self ):
96+ sys .stdout .write ("Generating Protobuf Version Message\n " )
97+ with open ("osi_version.proto.in" , "rt" ) as fin :
98+ with open ("osi_version.proto" , "wt" ) as fout :
99+ for line in fin :
100+ lineConfigured = line .replace ("@VERSION_MAJOR@" , str (VERSION_MAJOR ))
101+ lineConfigured = lineConfigured .replace (
102+ "@VERSION_MINOR@" , str (VERSION_MINOR )
103+ )
104+ lineConfigured = lineConfigured .replace (
105+ "@VERSION_PATCH@" , str (VERSION_PATCH )
106+ )
107+ fout .write (lineConfigured )
93108 pattern = re .compile ('^import "osi_' )
94109 for source in self .osi_files :
95110 with open (source ) as src_file :
@@ -103,38 +118,46 @@ def run(self):
103118 source_path = os .path .join (package_name , source )
104119 subprocess .check_call ([self .find_protoc (), "--python_out=." , source_path ])
105120
121+ def maybe_generate (self ):
122+ if os .path .exists ("osi_version.proto.in" ):
123+ self .generate ()
124+
125+
126+ class CustomBuildPyCommand (build_py ):
127+ def run (self ):
128+ ProtobufGenerator ().maybe_generate ()
106129 build_py .run (self )
107130
108131
132+ class CustomSDistCommand (sdist ):
133+ def run (self ):
134+ ProtobufGenerator ().generate ()
135+ sdist .run (self )
136+
137+
109138try :
110139 os .mkdir (package_path )
111140except Exception :
112141 pass
113142
114143try :
115- open (os .path .join (package_path , "__init__.py" ), "a" ).close ()
144+ with open (os .path .join (package_path , "__init__.py" ), "wt" ) as init_file :
145+ init_file .write (
146+ f"__version__ = '{ VERSION_MAJOR } .{ VERSION_MINOR } .{ VERSION_PATCH } { VERSION_SUFFIX or '' } '\n "
147+ )
116148except Exception :
117149 pass
118150
119151setup (
120- name = "open-simulation-interface" ,
121- version = str (VERSION_MAJOR ) + "." + str (VERSION_MINOR ) + "." + str (VERSION_PATCH ),
122- description = "A generic interface for the environmental perception of"
123- "automated driving functions in virtual scenarios." ,
124- author = "Carlo van Driesten, Timo Hanke, Nils Hirsenkorn,"
125- "Pilar Garcia-Ramos, Mark Schiementz, Sebastian Schneider" ,
126- author_email = "Carlo.van-Driesten@bmw.de, Timo.Hanke@bmw.de,"
127- "Nils.Hirsenkorn@tum.de, Pilar.Garcia-Ramos@bmw.de,"
128- "Mark.Schiementz@bmw.de, Sebastian.SB.Schneider@bmw.de" ,
152+ version = str (VERSION_MAJOR )
153+ + "."
154+ + str (VERSION_MINOR )
155+ + "."
156+ + str (VERSION_PATCH )
157+ + (VERSION_SUFFIX or "" ),
129158 packages = [package_name ],
130- install_requires = ["protobuf" ],
131159 cmdclass = {
132- "build_py" : GenerateProtobufCommand ,
160+ "sdist" : CustomSDistCommand ,
161+ "build_py" : CustomBuildPyCommand ,
133162 },
134- url = "https://github.com/OpenSimulationInterface/open-simulation-interface" ,
135- license = "MPL 2.0" ,
136- classifiers = [
137- "License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)" ,
138- ],
139- data_files = [("" , ["LICENSE" ])],
140163)
0 commit comments