setup.py 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. from __future__ import absolute_import, print_function
  2. from setuptools.command.build_py import build_py
  3. # Work around mbcs bug in distutils.
  4. # http://bugs.python.org/issue10945
  5. import codecs
  6. try:
  7. codecs.lookup('mbcs')
  8. except LookupError:
  9. ascii = codecs.lookup('ascii')
  10. func = lambda name, enc=ascii: {True: enc}.get(name=='mbcs')
  11. codecs.register(func)
  12. from setuptools import setup, Extension
  13. import glob, os, shutil, fnmatch, platform, sys
  14. version = '2.3.7'
  15. def generate_content():
  16. # generate the file content...
  17. from generator import mavgen, mavparse
  18. # path to message_definitions directory
  19. if os.getenv("MDEF",None) is not None:
  20. mdef_paths = [os.getenv("MDEF")]
  21. else:
  22. mdef_paths = [os.path.join('..', 'message_definitions'),
  23. os.path.join('mavlink', 'message_definitions'),
  24. os.path.join('..', 'mavlink', 'message_definitions'),
  25. os.path.join('message_definitions'),
  26. ]
  27. for path in mdef_paths:
  28. mdef_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), path)
  29. if os.path.exists(mdef_path):
  30. print("Using message definitions from %s" % mdef_path)
  31. break
  32. dialects_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'dialects')
  33. v10_dialects = glob.glob(os.path.join(mdef_path, 'v1.0', '*.xml'))
  34. # for now v2.0 uses same XML files as v1.0
  35. v20_dialects = glob.glob(os.path.join(mdef_path, 'v1.0', '*.xml'))
  36. should_generate = not "NOGEN" in os.environ
  37. if should_generate:
  38. if len(v10_dialects) == 0:
  39. print("No XML message definitions found")
  40. sys.exit(1)
  41. for xml in v10_dialects:
  42. shutil.copy(xml, os.path.join(dialects_path, 'v10'))
  43. for xml in v20_dialects:
  44. shutil.copy(xml, os.path.join(dialects_path, 'v20'))
  45. for xml in v10_dialects:
  46. dialect = os.path.basename(xml)[:-4]
  47. wildcard = os.getenv("MAVLINK_DIALECT",'*')
  48. if not fnmatch.fnmatch(dialect, wildcard):
  49. continue
  50. print("Building %s for protocol 1.0" % xml)
  51. if not mavgen.mavgen_python_dialect(dialect, mavparse.PROTOCOL_1_0):
  52. print("Building failed %s for protocol 1.0" % xml)
  53. sys.exit(1)
  54. for xml in v20_dialects:
  55. dialect = os.path.basename(xml)[:-4]
  56. wildcard = os.getenv("MAVLINK_DIALECT",'*')
  57. if not fnmatch.fnmatch(dialect, wildcard):
  58. continue
  59. print("Building %s for protocol 2.0" % xml)
  60. if not mavgen.mavgen_python_dialect(dialect, mavparse.PROTOCOL_2_0):
  61. print("Building failed %s for protocol 2.0" % xml)
  62. sys.exit(1)
  63. extensions = [] # Assume we might be unable to build native code
  64. if platform.system() != 'Windows':
  65. extensions = [ Extension('mavnative',
  66. sources=['mavnative/mavnative.c'],
  67. include_dirs=[
  68. 'generator/C/include_v1.0',
  69. 'generator/C/include_v2.0',
  70. 'mavnative'
  71. ]
  72. ) ]
  73. else:
  74. print("Skipping mavnative due to Windows possibly missing a compiler...")
  75. class custom_build_py(build_py):
  76. def run(self):
  77. generate_content()
  78. # distutils uses old-style classes, so no super()
  79. build_py.run(self)
  80. setup (name = 'pymavlink',
  81. version = version,
  82. description = 'Python MAVLink code',
  83. long_description = ('A Python library for handling MAVLink protocol streams and log files. This allows for the '
  84. 'creation of simple scripts to analyse telemetry logs from autopilots such as ArduPilot which use '
  85. 'the MAVLink protocol. See the scripts that come with the package for examples of small, useful '
  86. 'scripts that use pymavlink. For more information about the MAVLink protocol see '
  87. 'https://mavlink.io/en/'),
  88. url = 'https://github.com/ArduPilot/pymavlink/',
  89. classifiers=['Development Status :: 4 - Beta',
  90. 'Environment :: Console',
  91. 'Intended Audience :: Science/Research',
  92. 'License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)',
  93. 'Operating System :: OS Independent',
  94. 'Programming Language :: Python :: 2.7',
  95. 'Programming Language :: Python :: 3.5',
  96. 'Topic :: Scientific/Engineering'
  97. ],
  98. license='LGPLv3',
  99. package_dir = { 'pymavlink' : '.' },
  100. package_data = { 'pymavlink.dialects.v10' : ['*.xml'],
  101. 'pymavlink.dialects.v20' : ['*.xml'],
  102. 'pymavlink.generator' : [ '*.xsd',
  103. 'java/lib/*.*',
  104. 'java/lib/Messages/*.*',
  105. 'C/include_v1.0/*.h',
  106. 'C/include_v1.0/*.hpp',
  107. 'C/include_v2.0/*.h',
  108. 'C/include_v2.0/*.hpp',
  109. 'CPP11/include_v2.0/*.hpp',
  110. 'CS/common/*.cs',
  111. 'swift/*.swift',],
  112. 'pymavlink' : ['mavnative/*.h',
  113. 'message_definitions/v*/*.xml']
  114. },
  115. packages = ['pymavlink',
  116. 'pymavlink.generator',
  117. 'pymavlink.dialects',
  118. 'pymavlink.dialects.v10',
  119. 'pymavlink.dialects.v20'],
  120. scripts = [ 'tools/magfit_delta.py', 'tools/mavextract.py',
  121. 'tools/mavgraph.py', 'tools/mavparmdiff.py',
  122. 'tools/mavtogpx.py', 'tools/magfit_gps.py',
  123. 'tools/mavflightmodes.py', 'tools/mavlogdump.py',
  124. 'tools/mavparms.py', 'tools/magfit_motors.py',
  125. 'tools/mavflighttime.py', 'tools/mavloss.py',
  126. 'tools/mavplayback.py', 'tools/magfit.py',
  127. 'tools/mavgpslock.py',
  128. 'tools/mavmission.py',
  129. 'tools/mavsigloss.py',
  130. 'tools/mavsearch.py',
  131. 'tools/mavtomfile.py',
  132. 'tools/mavgen.py',
  133. 'tools/mavkml.py',
  134. 'tools/mavfft.py',
  135. 'tools/mavfft_isb.py',
  136. 'tools/mavsummarize.py',
  137. 'tools/MPU6KSearch.py',
  138. 'tools/mavlink_bitmask_decoder.py',
  139. ],
  140. install_requires=[
  141. 'future',
  142. 'lxml',
  143. ],
  144. setup_requires=[
  145. 'future' # future is required by mavgen, included by this file
  146. ],
  147. cmdclass={'build_py': custom_build_py},
  148. ext_modules = extensions
  149. )