Skip to content

Commit

Permalink
Trac #33467: sage.geometry: Use PalpExecutable(...).absolute_filename()
Browse files Browse the repository at this point in the history
This is so that the Sage library becomes fully functional even when not
being run from within sage-env (which sets PATH).

To test:
{{{
$ venv/bin/python3 -c 'from sage.all import *; print(lattice_polytope.cr
oss_polytope(3).polar().facets()[0].ambient_point_indices())'
$ venv/bin/python3 -c 'from sage.all import *; from
sage.geometry.polyhedron.palp_database import PALPreader;
print(next(iter(PALPreader(2, output="list"))))'
}}}

URL: https://trac.sagemath.org/33467
Reported by: mkoeppe
Ticket author(s): Matthias Koeppe
Reviewer(s): Dima Pasechnik
  • Loading branch information
Release Manager committed Mar 8, 2022
2 parents b9155bf + 4b58ad6 commit fa0c93f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/sage/geometry/lattice_polytope.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@

from sage.misc.lazy_import import lazy_import
from sage.features import PythonModule
from sage.features.palp import PalpExecutable
lazy_import('ppl', ['C_Polyhedron', 'Generator_System', 'Linear_Expression'],
feature=PythonModule("ppl", spkg="pplpy"))
lazy_import('ppl', 'point', as_='PPL_point',
Expand Down Expand Up @@ -146,6 +147,7 @@
from collections.abc import Hashable
from copyreg import constructor as copyreg_constructor
import os
import shlex
from subprocess import Popen, PIPE
from warnings import warn
from functools import reduce
Expand Down Expand Up @@ -5105,6 +5107,11 @@ def _palp(command, polytopes, reduce_dimension=False):
if _palp_dimension is not None:
dot = command.find(".")
command = command[:dot] + "-%dd" % _palp_dimension + command[dot:]
executable, args = command.split(" ", 1)
if executable.endswith('.x'):
executable = executable[:-2]
executable = PalpExecutable(executable).absolute_filename()
command = " ".join([shlex.quote(executable), args])
input_file_name = tmp_filename()
input_file = open(input_file_name, "w")
for p in polytopes:
Expand Down
5 changes: 3 additions & 2 deletions src/sage/geometry/polyhedron/palp_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

from sage.structure.sage_object import SageObject
from sage.rings.integer_ring import ZZ
from sage.features.palp import PalpExecutable

from sage.interfaces.process import terminate

Expand Down Expand Up @@ -134,7 +135,7 @@ def _palp_Popen(self):
<...Popen...>
"""

return Popen(["class.x", "-b2a", "-di", self._data_basename],
return Popen([PalpExecutable("class").absolute_filename(), "-b2a", "-di", self._data_basename],
stdout=PIPE, encoding='utf-8', errors='surrogateescape')

def _read_vertices(self, stdout, rows, cols):
Expand Down Expand Up @@ -459,7 +460,7 @@ def _palp_Popen(self):
<...Popen...>
"""

return Popen(['class-4d.x', '-He',
return Popen([PalpExecutable('class-4d').absolute_filename(), '-He',
'H{}:{}L100000000'.format(self._h21, self._h11),
'-di', self._data_basename], stdout=PIPE,
encoding='utf-8', errors='surrogateescape')

0 comments on commit fa0c93f

Please sign in to comment.