|
29 | 29 | physical_processor_count, |
30 | 30 | total_physical_memory, |
31 | 31 | ) |
32 | | -from newrelic.core.config import global_settings |
33 | 32 | from newrelic.packages.isort import stdlibs as isort_stdlibs |
34 | 33 |
|
35 | 34 | try: |
@@ -198,58 +197,54 @@ def environment_settings(): |
198 | 197 |
|
199 | 198 | env.extend(dispatcher) |
200 | 199 |
|
| 200 | + return env |
| 201 | + |
| 202 | + |
| 203 | +def plugins(): |
201 | 204 | # Module information. |
202 | 205 | stdlib_builtin_module_names = _get_stdlib_builtin_module_names() |
203 | 206 |
|
204 | | - plugins = [] |
205 | | - |
206 | | - settings = global_settings() |
207 | | - if settings and settings.package_reporting.enabled: |
208 | | - # Using any iterable to create a snapshot of sys.modules can occassionally |
209 | | - # fail in a rare case when modules are imported in parallel by different |
210 | | - # threads. |
211 | | - # |
212 | | - # TL;DR: Do NOT use an iterable on the original sys.modules to generate the |
213 | | - # list |
214 | | - for name, module in sys.modules.copy().items(): |
215 | | - # Exclude lib.sub_paths as independent modules except for newrelic.hooks. |
216 | | - nr_hook = name.startswith("newrelic.hooks.") |
217 | | - if "." in name and not nr_hook or name.startswith("_"): |
| 207 | + # Using any iterable to create a snapshot of sys.modules can occassionally |
| 208 | + # fail in a rare case when modules are imported in parallel by different |
| 209 | + # threads. |
| 210 | + # |
| 211 | + # TL;DR: Do NOT use an iterable on the original sys.modules to generate the |
| 212 | + # list |
| 213 | + for name, module in sys.modules.copy().items(): |
| 214 | + # Exclude lib.sub_paths as independent modules except for newrelic.hooks. |
| 215 | + nr_hook = name.startswith("newrelic.hooks.") |
| 216 | + if "." in name and not nr_hook or name.startswith("_"): |
| 217 | + continue |
| 218 | + |
| 219 | + # If the module isn't actually loaded (such as failed relative imports |
| 220 | + # in Python 2.7), the module will be None and should not be reported. |
| 221 | + try: |
| 222 | + if not module: |
218 | 223 | continue |
219 | | - |
220 | | - # If the module isn't actually loaded (such as failed relative imports |
221 | | - # in Python 2.7), the module will be None and should not be reported. |
| 224 | + except Exception: # nosec B112 |
| 225 | + # if the application uses generalimport to manage optional depedencies, |
| 226 | + # it's possible that generalimport.MissingOptionalDependency is raised. |
| 227 | + # In this case, we should not report the module as it is not actually loaded and |
| 228 | + # is not a runtime dependency of the application. |
| 229 | + # |
| 230 | + continue |
| 231 | + |
| 232 | + # Exclude standard library/built-in modules. |
| 233 | + if name in stdlib_builtin_module_names: |
| 234 | + continue |
| 235 | + |
| 236 | + # Don't attempt to look up version information for our hooks |
| 237 | + version = None |
| 238 | + if not nr_hook: |
222 | 239 | try: |
223 | | - if not module: |
224 | | - continue |
| 240 | + version = get_package_version(name) |
225 | 241 | except Exception: |
226 | | - # if the application uses generalimport to manage optional depedencies, |
227 | | - # it's possible that generalimport.MissingOptionalDependency is raised. |
228 | | - # In this case, we should not report the module as it is not actually loaded and |
229 | | - # is not a runtime dependency of the application. |
230 | | - # |
231 | | - continue |
232 | | - |
233 | | - # Exclude standard library/built-in modules. |
234 | | - if name in stdlib_builtin_module_names: |
235 | | - continue |
236 | | - |
237 | | - # Don't attempt to look up version information for our hooks |
238 | | - version = None |
239 | | - if not nr_hook: |
240 | | - try: |
241 | | - version = get_package_version(name) |
242 | | - except Exception: |
243 | | - pass |
244 | | - |
245 | | - # If it has no version it's likely not a real package so don't report it unless |
246 | | - # it's a new relic hook. |
247 | | - if nr_hook or version: |
248 | | - plugins.append(f"{name} ({version})") |
249 | | - |
250 | | - env.append(("Plugin List", plugins)) |
| 242 | + pass |
251 | 243 |
|
252 | | - return env |
| 244 | + # If it has no version it's likely not a real package so don't report it unless |
| 245 | + # it's a new relic hook. |
| 246 | + if nr_hook or version: |
| 247 | + yield [name, version, {}] if version else [name, " ", {}] |
253 | 248 |
|
254 | 249 |
|
255 | 250 | def _get_stdlib_builtin_module_names(): |
|
0 commit comments