diff --git a/.readthedocs.yaml b/.readthedocs.yaml index b968d47d..b7f92082 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -9,7 +9,7 @@ version: 2 python: - version: "3.6" + version: "3.7" install: - requirements: docs/requirements.txt - requirements: requirements.txt diff --git a/README.rst b/README.rst index 650fc8d0..9e5b81ed 100644 --- a/README.rst +++ b/README.rst @@ -41,7 +41,7 @@ Dependencies ============= This driver depends on: -* Python 3.6 or higher +* Python 3.7 or higher Installing from PyPI ===================== diff --git a/adafruit_platformdetect/__init__.py b/adafruit_platformdetect/__init__.py index 018f72e2..3d2cefa9 100644 --- a/adafruit_platformdetect/__init__.py +++ b/adafruit_platformdetect/__init__.py @@ -6,7 +6,11 @@ Attempt to detect the current platform. """ import re -from typing import Optional + +try: + from typing import Optional +except ImportError: + pass from .board import Board from .chip import Chip diff --git a/adafruit_platformdetect/board.py b/adafruit_platformdetect/board.py index d58c3fe5..3005e0ac 100644 --- a/adafruit_platformdetect/board.py +++ b/adafruit_platformdetect/board.py @@ -16,19 +16,25 @@ **Software and Dependencies:** -* Linux and Python 3.6 or Higher +* Linux and Python 3.7 or Higher """ # imports -from __future__ import annotations import os import re -from typing import Optional, TYPE_CHECKING + +try: + from typing import TYPE_CHECKING, Optional +except ImportError: + TYPE_CHECKING = False + from .constants import boards, chips if TYPE_CHECKING: - from . import Detector + from .protocols import DetectorProtocol +else: + DetectorProtocol = ... __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_PlatformDetect.git" @@ -37,7 +43,8 @@ class Board: """Attempt to detect specific boards.""" - def __init__(self, detector: Detector) -> None: + # pylint: disable=used-before-assignment + def __init__(self, detector: DetectorProtocol) -> None: self.detector = detector self._board_id = None diff --git a/adafruit_platformdetect/chip.py b/adafruit_platformdetect/chip.py index c5b36a91..3b4edb54 100644 --- a/adafruit_platformdetect/chip.py +++ b/adafruit_platformdetect/chip.py @@ -20,14 +20,20 @@ """ # imports -from __future__ import annotations import os import sys -from typing import Optional, TYPE_CHECKING + +try: + from typing import TYPE_CHECKING, Optional +except ImportError: + TYPE_CHECKING = False + from .constants import chips if TYPE_CHECKING: - from . import Detector + from .protocols import DetectorProtocol +else: + DetectorProtocol = ... __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_PlatformDetect.git" @@ -36,7 +42,8 @@ class Chip: """Attempt detection of current chip / CPU.""" - def __init__(self, detector: Detector) -> None: + # pylint: disable=used-before-assignment + def __init__(self, detector: DetectorProtocol) -> None: self.detector = detector self._chip_id = None diff --git a/adafruit_platformdetect/protocols.py b/adafruit_platformdetect/protocols.py new file mode 100644 index 00000000..352ecd7f --- /dev/null +++ b/adafruit_platformdetect/protocols.py @@ -0,0 +1,80 @@ +# SPDX-FileCopyrightText: 2022 Chris Wilson +# +# SPDX-License-Identifier: MIT + +""" +`adafruit_platformdetect.protocols` +================================================================================ + +Protocol definitions + +* Author(s): Chris Wilson + +Implementation Notes +-------------------- + +**Software and Dependencies:** + +* Linux and Python 3.7 or Higher + +""" + +from typing import Optional + +# Protocol was introduced in Python 3.8. +try: + from typing import Protocol +except ImportError: + from typing_extensions import Protocol + + +class DetectorProtocol(Protocol): + """Wrap various platform detection functions.""" + + def get_cpuinfo_field(self, field: str) -> Optional[str]: + """ + Search /proc/cpuinfo for a field and return its value, if found, + otherwise None. + """ + ... + + def check_dt_compatible_value(self, value: str) -> bool: + """ + Search /proc/device-tree/compatible for a value and return True, if found, + otherwise False. + """ + ... + + def get_armbian_release_field(self, field: str) -> Optional[str]: + """ + Search /etc/armbian-release, if it exists, for a field and return its + value, if found, otherwise None. + """ + ... + + def get_device_model(self) -> Optional[str]: + """ + Search /proc/device-tree/model for the device model and return its value, if found, + otherwise None. + """ + ... + + def get_device_compatible(self) -> Optional[str]: + """ + Search /proc/device-tree/compatible for the compatible chip name. + """ + ... + + def check_board_asset_tag_value(self) -> Optional[str]: + """ + Search /sys/devices/virtual/dmi/id for the device model and return its value, if found, + otherwise None. + """ + ... + + def check_board_name_value(self) -> Optional[str]: + """ + Search /sys/devices/virtual/dmi/id for the board name and return its value, if found, + otherwise None. Debian/ubuntu based + """ + ... diff --git a/bin/detect.py b/bin/detect.py index 2fb3d59f..9c84209b 100644 --- a/bin/detect.py +++ b/bin/detect.py @@ -15,7 +15,7 @@ **Software and Dependencies:** -* Linux and Python 3.5 or Higher +* Linux and Python 3.7 or Higher """ diff --git a/docs/conf.py b/docs/conf.py index cfb54b90..06ed60f2 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -27,7 +27,7 @@ autodoc_mock_imports = ["machine"] intersphinx_mapping = { - "python": ("https://docs.python.org/3.6", None), + "python": ("https://docs.python.org/3.7", None), "CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None), } diff --git a/requirements.txt b/requirements.txt index e69de29b..9a4cd5fd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -0,0 +1,5 @@ +# SPDX-FileCopyrightText: 2022 Chris Wilson +# +# SPDX-License-Identifier: MIT + +typing_extensions; python_version <= '3.7' diff --git a/setup.py b/setup.py index 44dfa57c..c20aa195 100644 --- a/setup.py +++ b/setup.py @@ -28,12 +28,12 @@ description="Platform detection for use by libraries like Adafruit-Blinka.", long_description=long_description, long_description_content_type="text/x-rst", - python_requires=">=3.6.0", + python_requires=">=3.7.0", url="https://github.com/adafruit/Adafruit_Python_PlatformDetect", # If your package is a single module, use this instead of 'packages': author="Adafruit Industries", author_email="circuitpython@adafruit.com", - install_requires=[], + install_requires=["typing_extensions; python_version <= '3.7'"], # Choose your license license="MIT", # See https://pypi.python.org/pypi?%3Aaction=list_classifiers @@ -44,7 +44,7 @@ "Topic :: System :: Hardware", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", ], packages=["adafruit_platformdetect", "adafruit_platformdetect.constants"], )