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


mavlink
Author(s): Lorenz Meier
autogenerated on Sun Apr 7 2019 02:06:02