From d3cfb72266a873cef1e8bfd748e8c46aa01b28bc Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Tue, 11 Jan 2022 17:41:48 +0100 Subject: [PATCH] Use importlib_resources --- lib/galaxy/config/__init__.py | 8 ++++++-- lib/galaxy/webapps/base/webapp.py | 8 ++++++-- packages/webapps/requirements.txt | 1 + 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/galaxy/config/__init__.py b/lib/galaxy/config/__init__.py index 4071e92bf67..097cbd907a2 100644 --- a/lib/galaxy/config/__init__.py +++ b/lib/galaxy/config/__init__.py @@ -6,7 +6,6 @@ Universe configuration builder. import collections import configparser import errno -import importlib.resources import ipaddress import logging import logging.config @@ -63,6 +62,11 @@ from galaxy.web.formatting import expand_pretty_datetime_format from galaxy.web_stack import get_stack_facts from ..version import VERSION_MAJOR, VERSION_MINOR +try: + from importlib.resources import files +except ImportError: + from importlib_resources import files + if TYPE_CHECKING: from galaxy.jobs import JobConfiguration from galaxy.tool_util.deps.containers import ContainerFinder @@ -73,7 +77,7 @@ if TYPE_CHECKING: log = logging.getLogger(__name__) GALAXY_APP_NAME = 'galaxy' -GALAXY_CONFIG_SCHEMA_PATH = importlib.resources.files('galaxy.webapps.galaxy') / 'config_schema.yml' +GALAXY_CONFIG_SCHEMA_PATH = files('galaxy.webapps.galaxy') / 'config_schema.yml' LOGGING_CONFIG_DEFAULT: Dict[str, Any] = { 'disable_existing_loggers': False, 'version': 1, diff --git a/lib/galaxy/webapps/base/webapp.py b/lib/galaxy/webapps/base/webapp.py index 9c10c58c4e8..374cf0afb29 100644 --- a/lib/galaxy/webapps/base/webapp.py +++ b/lib/galaxy/webapps/base/webapp.py @@ -1,7 +1,6 @@ """ """ import datetime -import importlib.resources import inspect import logging import os @@ -42,6 +41,11 @@ from galaxy.web.framework import ( ) from galaxy.web_stack import get_app_kwds +try: + from importlib.resources import files +except ImportError: + from importlib_resources import files + log = logging.getLogger(__name__) @@ -91,7 +95,7 @@ class WebApplication(base.WebApplication): def create_mako_template_lookup(self, galaxy_app, name): paths = [] - base_template_path = importlib.resources.files('galaxy.webapps.base') / 'templates' + base_template_path = files('galaxy.webapps.base') / 'templates' app_template_path = base_template_path / 'webapps' # First look in webapp specific directory if name is not None: diff --git a/packages/webapps/requirements.txt b/packages/webapps/requirements.txt index a932b6c2948..7a195cd8db1 100644 --- a/packages/webapps/requirements.txt +++ b/packages/webapps/requirements.txt @@ -2,6 +2,7 @@ galaxy-app Cheetah3 fastapi>=0.68.2,!=0.69.0,!=0.70.0,!=0.70.1 fastapi-utils +importlib_resources Mako pydantic python-multipart # required to support form parsing in FastAPI/Starlette