intercreate / smpclient

Simple Management Protocol (SMP) Client for remotely managing MCU firmware
Apache License 2.0
9 stars 6 forks source link

support for python 3.9 #16

Closed tomaszduda23 closed 6 months ago

tomaszduda23 commented 6 months ago

I'm working on integration of https://github.com/esphome/esphome/pull/6075. When I try to build esphome with python 3.9 I get following error.

# python -m esphome compile tests/test12.2.yaml 
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/local/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/data/esphome/__main__.py", line 51, in <module>
    from .zephyr_tools import (
  File "/data/esphome/zephyr_tools.py", line 8, in <module>
    from smpclient.transport.ble import SMPBLETransport
  File "/usr/local/lib/python3.9/site-packages/smpclient/__init__.py", line 7, in <module>
    from smp import header as smpheader
  File "/usr/local/lib/python3.9/site-packages/smp/header.py", line 81, in <module>
    class Header:
  File "/usr/local/lib/python3.9/site-packages/smp/header.py", line 88, in Header
    command_id: CommandId.OSManagement | CommandId.ImageManagement | IntEnum
TypeError: unsupported operand type(s) for |: 'EnumMeta' and 'EnumMeta'

minimum version of python for esphome is 3.9. Could you please consider to support python 3.9 also? I'm not sure how many changes it would required.

JPHutchins commented 6 months ago

Darn! What is ESPHome's python support policy? 3.9 is EOL in about a year, do they support right up until EOL and then remove support?

https://devguide.python.org/versions/#python-release-cycle

Supporting 3.9 would involved replacing every "Union type" with Union[] instead of |. Because mypy is in place, the linting tests should cover this well.

JPHutchins commented 6 months ago

Looks there may be an easy fix: https://stackoverflow.com/questions/76579085/python-3-9-use-or-operator-for-union-types

JPHutchins commented 6 months ago

OK, getting support at smp was the heavy lift, updating smpclient shouldn't be too bad: https://github.com/JPHutchins/smp/pull/16