setup.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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/', 'aman/com/')
  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', '-Isrc/protobuf/', '-I.', '--python_out=aman/com/', 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 or 'build' == dirname or 'dist' == 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. with open('README.md', 'r') as f:
  47. longDescription = f.read()
  48. setup(
  49. name = 'Arrival MANager',
  50. version = '0.1.0',
  51. packages = [
  52. 'aman',
  53. 'aman.com',
  54. 'aman.tools'
  55. ],
  56. namespace_packages = [ 'aman' ],
  57. description = 'AMAN optimization backend',
  58. long_description = longDescription,
  59. author = 'Sven Czarnian',
  60. author_email = 'devel@svcz.de',
  61. license = 'GPLv3',
  62. cmdclass = { 'clean': clean, 'build_py': build_py },
  63. install_requires=[
  64. 'setuptools',
  65. 'pyzmq',
  66. 'protobuf'
  67. ]
  68. )