6
6
7
7
8
8
if TYPE_CHECKING :
9
+ from collections .abc import Sequence
9
10
from typing import Callable
10
11
from typing import Dict
11
12
from typing import Iterator
12
13
from typing import List
14
+ from typing import Optional
13
15
from typing import Set
14
16
from typing import Type
15
17
@@ -114,21 +116,33 @@ def iter_default_integrations(with_auto_enabling_integrations):
114
116
115
117
116
118
def setup_integrations (
117
- integrations , with_defaults = True , with_auto_enabling_integrations = False
119
+ integrations ,
120
+ with_defaults = True ,
121
+ with_auto_enabling_integrations = False ,
122
+ disabled_integrations = None ,
118
123
):
119
- # type: (List [Integration], bool, bool) -> Dict[str, Integration]
124
+ # type: (Sequence [Integration], bool, bool, Optional[Sequence[Integration]] ) -> Dict[str, Integration]
120
125
"""
121
126
Given a list of integration instances, this installs them all.
122
127
123
128
When `with_defaults` is set to `True` all default integrations are added
124
129
unless they were already provided before.
130
+
131
+ `disabled_integrations` takes precedence over `with_defaults` and
132
+ `with_auto_enabling_integrations`.
125
133
"""
126
134
integrations = dict (
127
135
(integration .identifier , integration ) for integration in integrations or ()
128
136
)
129
137
130
138
logger .debug ("Setting up integrations (with default = %s)" , with_defaults )
131
139
140
+ # Integrations that will not be enabled
141
+ disabled_integrations = [
142
+ integration if isinstance (integration , type ) else type (integration )
143
+ for integration in disabled_integrations or []
144
+ ]
145
+
132
146
# Integrations that are not explicitly set up by the user.
133
147
used_as_default_integration = set ()
134
148
@@ -144,20 +158,23 @@ def setup_integrations(
144
158
for identifier , integration in integrations .items ():
145
159
with _installer_lock :
146
160
if identifier not in _processed_integrations :
147
- logger .debug (
148
- "Setting up previously not enabled integration %s" , identifier
149
- )
150
- try :
151
- type (integration ).setup_once ()
152
- except DidNotEnable as e :
153
- if identifier not in used_as_default_integration :
154
- raise
155
-
161
+ if type (integration ) in disabled_integrations :
162
+ logger .debug ("Ignoring integration %s" , identifier )
163
+ else :
156
164
logger .debug (
157
- "Did not enable default integration %s: %s " , identifier , e
165
+ "Setting up previously not enabled integration %s" , identifier
158
166
)
159
- else :
160
- _installed_integrations .add (identifier )
167
+ try :
168
+ type (integration ).setup_once ()
169
+ except DidNotEnable as e :
170
+ if identifier not in used_as_default_integration :
171
+ raise
172
+
173
+ logger .debug (
174
+ "Did not enable default integration %s: %s" , identifier , e
175
+ )
176
+ else :
177
+ _installed_integrations .add (identifier )
161
178
162
179
_processed_integrations .add (identifier )
163
180
0 commit comments