mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Finish removing pkg_resources, closes #2057
This commit is contained in:
parent
6763572948
commit
10bc805473
1 changed files with 16 additions and 16 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
import importlib
|
import importlib.metadata
|
||||||
|
import importlib.resources
|
||||||
import os
|
import os
|
||||||
import pluggy
|
import pluggy
|
||||||
import pkg_resources
|
|
||||||
import sys
|
import sys
|
||||||
from . import hookspecs
|
from . import hookspecs
|
||||||
|
|
||||||
|
|
@ -35,15 +35,15 @@ if DATASETTE_LOAD_PLUGINS is not None:
|
||||||
name for name in DATASETTE_LOAD_PLUGINS.split(",") if name.strip()
|
name for name in DATASETTE_LOAD_PLUGINS.split(",") if name.strip()
|
||||||
]:
|
]:
|
||||||
try:
|
try:
|
||||||
distribution = pkg_resources.get_distribution(package_name)
|
distribution = importlib.metadata.distribution(package_name)
|
||||||
entry_map = distribution.get_entry_map()
|
entry_points = distribution.entry_points
|
||||||
if "datasette" in entry_map:
|
for entry_point in entry_points:
|
||||||
for plugin_name, entry_point in entry_map["datasette"].items():
|
if entry_point.group == "datasette":
|
||||||
mod = entry_point.load()
|
mod = entry_point.load()
|
||||||
pm.register(mod, name=entry_point.name)
|
pm.register(mod, name=entry_point.name)
|
||||||
# Ensure name can be found in plugin_to_distinfo later:
|
# Ensure name can be found in plugin_to_distinfo later:
|
||||||
pm._plugin_distinfo.append((mod, distribution))
|
pm._plugin_distinfo.append((mod, distribution))
|
||||||
except pkg_resources.DistributionNotFound:
|
except importlib.metadata.PackageNotFoundError:
|
||||||
sys.stderr.write("Plugin {} could not be found\n".format(package_name))
|
sys.stderr.write("Plugin {} could not be found\n".format(package_name))
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -61,16 +61,16 @@ def get_plugins():
|
||||||
templates_path = None
|
templates_path = None
|
||||||
if plugin.__name__ not in DEFAULT_PLUGINS:
|
if plugin.__name__ not in DEFAULT_PLUGINS:
|
||||||
try:
|
try:
|
||||||
if pkg_resources.resource_isdir(plugin.__name__, "static"):
|
if (importlib.resources.files(plugin.__name__) / "static").is_dir():
|
||||||
static_path = pkg_resources.resource_filename(
|
static_path = str(
|
||||||
plugin.__name__, "static"
|
importlib.resources.files(plugin.__name__) / "static"
|
||||||
)
|
)
|
||||||
if pkg_resources.resource_isdir(plugin.__name__, "templates"):
|
if (importlib.resources.files(plugin.__name__) / "templates").is_dir():
|
||||||
templates_path = pkg_resources.resource_filename(
|
templates_path = str(
|
||||||
plugin.__name__, "templates"
|
importlib.resources.files(plugin.__name__) / "templates"
|
||||||
)
|
)
|
||||||
except (KeyError, ImportError):
|
except (TypeError, ModuleNotFoundError):
|
||||||
# Caused by --plugins_dir= plugins - KeyError/ImportError thrown in Py3.5
|
# Caused by --plugins_dir= plugins
|
||||||
pass
|
pass
|
||||||
plugin_info = {
|
plugin_info = {
|
||||||
"name": plugin.__name__,
|
"name": plugin.__name__,
|
||||||
|
|
@ -81,6 +81,6 @@ def get_plugins():
|
||||||
distinfo = plugin_to_distinfo.get(plugin)
|
distinfo = plugin_to_distinfo.get(plugin)
|
||||||
if distinfo:
|
if distinfo:
|
||||||
plugin_info["version"] = distinfo.version
|
plugin_info["version"] = distinfo.version
|
||||||
plugin_info["name"] = distinfo.project_name
|
plugin_info["name"] = distinfo.name
|
||||||
plugins.append(plugin_info)
|
plugins.append(plugin_info)
|
||||||
return plugins
|
return plugins
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue