-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Defer import of matplotlib until needed (#3579)
* Defer import of matplotlib until needed matplotlib has a heavy dep chain Fixes #3578 * relocate * pyx relo * update docstrings * git add file * fix typo * fix typo * naming * missed one * adjust logging to try to figure out why it fails on py27 windows * fix py27 windows * unguarded raise * try to make py27 happy * name collision? * tweak * rename to avoid name collision
- Loading branch information
Showing
8 changed files
with
98 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# This file is part of Scapy | ||
# See http://www.secdev.org/projects/scapy for more information | ||
# Copyright (C) Philippe Biondi <phil@secdev.org> | ||
# This program is published under a GPLv2 license | ||
|
||
""" | ||
External link to matplotlib | ||
""" | ||
|
||
from scapy.error import log_loading | ||
|
||
# Notice: this file must not be called before main.py, if started | ||
# in interactive mode, because it needs to be called after the | ||
# logger has been setup, to be able to print the warning messages | ||
|
||
__all__ = [ | ||
"Line2D", | ||
"MATPLOTLIB", | ||
"MATPLOTLIB_DEFAULT_PLOT_KARGS", | ||
"MATPLOTLIB_INLINED", | ||
"plt", | ||
] | ||
|
||
# MATPLOTLIB | ||
|
||
try: | ||
from matplotlib import get_backend as matplotlib_get_backend | ||
from matplotlib import pyplot as plt | ||
from matplotlib.lines import Line2D | ||
MATPLOTLIB = 1 | ||
if "inline" in matplotlib_get_backend(): | ||
MATPLOTLIB_INLINED = 1 | ||
else: | ||
MATPLOTLIB_INLINED = 0 | ||
MATPLOTLIB_DEFAULT_PLOT_KARGS = {"marker": "+"} | ||
# RuntimeError to catch gtk "Cannot open display" error | ||
except (ImportError, RuntimeError) as ex: | ||
plt = None | ||
Line2D = None | ||
MATPLOTLIB = 0 | ||
MATPLOTLIB_INLINED = 0 | ||
MATPLOTLIB_DEFAULT_PLOT_KARGS = dict() | ||
log_loading.info("Can't import matplotlib: %s. Won't be able to plot.", ex) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters