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