setup.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/usr/bin/env python
  2. import os
  3. import shutil
  4. import subprocess
  5. import sys
  6. from setuptools import setup
  7. from distutils.command.clean import clean as _clean
  8. from distutils.command.build_py import build_py_2to3 as _build_py
  9. # @brief Creates Protobuf python files to encode and decode messages
  10. # @param[in] source The protobuf source file
  11. def generateProtobuf(source):
  12. output = source.replace('.proto', '_pb2.py').replace('../src/protobuf/', '')
  13. if (not os.path.exists(output) or (os.path.exists(source) and os.path.getmtime(source) > os.path.getmtime(output))):
  14. print('Generating %s...' % output)
  15. if not os.path.exists(source):
  16. sys.stderr.write('Cannot find %s' % source)
  17. sys.exit(-1)
  18. if not os.path.exists('../external/bin/protoc.exe'):
  19. sys.stderr.write('Cannot find proto-compiler')
  20. sys.exit(-1)
  21. command = [ '../external/bin/protoc.exe', '-I../src/protobuf/', '-I.', '--python_out=.', source]
  22. if 0 != subprocess.call(command):
  23. sys.exit(-1)
  24. # @brief Cleans up all auto-generated files and folders
  25. # @param[in] _clean Instance of setuptools to clean up the system
  26. class clean(_clean):
  27. def run(self):
  28. for (dirpath, dirnames, filenames) in os.walk('.'):
  29. for filename in filenames:
  30. filepath = os.path.join(dirpath, filename)
  31. if filepath.endswith('_pb2.py') or filepath.endswith('.pyc'):
  32. os.remove(filepath)
  33. for dirname in dirnames:
  34. if 'Arrival_MANager.egg-info' == dirname:
  35. shutil.rmtree(os.path.join(dirpath, dirname))
  36. _clean.run(self)
  37. # @brief Generates the python files and folders to set up the development/runtime environment
  38. # @param[in] _build_py Instance of setuptools to build the system
  39. class build_py(_build_py):
  40. def run(self):
  41. generateProtobuf('../src/protobuf/Aircraft.proto')
  42. generateProtobuf('../src/protobuf/AircraftReport.proto')
  43. generateProtobuf('../src/protobuf/AircraftSchedule.proto')
  44. generateProtobuf('../src/protobuf/BaseTypes.proto')
  45. _build_py.run(self)
  46. setup(
  47. name='Arrival MANager',
  48. version='0.1.0',
  49. packages=[ 'aman' ],
  50. namespace_packages=[ 'aman' ],
  51. description='AMAN optimization backend',
  52. author='Sven Czarnian',
  53. author_email='devel@svcz.de',
  54. license='GPLv3',
  55. cmdclass = { 'clean': clean, 'build_py': build_py },
  56. install_requires=[
  57. 'setuptools',
  58. 'pyzmq',
  59. 'protobuf'
  60. ]
  61. )