From a390d63b300d30711474708ae60b7dfb6b8c9b57 Mon Sep 17 00:00:00 2001 From: "Ban Siesta (Bot)" Date: Tue, 1 Dec 2026 12:54:31 +1300 Subject: [PATCH] Expose the package version as mavsdk.__version__ There was no way to get the installed version from Python. `mavsdk.major` and `mavsdk.minor` looked like a version, but they were the Python version, left over from a compatibility check. Add `__version__`, read from the installed distribution's metadata, so it matches `pip show`. It is "unknown" in a source checkout. The bundled mavsdk_server has the same version. Remove the Python >= 3.6 check. setup.py already requires >= 3.9, and the check was what leaked `major` and `minor`. Fixes #671 --- mavsdk/__init__.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/mavsdk/__init__.py b/mavsdk/__init__.py index 430ca896..51582cde 100644 --- a/mavsdk/__init__.py +++ b/mavsdk/__init__.py @@ -1,25 +1,26 @@ # -*- coding: utf-8 -*- import asyncio -import platform -import sys +import importlib.metadata import warnings from .system import System, MavsdkServerExitedError -# Check for compatibility -(major, minor, _) = platform.python_version_tuple() -if not ((int(major) >= 3 and int(minor) >= 6) or (int(major) >= 4)): - print("[!] MAVSDK-Python is only available on Python >= 3.6") - sys.exit(1) - # Written by setup.py at build time. Absent when running from a source checkout, -# in which case there is nothing to warn about. +# in which case there is nothing to warn about and no version to report. try: from ._dist import DIST_NAME as _dist_name except ImportError: _dist_name = None +# Version of the installed distribution, as shown by `pip show`, e.g. "4.3.0". +# The bundled mavsdk_server has the same version; it logs it on startup +# ("MAVSDK version: v4.3.0"). +try: + __version__ = importlib.metadata.version(_dist_name) if _dist_name else "unknown" +except importlib.metadata.PackageNotFoundError: + __version__ = "unknown" + if _dist_name == "mavsdk": # A FutureWarning rather than a DeprecationWarning: the latter is filtered # out by default unless it is raised from __main__, which would hide this