diff options
author | Ralf Gommers <ralf.gommers@gmail.com> | 2019-03-13 14:45:57 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-13 14:45:57 -0700 |
commit | eea136ffadf75b92d8125678ce196367b1e3836c (patch) | |
tree | a26e7648de9af474b8027558f12ffd2581578a30 /numpy | |
parent | 8ba1ca574a54a102177e81ffc63564748afb6332 (diff) | |
parent | 0be56a4ce076fe610f56d4e64320394e49499abc (diff) | |
download | numpy-eea136ffadf75b92d8125678ce196367b1e3836c.tar.gz |
Merge pull request #12879 from mattip/deprecate-exec_command
DEP: deprecate exec_command
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/distutils/exec_command.py | 23 | ||||
-rw-r--r-- | numpy/distutils/tests/test_exec_command.py | 31 |
2 files changed, 28 insertions, 26 deletions
diff --git a/numpy/distutils/exec_command.py b/numpy/distutils/exec_command.py index ede347b03..2e7b9e463 100644 --- a/numpy/distutils/exec_command.py +++ b/numpy/distutils/exec_command.py @@ -57,6 +57,7 @@ import os import sys import subprocess import locale +import warnings from numpy.distutils.misc_util import is_sequence, make_temp_file from numpy.distutils import log @@ -105,6 +106,9 @@ def forward_bytes_to_stdout(val): def temp_file_name(): + # 2019-01-30, 1.17 + warnings.warn('temp_file_name is deprecated since NumPy v1.17, use ' + 'tempfile.mkstemp instead', DeprecationWarning, stacklevel=1) fo, name = make_temp_file() fo.close() return name @@ -179,24 +183,14 @@ def _update_environment( **env ): for name, value in env.items(): os.environ[name] = value or '' -def _supports_fileno(stream): - """ - Returns True if 'stream' supports the file descriptor and allows fileno(). - """ - if hasattr(stream, 'fileno'): - try: - stream.fileno() - return True - except IOError: - return False - else: - return False - def exec_command(command, execute_in='', use_shell=None, use_tee=None, _with_python = 1, **env ): """ Return (status,output) of executed command. + .. deprecated:: 1.17 + Use subprocess.Popen instead + Parameters ---------- command : str @@ -220,6 +214,9 @@ def exec_command(command, execute_in='', use_shell=None, use_tee=None, Wild cards will not work for non-posix systems or when use_shell=0. """ + # 2019-01-30, 1.17 + warnings.warn('exec_command is deprecated since NumPy v1.17, use ' + 'subprocess.Popen instead', DeprecationWarning, stacklevel=1) log.debug('exec_command(%r,%s)' % (command,\ ','.join(['%s=%r'%kv for kv in env.items()]))) diff --git a/numpy/distutils/tests/test_exec_command.py b/numpy/distutils/tests/test_exec_command.py index 8bd265007..37912f5ba 100644 --- a/numpy/distutils/tests/test_exec_command.py +++ b/numpy/distutils/tests/test_exec_command.py @@ -6,7 +6,7 @@ from tempfile import TemporaryFile from numpy.distutils import exec_command from numpy.distutils.exec_command import get_pythonexe -from numpy.testing import tempdir, assert_ +from numpy.testing import tempdir, assert_, assert_warns # In python 3 stdout, stderr are text (unicode compliant) devices, so to # emulate them import StringIO from the io module. @@ -71,27 +71,31 @@ def test_exec_command_stdout(): # Test posix version: with redirect_stdout(StringIO()): with redirect_stderr(TemporaryFile()): - exec_command.exec_command("cd '.'") + with assert_warns(DeprecationWarning): + exec_command.exec_command("cd '.'") if os.name == 'posix': # Test general (non-posix) version: with emulate_nonposix(): with redirect_stdout(StringIO()): with redirect_stderr(TemporaryFile()): - exec_command.exec_command("cd '.'") + with assert_warns(DeprecationWarning): + exec_command.exec_command("cd '.'") def test_exec_command_stderr(): # Test posix version: with redirect_stdout(TemporaryFile(mode='w+')): with redirect_stderr(StringIO()): - exec_command.exec_command("cd '.'") + with assert_warns(DeprecationWarning): + exec_command.exec_command("cd '.'") if os.name == 'posix': # Test general (non-posix) version: with emulate_nonposix(): with redirect_stdout(TemporaryFile()): with redirect_stderr(StringIO()): - exec_command.exec_command("cd '.'") + with assert_warns(DeprecationWarning): + exec_command.exec_command("cd '.'") class TestExecCommand(object): @@ -205,11 +209,12 @@ class TestExecCommand(object): def test_basic(self): with redirect_stdout(StringIO()): with redirect_stderr(StringIO()): - if os.name == "posix": - self.check_posix(use_tee=0) - self.check_posix(use_tee=1) - elif os.name == "nt": - self.check_nt(use_tee=0) - self.check_nt(use_tee=1) - self.check_execute_in(use_tee=0) - self.check_execute_in(use_tee=1) + with assert_warns(DeprecationWarning): + if os.name == "posix": + self.check_posix(use_tee=0) + self.check_posix(use_tee=1) + elif os.name == "nt": + self.check_nt(use_tee=0) + self.check_nt(use_tee=1) + self.check_execute_in(use_tee=0) + self.check_execute_in(use_tee=1) |