Security fixes for IPython (#11069)
Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>
This commit is contained in:
1 parent
7dee52f94d
commit
3c0a6e664b
4 files changed
+24
-12
No files matched your search
+4
-2
@@ -60,17 +60,19 @@ def notebook_init(verbose=True):
|
||||
check_font()
|
||||
|
||||
import psutil
|
||||
from IPython import display # to display images and clear console output
|
||||
|
||||
if is_colab():
|
||||
shutil.rmtree('/content/sample_data', ignore_errors=True) # remove colab /sample_data directory
|
||||
|
||||
# System info
|
||||
display = None
|
||||
if verbose:
|
||||
gb = 1 << 30 # bytes to GiB (1024 ** 3)
|
||||
ram = psutil.virtual_memory().total
|
||||
total, used, free = shutil.disk_usage('/')
|
||||
display.clear_output()
|
||||
with contextlib.suppress(Exception): # clear display if ipython is installed
|
||||
from IPython import display
|
||||
display.clear_output()
|
||||
s = f'({os.cpu_count()} CPUs, {ram / gb:.1f} GB RAM, {(total - free) / gb:.1f}/{total / gb:.1f} GB disk)'
|
||||
else:
|
||||
s = ''
|
||||
|
||||
+13
-6
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user