2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-05-01 21:16:46 +00:00

Fix for allowing plugins without explicit metadata (#3769)

This commit is contained in:
Oliver 2022-10-12 00:16:12 +11:00 committed by GitHub
parent cfabf67b67
commit 531c39725c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 4 deletions

View File

@ -64,6 +64,7 @@ def handle_error(error, do_raise: bool = True, do_log: bool = True, log_name: st
"""Handles an error and casts it as an IntegrationPluginError.""" """Handles an error and casts it as an IntegrationPluginError."""
package_path = traceback.extract_tb(error.__traceback__)[-1].filename package_path = traceback.extract_tb(error.__traceback__)[-1].filename
install_path = sysconfig.get_paths()["purelib"] install_path = sysconfig.get_paths()["purelib"]
try: try:
package_name = pathlib.Path(package_path).relative_to(install_path).parts[0] package_name = pathlib.Path(package_path).relative_to(install_path).parts[0]
except ValueError: except ValueError:
@ -88,9 +89,10 @@ def handle_error(error, do_raise: bool = True, do_log: bool = True, log_name: st
log_error({package_name: str(error)}, **log_kwargs) log_error({package_name: str(error)}, **log_kwargs)
if do_raise: if do_raise:
# do a straight raise if we are playing with enviroment variables at execution time, ignore the broken sample # do a straight raise if we are playing with environment variables at execution time, ignore the broken sample
if settings.TESTING_ENV and package_name != 'integration.broken_sample' and isinstance(error, IntegrityError): if settings.TESTING_ENV and package_name != 'integration.broken_sample' and isinstance(error, IntegrityError):
raise error # pragma: no cover raise error # pragma: no cover
raise IntegrationPluginError(package_name, str(error)) raise IntegrationPluginError(package_name, str(error))
# endregion # endregion

View File

@ -6,7 +6,7 @@ import os
import pathlib import pathlib
import warnings import warnings
from datetime import datetime from datetime import datetime
from importlib.metadata import metadata from importlib.metadata import PackageNotFoundError, metadata
from django.conf import settings from django.conf import settings
from django.db.utils import OperationalError, ProgrammingError from django.db.utils import OperationalError, ProgrammingError
@ -294,7 +294,18 @@ class InvenTreePlugin(MixinBase, MetaBase):
@classmethod @classmethod
def _get_package_metadata(cls): def _get_package_metadata(cls):
"""Get package metadata for plugin.""" """Get package metadata for plugin."""
meta = metadata(cls.__name__)
# Try simple metadata lookup
try:
meta = metadata(cls.__name__)
# Simple lookup did not work - get data from module
except PackageNotFoundError:
try:
meta = metadata(cls.__module__.split('.')[0])
except PackageNotFoundError:
# Not much information we can extract at this point
return {}
return { return {
'author': meta['Author-email'], 'author': meta['Author-email'],

View File

@ -7,7 +7,7 @@
{% block heading %} {% block heading %}
{% blocktrans with name=plugin.human_name %}Plugin details for {{name}}{% endblocktrans %} {% trans "Plugin" %}: <em>{{ plugin.human_name }}</em>
{% endblock %} {% endblock %}
{% block content %} {% block content %}