|
| 1 | +""" |
| 2 | +Find out installation paths of PARI/GP |
| 3 | +""" |
| 4 | + |
| 5 | +#***************************************************************************** |
| 6 | +# Copyright (C) 2017 Jeroen Demeyer <[email protected]> |
| 7 | +# |
| 8 | +# This program is free software: you can redistribute it and/or modify |
| 9 | +# it under the terms of the GNU General Public License as published by |
| 10 | +# the Free Software Foundation, either version 2 of the License, or |
| 11 | +# (at your option) any later version. |
| 12 | +# http://www.gnu.org/licenses/ |
| 13 | +#***************************************************************************** |
| 14 | + |
| 15 | +from __future__ import absolute_import |
| 16 | + |
| 17 | +import os |
| 18 | +from glob import glob |
| 19 | +from distutils.spawn import find_executable |
| 20 | + |
| 21 | + |
| 22 | +# find_executable() returns None if nothing was found |
| 23 | +gppath = find_executable("gp") or "" |
| 24 | +if gppath is None: |
| 25 | + # This almost certainly won't work, but we need to put something here |
| 26 | + prefix = "." |
| 27 | +else: |
| 28 | + # Assume gppath is ${prefix}/bin/gp |
| 29 | + prefix = os.path.dirname(os.path.dirname(gppath)) |
| 30 | + |
| 31 | + |
| 32 | +def pari_share(): |
| 33 | + r""" |
| 34 | + Return the directory where the PARI data files are stored. |
| 35 | +
|
| 36 | + EXAMPLES:: |
| 37 | +
|
| 38 | + sage: from sage_setup.autogen.pari.parser import pari_share |
| 39 | + sage: pari_share() |
| 40 | + '.../share/pari' |
| 41 | + """ |
| 42 | + from subprocess import Popen, PIPE |
| 43 | + if not gppath: |
| 44 | + raise EnvironmentError("cannot find an installation of PARI/GP: make sure that the 'gp' program is in your $PATH") |
| 45 | + gp = Popen([gppath, "-f", "-q"], stdin=PIPE, stdout=PIPE) |
| 46 | + out = gp.communicate(b"print(default(datadir))")[0] |
| 47 | + datadir = out.strip() |
| 48 | + if not os.path.isdir(datadir): |
| 49 | + # As a fallback, try a path relative to the prefix |
| 50 | + datadir = os.path.join(prefix, "share", "pari") |
| 51 | + if not os.path.isdir(datadir): |
| 52 | + raise EnvironmentError("PARI data directory {!r} does not exist".format(datadir)) |
| 53 | + return datadir |
| 54 | + |
| 55 | + |
| 56 | +def include_dirs(): |
| 57 | + """ |
| 58 | + Return the directory containing PARI include files. |
| 59 | + """ |
| 60 | + dirs = [os.path.join(prefix, "include")] |
| 61 | + return [d for d in dirs if os.path.isdir(os.path.join(d, "pari"))] |
| 62 | + |
| 63 | + |
| 64 | +def library_dirs(): |
| 65 | + """ |
| 66 | + Return the directory containing PARI library files. |
| 67 | + """ |
| 68 | + dirs = [os.path.join(prefix, s) for s in ("lib", "lib32", "lib64")] |
| 69 | + return [d for d in dirs if glob(os.path.join(d, "libpari*"))] |
0 commit comments