Skip to content

Commit

Permalink
importlib_resources for Python < 3.9, refs #2057
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Sep 21, 2023
1 parent 947520c commit b0d0a0e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
15 changes: 10 additions & 5 deletions datasette/plugins.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import importlib.metadata
import importlib.resources
import os
import pluggy
import sys
from . import hookspecs

if sys.version_info >= (3, 9):
import importlib.resources as importlib_resources
else:
import importlib_resources


DEFAULT_PLUGINS = (
"datasette.publish.heroku",
"datasette.publish.cloudrun",
Expand Down Expand Up @@ -61,13 +66,13 @@ def get_plugins():
templates_path = None
if plugin.__name__ not in DEFAULT_PLUGINS:
try:
if (importlib.resources.files(plugin.__name__) / "static").is_dir():
if (importlib_resources.files(plugin.__name__) / "static").is_dir():
static_path = str(
importlib.resources.files(plugin.__name__) / "static"
importlib_resources.files(plugin.__name__) / "static"
)
if (importlib.resources.files(plugin.__name__) / "templates").is_dir():
if (importlib_resources.files(plugin.__name__) / "templates").is_dir():
templates_path = str(
importlib.resources.files(plugin.__name__) / "templates"
importlib_resources.files(plugin.__name__) / "templates"
)
except (TypeError, ModuleNotFoundError):
# Caused by --plugins_dir= plugins
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def get_version():
"Jinja2>=2.10.3",
"hupper>=1.9",
"httpx>=0.20",
'importlib_resources>=1.3.1; python_version < "3.9"',
"pint>=0.9",
"pluggy>=1.0",
"uvicorn>=0.11",
Expand Down

0 comments on commit b0d0a0e

Please sign in to comment.