-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
122 lines (107 loc) · 4 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#! python
# -*- coding: UTF-8 -*-
import os
import subprocess
import sys
import re
from distutils.spawn import find_executable
from setuptools import setup
from setuptools.command.build_py import build_py
# configure the version number
from shutil import copyfile
copyfile('VERSION', 'version.py')
from version import *
with open("osi_version.proto.in", "rt") as fin:
with open("osi_version.proto", "wt") as fout:
for line in fin:
lineConfigured = line.replace('@VERSION_MAJOR@',str(VERSION_MAJOR))
lineConfigured = lineConfigured.replace('@VERSION_MINOR@',str(VERSION_MINOR))
lineConfigured = lineConfigured.replace('@VERSION_PATCH@',str(VERSION_PATCH))
fout.write(lineConfigured)
package_name = 'osi3'
package_path = os.path.join(os.getcwd(), package_name)
class GenerateProtobufCommand(build_py):
@staticmethod
def find_protoc():
"""Locates protoc executable"""
if 'PROTOC' in os.environ and os.path.exists(os.environ['PROTOC']):
protoc = os.environ['PROTOC']
else:
protoc = find_executable('protoc')
if protoc is None:
sys.stderr.write(
'protoc not found. Is protobuf-compiler installed? \n'
'Alternatively, you can point the PROTOC environment variable'
'at a local version.')
sys.exit(1)
return protoc
osi_files = (
'osi_version.proto',
'osi_common.proto',
'osi_datarecording.proto',
'osi_detectedtrafficsign.proto',
'osi_detectedtrafficlight.proto',
'osi_detectedroadmarking.proto',
'osi_detectedobject.proto',
'osi_detectedoccupant.proto',
'osi_detectedlane.proto',
'osi_environment.proto',
'osi_groundtruth.proto',
'osi_hostvehicledata.proto',
'osi_trafficsign.proto',
'osi_trafficlight.proto',
'osi_roadmarking.proto',
'osi_featuredata.proto',
'osi_object.proto',
'osi_occupant.proto',
'osi_lane.proto',
'osi_sensordata.proto',
'osi_sensorviewconfiguration.proto',
'osi_sensorspecific.proto',
'osi_sensorview.proto')
""" Generate Protobuf Messages """
def run(self):
pattern = re.compile('^import "osi_')
for source in self.osi_files:
with open(source) as src_file:
with open(os.path.join(package_path, source),"w") as dst_file:
for line in src_file:
dst_file.write(pattern.sub('import "' + package_name + '/osi_',line))
for source in self.osi_files:
sys.stdout.write('Protobuf-compiling ' + source + '\n')
source_path = os.path.join(package_name, source)
subprocess.check_call([self.find_protoc(),
'--python_out=.',
source_path])
build_py.run(self)
try:
os.mkdir(package_path)
except Exception:
pass
try:
open(os.path.join(package_path, '__init__.py'), 'a').close()
except Exception:
pass
setup(
name='open-simulation-interface',
version=str(VERSION_MAJOR)+'.'+str(VERSION_MINOR)+'.'+str(VERSION_PATCH),
description='A generic interface for the environmental perception of'
'automated driving functions in virtual scenarios.',
author='Carlo van Driesten, Timo Hanke, Nils Hirsenkorn,'
'Pilar Garcia-Ramos, Mark Schiementz, Sebastian Schneider',
author_email='[email protected], [email protected],'
packages=[package_name],
install_requires=['protobuf'],
cmdclass={
'build_py': GenerateProtobufCommand,
},
url='https://github.com/OpenSimulationInterface/open-simulation-interface',
license="MPL 2.0",
classifiers=[
'License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)',
],
data_files=[
("",
["LICENSE"])])