From 0217351b6d421c4f8e3b57ca77b37d913e56eb9f Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Thu, 18 Jan 2024 11:53:36 +1100 Subject: [PATCH 1/2] README.md: remove some Python2 information --- README.md | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/README.md b/README.md index 506ae9719..090280f0e 100644 --- a/README.md +++ b/README.md @@ -15,8 +15,6 @@ Examples can be found [in the repository](examples/) or in the [ArduSub book](ht # Installation -Pymavlink supports both Python 2 and Python 3. - The following instructions assume you are using Python 3 and a Debian-based (like Ubuntu) installation. .. note:: @@ -27,7 +25,7 @@ The following instructions assume you are using Python 3 and a Debian-based (lik Pymavlink has several dependencies : - - [future](http://python-future.org/) : for Python 2 and Python 3 interoperability + - [future](http://python-future.org/) : for interoperability - [lxml](http://lxml.de/installation.html) : for checking and parsing xml file Optional : @@ -39,10 +37,6 @@ Optional : lxml has some additional dependencies that can be installed with your package manager (here with `apt-get`) : -.. note:: - - If you continue to use Python 2 you may need to change package names here (e.g. python3-numpy => python-numpy) - ```bash sudo apt-get install libxml2-dev libxslt-dev ``` From 554cc7d169463cc60e9e3db7ab16856444fe39ee Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Wed, 17 Jan 2024 17:02:08 +1100 Subject: [PATCH 2/2] mavgen_python: make enumerations MavEnum instances ... instead of just bare dictionaries ... and add an is_bitmask method to them --- generator/mavgen_python.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/generator/mavgen_python.py b/generator/mavgen_python.py index 750061f28..64efdc3ea 100644 --- a/generator/mavgen_python.py +++ b/generator/mavgen_python.py @@ -44,6 +44,8 @@ def extend_with_type_info(extended, enable_type_annotations): "mavlink_message_signed_callback": ('Callable[["MAVLink", int], bool]', None), "dict_str_to_str_float_int": ("Dict[str, Union[str, float, int]]", None), "dict_str_to_dict_int_to_enumentry": ("Dict[str, Dict[int, EnumEntry]]", None), + "dict_int_to_enumentry": ("Dict[int, EnumEntry]", None), + "dict_str_to_MavEnum": ("Dict[str, MavEnum]", None), "dict_int_to_str": ("Dict[int, str]", None), "dict_str_to_str": ("Dict[str, str]", None), "dict_int_int_int_to_int": ("Dict[Tuple[int, int, int], int]", None), @@ -457,14 +459,26 @@ def __init__(self, name${type_str}, description${type_str})${type_none_ret}: self.has_location = False -enums${type_dict_str_to_dict_int_to_enumentry} = {} +class MavEnum(${type_dict_int_to_enumentry_cast}): + def __init__(self, bitmask${type_bool_default})${type_none_ret}: + super(MavEnum, self).__init__() + self.bitmask = bitmask + + def is_bitmask(self)${type_bool_ret}: + return self.bitmask + + +enums${type_dict_str_to_MavEnum} = {} """, type_info, ) for e in enums: outf.write("\n# %s\n" % e.name) - outf.write('enums["%s"] = {}\n' % e.name) + mavenum_kwargs = "" + if bool(e.bitmask): + mavenum_kwargs = "bitmask=True" + outf.write('enums["%s"] = MavEnum(%s)\n' % (e.name, mavenum_kwargs)) for entry in e.entry: outf.write("%s = %u\n" % (entry.name, entry.value)) description = entry.description.replace("\t", " ")