setup.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #!/usr/bin/env python
  2. import os
  3. import re
  4. import shutil
  5. import subprocess
  6. import sys
  7. from setuptools import setup
  8. from distutils.command.clean import clean as _clean
  9. from distutils.command.build_py import build_py_2to3 as _build_py
  10. # @brief Creates Protobuf python files to encode and decode messages
  11. # @param[in] source The protobuf source file
  12. def generateProtobuf(source):
  13. output = source.replace('.proto', '_pb2.py').replace('src/protobuf/', 'aman/com/')
  14. if (not os.path.exists(output) or (os.path.exists(source) and os.path.getmtime(source) > os.path.getmtime(output))):
  15. print('Generating %s...' % output)
  16. if not os.path.exists(source):
  17. sys.stderr.write('Cannot find %s' % source)
  18. sys.exit(-1)
  19. if not os.path.exists('external/bin/protoc.exe'):
  20. sys.stderr.write('Cannot find proto-compiler')
  21. sys.exit(-1)
  22. command = [ 'external/bin/protoc.exe', '-Isrc/protobuf/', '-I.', '--python_out=aman/com/', source]
  23. if 0 != subprocess.call(command):
  24. sys.exit(-1)
  25. # check if we need to replace some import commands
  26. replaced = False
  27. content = open(output, 'r').read()
  28. for entry in re.findall('import.[A-Z].*.as.*', content):
  29. content = content.replace(entry, 'from . ' + entry)
  30. replaced = True
  31. # update the content
  32. if replaced:
  33. with open(output, 'w') as file:
  34. file.write(content)
  35. # @brief Cleans up all auto-generated files and folders
  36. # @param[in] _clean Instance of setuptools to clean up the system
  37. class clean(_clean):
  38. def run(self):
  39. for (dirpath, dirnames, filenames) in os.walk('.'):
  40. for filename in filenames:
  41. filepath = os.path.join(dirpath, filename)
  42. if filepath.endswith('_pb2.py') or filepath.endswith('.pyc'):
  43. os.remove(filepath)
  44. for dirname in dirnames:
  45. if 'Arrival_MANager.egg-info' == dirname or 'build' == dirname or 'dist' == dirname or '__pycache__' == dirname:
  46. shutil.rmtree(os.path.join(dirpath, dirname))
  47. _clean.run(self)
  48. # @brief Generates the python files and folders to set up the development/runtime environment
  49. # @param[in] _build_py Instance of setuptools to build the system
  50. class build_py(_build_py):
  51. def run(self):
  52. generateProtobuf('src/protobuf/Aircraft.proto')
  53. generateProtobuf('src/protobuf/AircraftReport.proto')
  54. generateProtobuf('src/protobuf/AircraftSchedule.proto')
  55. generateProtobuf('src/protobuf/BaseTypes.proto')
  56. _build_py.run(self)
  57. with open('README.md', 'r') as f:
  58. longDescription = f.read()
  59. setup(
  60. name = 'Arrival MANager',
  61. version = '0.1.0',
  62. packages = [
  63. 'aman',
  64. 'aman.com',
  65. 'aman.config',
  66. 'aman.formats',
  67. 'aman.sys',
  68. 'aman.tools',
  69. 'aman.types'
  70. ],
  71. namespace_packages = [ 'aman' ],
  72. description = 'AMAN optimization backend',
  73. long_description = longDescription,
  74. author = 'Sven Czarnian',
  75. author_email = 'devel@svcz.de',
  76. license = 'GPLv3',
  77. cmdclass = { 'clean': clean, 'build_py': build_py },
  78. install_requires=[
  79. 'argparse',
  80. 'bs4',
  81. 'configparser',
  82. 'numpy',
  83. 'protobuf',
  84. 'pyzmq',
  85. 'scikit-learn',
  86. 'scipy',
  87. 'setuptools'
  88. ]
  89. )