From 613cdc10bc61dbb902a42ccb11fcb472a160771e Mon Sep 17 00:00:00 2001 From: Catherine Date: Wed, 4 Oct 2023 00:19:06 +0000 Subject: [PATCH] support.plugin: add python 3.8-3.9 support. --- .github/workflows/main.yml | 4 +++- software/glasgow/support/plugin.py | 13 ++++++++----- software/pyproject.toml | 1 + 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c5fa32377..64115f5b9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -51,7 +51,9 @@ jobs: YOSYS: yowasp-yosys NEXTPNR_ICE40: yowasp-nextpnr-ice40 ICEPACK: yowasp-icepack - run: pdm run test + run: | + pdm run glasgow --help + pdm run test build-firmware: if: (github.event.ref == 'refs/heads/main' || github.event_name == 'pull_request') || github.repository != 'GlasgowEmbedded/glasgow' diff --git a/software/glasgow/support/plugin.py b/software/glasgow/support/plugin.py index e2e379f88..e8e32c270 100644 --- a/software/glasgow/support/plugin.py +++ b/software/glasgow/support/plugin.py @@ -1,8 +1,11 @@ -import importlib.metadata import packaging.requirements import pathlib import sysconfig import textwrap +try: + import importlib_metadata # py3.9- +except ImportError: + import importlib.metadata as importlib_metadata __all__ = ["PluginRequirementsUnmet", "PluginMetadata"] @@ -24,8 +27,8 @@ def _unmet_requirements_in(requirements): unmet_requirements = set() for requirement in requirements: try: - version = importlib.metadata.version(requirement.name) - except importlib.metadata.PackageNotFoundError: + version = importlib_metadata.version(requirement.name) + except importlib_metadata.PackageNotFoundError: unmet_requirements.add(requirement) continue if not requirement.specifier.contains(version): @@ -64,11 +67,11 @@ class PluginMetadata: @classmethod def get(cls, handle): - return cls(importlib.metadata.entry_points(group=cls.GROUP_NAME, name=handle)[0]) + return cls(importlib_metadata.entry_points(group=cls.GROUP_NAME, name=handle)[0]) @classmethod def all(cls): - return {ep.name: cls(ep) for ep in importlib.metadata.entry_points(group=cls.GROUP_NAME)} + return {ep.name: cls(ep) for ep in importlib_metadata.entry_points(group=cls.GROUP_NAME)} def __init__(self, entry_point): if entry_point.dist.name != "glasgow": diff --git a/software/pyproject.toml b/software/pyproject.toml index 30da71e6a..4b40abad2 100644 --- a/software/pyproject.toml +++ b/software/pyproject.toml @@ -18,6 +18,7 @@ classifiers = [ requires-python = "~=3.8" dependencies = [ "packaging>=23", + "importlib_metadata; python_version<'3.10'", "appdirs~=1.4", "amaranth[builtin-yosys] @ git+https://github.com/amaranth-lang/amaranth.git", "fx2>=0.11",