Skip to content

Commit 7197d26

Browse files
authored
Merge pull request #236 from QuLogic/remove-genutils
Remove use of ipython_genutils
2 parents 24a39f3 + 8b6d845 commit 7197d26

File tree

3 files changed

+16
-18
lines changed

3 files changed

+16
-18
lines changed

.github/workflows/python-package.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
- name: Install dependencies
2727
run: |
2828
python -m pip install --upgrade pip check-manifest
29-
pip install pytest nose
29+
pip install pytest
3030
pip install .
3131
python -m ipykernel.kernelspec --user
3232
- name: Test with pytest

jupyter_console/ptshell.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
import signal
1212
import subprocess
1313
import sys
14+
from tempfile import TemporaryDirectory
1415
import time
1516
from warnings import warn
1617

1718
from typing import Dict as DictType, Any as AnyType
1819

1920
from zmq import ZMQError
2021
from IPython.core import page
21-
from ipython_genutils.tempdir import NamedFileInTemporaryDirectory
2222
from traitlets import (
2323
Bool,
2424
Integer,
@@ -975,24 +975,22 @@ def handle_image_stream(self, data, mime):
975975
imageformat = self._imagemime[mime]
976976
fmt = dict(format=imageformat)
977977
args = [s.format(**fmt) for s in self.stream_image_handler]
978-
with open(os.devnull, 'w') as devnull:
979-
proc = subprocess.Popen(
980-
args, stdin=subprocess.PIPE,
981-
stdout=devnull, stderr=devnull)
978+
with subprocess.Popen(args, stdin=subprocess.PIPE,
979+
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) as proc:
982980
proc.communicate(raw)
983-
return (proc.returncode == 0)
981+
return (proc.returncode == 0)
984982

985983
def handle_image_tempfile(self, data, mime):
986984
raw = base64.decodebytes(data[mime].encode('ascii'))
987985
imageformat = self._imagemime[mime]
988986
filename = 'tmp.{0}'.format(imageformat)
989-
with NamedFileInTemporaryDirectory(filename) as f, \
990-
open(os.devnull, 'w') as devnull:
991-
f.write(raw)
992-
f.flush()
993-
fmt = dict(file=f.name, format=imageformat)
987+
with TemporaryDirectory() as tempdir:
988+
fullpath = os.path.join(tempdir, filename)
989+
with open(fullpath, 'wb') as f:
990+
f.write(raw)
991+
fmt = dict(file=fullpath, format=imageformat)
994992
args = [s.format(**fmt) for s in self.tempfile_image_handler]
995-
rc = subprocess.call(args, stdout=devnull, stderr=devnull)
993+
rc = subprocess.call(args, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
996994
return (rc == 0)
997995

998996
def handle_image_callable(self, data, mime):

jupyter_console/tests/test_image_handler.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# Copyright (c) IPython Development Team.
22
# Distributed under the terms of the Modified BSD License.
33

4+
import base64
45
import os
56
import sys
7+
from tempfile import TemporaryDirectory
68
import unittest
7-
import base64
8-
99
from unittest.mock import patch
1010

11+
import pytest
12+
1113
from jupyter_console.ptshell import ZMQTerminalInteractiveShell
12-
from ipython_genutils.tempdir import TemporaryDirectory
13-
from ipython_genutils.testing.decorators import skip_without
1414

1515

1616
SCRIPT_PATH = os.path.join(
@@ -48,8 +48,8 @@ def raise_if_called(*args, **kwds):
4848
shell.handle_image(None, None) # arguments are dummy
4949
assert len(pil_called_with) == 1
5050

51-
@skip_without('PIL')
5251
def test_handle_image_PIL(self):
52+
pytest.importorskip('PIL')
5353
from PIL import Image, ImageShow
5454

5555
open_called_with = []

0 commit comments

Comments
 (0)