Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update mavgen_c to python3 #1000

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions generator/mavgen_c.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
#!/usr/bin/env python
#!/usr/bin/env python3
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leave this as python for now.

'''
parse a MAVLink protocol XML file and generate a C implementation

Copyright Andrew Tridgell 2011
Released under GNU GPL version 3 or later
'''
from __future__ import print_function
from future.utils import iteritems

from builtins import range
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leaving the from __future__ and from builtins lines has no real impact on python3 but maintains compatibility with python2.

from builtins import object

import os
from . import mavparse, mavtemplate
Expand Down Expand Up @@ -675,7 +670,7 @@ def generate_one(basename, xml):
# form message name array
xml.message_name_array = ''
# sort by names
for msgid, name in sorted(iteritems(xml.message_names), key=lambda k_v: (k_v[1], k_v[0])):
for msgid, name in sorted(xml.message_names.items(), key=lambda k_v: (k_v[1], k_v[0])):
Copy link

@bobpaul bobpaul Jan 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This runs the same on Python 2 as Python 3. iteritems() from future is for performance, not correctness.

xml.message_name_array += '{ "%s", %u }, ' % (name, msgid)
xml.message_name_array = xml.message_name_array[:-2]

Expand Down