Skip to content

Commit

Permalink
Trac #33624: doctest unnecessarily assumes SAGE_VENV/bin contains `sa…
Browse files Browse the repository at this point in the history
…ge` binary

In my setup `SAGE_VENV` is left unset so it defaults to `sys.prefix =
'/usr'`; in this way, sage uses system python packages (and everything
works).

However, the `sage` binary is not necessarily installed as
`/usr/bin/sage`. For example:
 - I build just sagelib from source, so that the sage python packages
are placed in `.../pkgs/sagemath-standard/build/lib.linux-x86_64-3.10/`
and the sage scripts are placed in `.../pkgs/sagemath-
standard/build/scripts-3.10/`. I want to use and doctest this sagelib
without installing (which can be done easily by setting PATH and
PYTHONPATH to those directories).

Now `/usr/bin/sage` may or may not exist (depends on whether I have the
system sagemath installed -- this is never true in github CI where the
void linux package for sagemath is built and tested in a clean
container)

In any case, the directory where the actual `sage` script is located can
be obtained as `os.path.dirname(sys.argv[0])` (this will normally be the
same as `SAGE_VENV/bin`).

URL: https://trac.sagemath.org/33624
Reported by: tornaria
Ticket author(s): Gonzalo Tornaría
Reviewer(s): Matthias Koeppe
  • Loading branch information
Release Manager committed Apr 2, 2022
2 parents b438a78 + 0c1ca80 commit d8f76fb
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/sage/misc/sage_ostools.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@ def have_program(program, path=None):
True
sage: have_program('there_is_not_a_program_with_this_name')
False
sage: from sage.env import SAGE_VENV
sage: have_program('sage', os.path.join(SAGE_VENV, 'bin'))
sage: have_program('sh', '/bin')
True
sage: have_program('sage', '/there_is_not_a_path_with_this_name')
False
sage: have_program('there_is_not_a_program_with_this_name', os.path.join(SAGE_VENV, 'bin'))
sage: have_program('there_is_not_a_program_with_this_name', "/bin")
False
"""
if path is None:
Expand Down

0 comments on commit d8f76fb

Please sign in to comment.