From c56a8ef8f7897d14ee18d85cf6bd984697c94e41 Mon Sep 17 00:00:00 2001 From: grossmj Date: Fri, 30 Dec 2022 09:15:40 +0800 Subject: [PATCH] Only use importlib_resources for Python < 3.9. Fixes #2147 --- gns3server/controller/__init__.py | 6 +++++- gns3server/controller/appliance_manager.py | 7 ++++++- gns3server/utils/get_resource.py | 7 ++++++- requirements.txt | 2 +- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/gns3server/controller/__init__.py b/gns3server/controller/__init__.py index 5c5236b9..4b8a5001 100644 --- a/gns3server/controller/__init__.py +++ b/gns3server/controller/__init__.py @@ -22,7 +22,11 @@ import uuid import socket import shutil import aiohttp -import importlib_resources + +try: + import importlib_resources +except ImportError: + from importlib import resources as importlib_resources from ..config import Config from .project import Project diff --git a/gns3server/controller/appliance_manager.py b/gns3server/controller/appliance_manager.py index d15fc69b..ea2b294a 100644 --- a/gns3server/controller/appliance_manager.py +++ b/gns3server/controller/appliance_manager.py @@ -21,9 +21,14 @@ import json import uuid import asyncio import aiohttp -import importlib_resources import shutil +try: + import importlib_resources +except ImportError: + from importlib import resources as importlib_resources + + from .appliance import Appliance from ..config import Config from ..utils.asyncio import locking diff --git a/gns3server/utils/get_resource.py b/gns3server/utils/get_resource.py index b4b599bd..56aab259 100644 --- a/gns3server/utils/get_resource.py +++ b/gns3server/utils/get_resource.py @@ -19,7 +19,12 @@ import atexit import logging import os import sys -import importlib_resources + +try: + import importlib_resources +except ImportError: + from importlib import resources as importlib_resources + from contextlib import ExitStack resource_manager = ExitStack() diff --git a/requirements.txt b/requirements.txt index 41c81b77..ca7d7934 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,6 +11,6 @@ psutil==5.9.4 async-timeout>=4.0.2,<4.1 distro>=1.7.0 py-cpuinfo>=9.0.0,<10.0 -importlib-resources>=1.3 +importlib-resources>=1.3; python_version < '3.9' setuptools>=60.8.1; python_version >= '3.7' setuptools==59.6.0; python_version < '3.7' # v59.6.0 is the last version to support Python 3.6