Skip to content

Commit

Permalink
ref(messaging): Removing Integration Namespace Imports (#72033)
Browse files Browse the repository at this point in the history
Importing the entire `integration` module is bad practice and it turns
out we only do it to access the `IntegrationManager`. I moved the
instantiation of the manager back to the original file and import the
manager directly.
  • Loading branch information
iamrajjoshi authored Jun 4, 2024
1 parent 2a5bd98 commit 25c760f
Show file tree
Hide file tree
Showing 14 changed files with 24 additions and 22 deletions.
3 changes: 2 additions & 1 deletion src/sentry/api/endpoints/group_integrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
from rest_framework.request import Request
from rest_framework.response import Response

from sentry import features, integrations
from sentry import features
from sentry.api.api_publish_status import ApiPublishStatus
from sentry.api.base import region_silo_endpoint
from sentry.api.bases import GroupEndpoint
from sentry.api.serializers import IntegrationSerializer, serialize
from sentry.integrations.base import IntegrationFeatures
from sentry.integrations.manager import default_manager as integrations
from sentry.models.group import Group
from sentry.models.grouplink import GroupLink
from sentry.models.integrations.external_issue import ExternalIssue
Expand Down
3 changes: 2 additions & 1 deletion src/sentry/api/endpoints/integrations/index.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from rest_framework.request import Request
from rest_framework.response import Response

from sentry import features, integrations
from sentry import features
from sentry.api.api_owners import ApiOwner
from sentry.api.api_publish_status import ApiPublishStatus
from sentry.api.base import region_silo_endpoint
from sentry.api.bases.organization import OrganizationEndpoint
from sentry.api.serializers import serialize
from sentry.api.serializers.models.integration import IntegrationProviderSerializer
from sentry.integrations.manager import default_manager as integrations


@region_silo_endpoint
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/api/endpoints/integrations/install_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
from rest_framework.request import Request
from rest_framework.response import Response

from sentry import integrations
from sentry.api.api_owners import ApiOwner
from sentry.api.api_publish_status import ApiPublishStatus
from sentry.api.base import region_silo_endpoint
from sentry.api.bases.organization_request_change import OrganizationRequestChangeEndpoint
from sentry.integrations.manager import default_manager as integrations
from sentry.notifications.notifications.organization_request.integration_request import (
IntegrationRequestNotification,
)
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/api/endpoints/project_repo_path_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
from rest_framework.request import Request
from rest_framework.response import Response

from sentry import integrations
from sentry.api.api_publish_status import ApiPublishStatus
from sentry.api.base import region_silo_endpoint
from sentry.api.bases.project import ProjectEndpoint, ProjectPermission
from sentry.api.serializers.rest_framework.base import CamelSnakeSerializer
from sentry.integrations.base import IntegrationFeatures
from sentry.integrations.manager import default_manager as integrations
from sentry.integrations.utils.code_mapping import find_roots
from sentry.models.repository import Repository
from sentry.services.hybrid_cloud.integration import RpcIntegration, integration_service
Expand Down
4 changes: 2 additions & 2 deletions src/sentry/api/serializers/models/user_identity_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

from django.db.models.base import Model

import sentry.integrations
from sentry.api.serializers import Serializer, register, serialize
from sentry.api.serializers.models import ControlSiloOrganizationSerializer
from sentry.auth.provider import Provider
from sentry.exceptions import NotRegistered
from sentry.identity import is_login_provider
from sentry.integrations.manager import default_manager as integrations
from sentry.models.authidentity import AuthIdentity
from sentry.models.identity import Identity
from sentry.services.hybrid_cloud.organization_mapping import organization_mapping_service
Expand Down Expand Up @@ -88,7 +88,7 @@ def base(**kwargs):
try:
provider = identity.get_provider()
except NotRegistered:
provider = sentry.integrations.get(identity.idp.type)
provider = integrations.get(identity.idp.type)

return base(
provider=UserIdentityProvider.adapt(provider),
Expand Down
9 changes: 0 additions & 9 deletions src/sentry/integrations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,3 @@
from .analytics import register_analytics

register_analytics()

from .manager import IntegrationManager

default_manager = IntegrationManager()
all = default_manager.all
get = default_manager.get
exists = default_manager.exists
register = default_manager.register
unregister = default_manager.unregister
8 changes: 8 additions & 0 deletions src/sentry/integrations/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,11 @@ def unregister(self, cls: type[IntegrationProvider]) -> None:
# we gracefully handle a missing provider
return
del self.__values[cls.key]


default_manager = IntegrationManager()
all = default_manager.all
get = default_manager.get
exists = default_manager.exists
register = default_manager.register
unregister = default_manager.unregister
2 changes: 1 addition & 1 deletion src/sentry/integrations/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

logger = logging.getLogger(__name__)

from . import default_manager
from sentry.integrations.manager import default_manager


def ensure_integration(key, data):
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/models/integrations/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


def get_provider(instance: Integration | RpcIntegration) -> IntegrationProvider:
from sentry import integrations
from sentry.integrations.manager import default_manager as integrations

return integrations.get(instance.provider)

Expand Down
2 changes: 1 addition & 1 deletion src/sentry/notifications/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
from django.utils.safestring import mark_safe
from django.utils.translation import gettext_lazy as _

from sentry import integrations
from sentry.eventstore.models import Event, GroupEvent
from sentry.incidents.models.alert_rule import AlertRuleTriggerAction
from sentry.integrations.base import IntegrationFeatures, IntegrationProvider
from sentry.integrations.manager import default_manager as integrations
from sentry.issues.grouptype import (
PerformanceConsecutiveDBQueriesGroupType,
PerformanceNPlusOneAPICallsGroupType,
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/runner/initializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def register_plugins(settings: Any, raise_on_plugin_load_failure: bool = False)
for plugin in plugins.all(version=None):
init_plugin(plugin)

from sentry import integrations
from sentry.integrations.manager import default_manager as integrations
from sentry.utils.imports import import_string

for integration_path in settings.SENTRY_DEFAULT_INTEGRATIONS:
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/testutils/pytest/sentry.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@ def register_extensions() -> None:

plugins.register(TestIssuePlugin2)

from sentry import integrations
from sentry.integrations.example import (
AlertRuleIntegrationProvider,
AliasedIntegrationProvider,
Expand All @@ -322,6 +321,7 @@ def register_extensions() -> None:
FeatureFlagIntegration,
ServerExampleProvider,
)
from sentry.integrations.manager import default_manager as integrations

integrations.register(ExampleIntegrationProvider)
integrations.register(AliasedIntegrationProvider)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from django.urls import reverse
from django.utils.http import urlencode

from sentry import features, integrations
from sentry import features
from sentry.integrations.manager import default_manager as integrations
from sentry.integrations.pipeline import IntegrationPipeline
from sentry.services.hybrid_cloud.organization import organization_service
from sentry.services.hybrid_cloud.user.service import user_service
Expand Down
2 changes: 1 addition & 1 deletion tests/sentry/integrations/test_manager.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from sentry import integrations
from sentry.integrations.manager import default_manager as integrations
from sentry.integrations.vsts_extension import VstsExtensionIntegrationProvider
from sentry.testutils.cases import TestCase

Expand Down

0 comments on commit 25c760f

Please sign in to comment.