Skip to content

Commit b9fb955

Browse files
author
Release Manager
committed
gh-41666: Deprecate sage.misc.sage_ostools.have_program() Deprecate `have_program()` in favor of `shutil.which()`, and replace the two remaining uses in the sage library cf. #32957 When this is done, I'll open a new issue to replace `shutil.which` with features, since we still should not be randomly guessing at this stuff at runtime. URL: #41666 Reported by: Michael Orlitzky Reviewer(s): Tobias Diez
2 parents 7ea9bae + 86fea3d commit b9fb955

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

src/sage/interfaces/phc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -917,8 +917,8 @@ def blackbox(self, polys, input_ring, verbose=False):
917917

918918
# Was there an error?
919919
if e:
920-
from sage.misc.sage_ostools import have_program
921-
if not have_program('phc'):
920+
from shutil import which
921+
if not which('phc'):
922922
print(str(os.system('which phc')) + ' PHC needs to be installed and in your path')
923923
raise RuntimeError
924924
# todo -- why? etc.

src/sage/misc/sage_ostools.pyx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ def have_program(program, path=None) -> bool:
2828

2929
sage: from sage.misc.sage_ostools import have_program
3030
sage: have_program('ls')
31+
doctest:warning
32+
...
33+
DeprecationWarning: have_program is deprecated; use shutil.which instead
34+
See https://github.com/sagemath/sage/issues/32957 for details.
3135
True
3236
sage: have_program('there_is_not_a_program_with_this_name')
3337
False
@@ -38,6 +42,8 @@ def have_program(program, path=None) -> bool:
3842
sage: have_program('there_is_not_a_program_with_this_name', "/bin")
3943
False
4044
"""
45+
from sage.misc.superseded import deprecation
46+
deprecation(32957, "have_program is deprecated; use shutil.which instead")
4147
if path is None:
4248
path = os.environ.get('PATH', "")
4349
for p in path.split(os.pathsep):

src/sage/misc/viewer.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def default_viewer(viewer=None):
5555
ValueError: Unknown type of viewer: jpg.
5656
"""
5757
import os
58-
from sage.misc.sage_ostools import have_program
58+
from shutil import which
5959

6060
if isinstance(viewer, str):
6161
viewer = viewer.lower()
@@ -74,7 +74,7 @@ def default_viewer(viewer=None):
7474
PDF_VIEWER = BROWSER
7575
PNG_VIEWER = BROWSER
7676

77-
elif have_program('xdg-open'):
77+
elif which('xdg-open'):
7878
# On other OS'es try xdg-open if present.
7979
# See http://portland.freedesktop.org/xdg-utils-1.0.
8080
BROWSER = 'xdg-open'
@@ -89,7 +89,7 @@ def default_viewer(viewer=None):
8989
except KeyError:
9090
BROWSER = 'less' # silly default; lets hope it doesn't come to this!
9191
for cmd in ['firefox', 'konqueror', 'mozilla', 'mozilla-firefox']:
92-
if have_program(cmd):
92+
if which(cmd):
9393
BROWSER = cmd
9494
break
9595
DVI_VIEWER = BROWSER
@@ -101,14 +101,14 @@ def default_viewer(viewer=None):
101101
DVI_VIEWER = os.environ['DVI_VIEWER']
102102
except KeyError:
103103
for cmd in ['xdvi', 'kdvi']:
104-
if have_program(cmd):
104+
if which(cmd):
105105
DVI_VIEWER = cmd
106106
break
107107
try:
108108
PDF_VIEWER = os.environ['PDF_VIEWER']
109109
except KeyError:
110110
for cmd in ['acroread', 'xpdf']:
111-
if have_program(cmd):
111+
if which(cmd):
112112
PDF_VIEWER = cmd
113113
break
114114

0 commit comments

Comments
 (0)