Security fixes for IPython (#11069)

Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>
This commit is contained in:
Glenn Jocher authored and GitHub committed 2023-02-25 16:15:07 -08:00
1 parent 7dee52f94d
commit 3c0a6e664b
4 files changed
+24 -12

No files matched your search

+13 -6
View File
@@ -29,7 +29,6 @@ from typing import Optional
from zipfile import ZipFile, is_zipfile
import cv2
import IPython
import numpy as np
import pandas as pd
import pkg_resources as pkg
@@ -77,10 +76,18 @@ def is_colab():
return 'google.colab' in sys.modules
def is_notebook():
# Is environment a Jupyter notebook? Verified on Colab, Jupyterlab, Kaggle, Paperspace
ipython_type = str(type(IPython.get_ipython()))
return 'colab' in ipython_type or 'zmqshell' in ipython_type
def is_jupyter():
"""
Check if the current script is running inside a Jupyter Notebook.
Verified on Colab, Jupyterlab, Kaggle, Paperspace.
Returns:
bool: True if running inside a Jupyter Notebook, False otherwise.
"""
with contextlib.suppress(Exception):
from IPython import get_ipython
return get_ipython() is not None
return False
def is_kaggle():
@@ -429,7 +436,7 @@ def check_img_size(imgsz, s=32, floor=0):
def check_imshow(warn=False):
# Check if environment supports image displays
try:
assert not is_notebook()
assert not is_jupyter()
assert not is_docker()
cv2.imshow('test', np.zeros((1, 1, 3)))
cv2.waitKey(1)