Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Automatic plugin discovery

Patryk Zawadzki9e244aced521
diff --git a/.isort.cfg b/.isort.cfg
index 42a876e47e..332869e190 100644
--- a/.isort.cfg
+++ b/.isort.cfg
@@ -1,2 +1,2 @@
[settings]
-known_third_party = PIL,babel,braintree,celery,dj_database_url,dj_email_url,django,django_cache_url,django_countries,django_filters,django_measurement,django_prices,django_prices_openexchangerates,django_prices_vatlayer,draftjs_sanitizer,faker,freezegun,geolite2,google_measurement_protocol,graphene,graphene_django,graphene_federation,graphql,graphql_jwt,graphql_relay,html_to_draftjs,i18naddress,jaeger_client,jwt,markdown,measurement,mptt,oauthlib,opentracing,phonenumber_field,phonenumbers,prices,promise,pytest,pytz,razorpay,requests,sentry_sdk,storages,stripe,templated_email,text_unidecode,tqdm,versatileimagefield
+known_third_party = PIL,babel,braintree,celery,dj_database_url,dj_email_url,django,django_cache_url,django_countries,django_filters,django_measurement,django_prices,django_prices_openexchangerates,django_prices_vatlayer,draftjs_sanitizer,faker,freezegun,geolite2,google_measurement_protocol,graphene,graphene_django,graphene_federation,graphql,graphql_jwt,graphql_relay,html_to_draftjs,i18naddress,jaeger_client,jwt,markdown,measurement,mptt,oauthlib,opentracing,phonenumber_field,phonenumbers,pkg_resources,prices,promise,pytest,pytz,razorpay,requests,sentry_sdk,storages,stripe,templated_email,text_unidecode,tqdm,versatileimagefield
diff --git a/saleor/settings.py b/saleor/settings.py
index 86200069c2..d1720b557b 100644
--- a/saleor/settings.py
+++ b/saleor/settings.py
@@ -8,6 +8,7 @@ import dj_email_url
import django_cache_url
import jaeger_client
import jaeger_client.config
+import pkg_resources
import sentry_sdk
from django.core.exceptions import ImproperlyConfigured
from django.core.management.utils import get_random_secret_key
@@ -518,6 +519,15 @@ PLUGINS = [
"saleor.payment.gateways.razorpay.plugin.RazorpayGatewayPlugin",
]
+# Plugin discovery
+installed_plugins = pkg_resources.iter_entry_points("saleor.plugins")
+for entry_point in installed_plugins:
+ plugin_path = "{}.{}".format(entry_point.module_name, entry_point.attrs[0])
+ if plugin_path not in PLUGINS:
+ if entry_point.name not in INSTALLED_APPS:
+ INSTALLED_APPS.append(entry_point.name)
+ PLUGINS.append(plugin_path)
+
if (
not DEBUG
and ENABLE_ACCOUNT_CONFIRMATION_BY_EMAIL