mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-21 17:51:03 +00:00
Python runtime detection requirement upgraded to 3.8
Remove -tt option that is a no-op in Python 3. Remove search for Python 2
This commit is contained in:
parent
4372f1b58f
commit
1c458dc121
@ -1,62 +0,0 @@
|
|||||||
## ------------------------ -*- Autoconf -*-
|
|
||||||
# adapted for LyX from the automake python support.
|
|
||||||
## Python file handling
|
|
||||||
## From Andrew Dalke
|
|
||||||
## Updated by James Henstridge
|
|
||||||
## ------------------------
|
|
||||||
# Copyright (C) 1999-2015 Free Software Foundation, Inc.
|
|
||||||
#
|
|
||||||
# This file is free software; the Free Software Foundation
|
|
||||||
# gives unlimited permission to copy and/or distribute it,
|
|
||||||
# with or without modifications, as long as this notice is preserved.
|
|
||||||
|
|
||||||
dnl Usage: LYX_PATH_PYTHON23(PY2-MIN-VERSION, PYTHON3-MIN-VERSION)
|
|
||||||
dnl Find a suitable Python interpreter, that is either python2 >= $1
|
|
||||||
dnl or python3 >= $2. Stop with an error message if it has not been found.
|
|
||||||
AC_DEFUN([LYX_PATH_PYTHON23],
|
|
||||||
[
|
|
||||||
m4_define(py2_ver, [patsubst($1,[\.],[,])])
|
|
||||||
m4_define(py3_ver, [patsubst($2,[\.],[,])])
|
|
||||||
|
|
||||||
m4_define_default([_AM_PYTHON_INTERPRETER_LIST], [python3 python2 python])
|
|
||||||
|
|
||||||
if test -n "$PYTHON"; then
|
|
||||||
# If the user set $PYTHON, use it and don't search something else.
|
|
||||||
AC_MSG_CHECKING([whether $PYTHON version is >= $1 or $2])
|
|
||||||
LYX_PYTHON_CHECK_VERSION([$PYTHON],
|
|
||||||
[AC_MSG_RESULT([yes])],
|
|
||||||
[AC_MSG_RESULT([no])
|
|
||||||
AC_MSG_ERROR([Python interpreter is not suitable])])
|
|
||||||
am_display_PYTHON=$PYTHON
|
|
||||||
else
|
|
||||||
# Otherwise, try each interpreter until we find one that satisfies
|
|
||||||
# LYX_PYTHON_CHECK_VERSION.
|
|
||||||
AC_CACHE_CHECK([for a Python interpreter with version >= $1 or $2],
|
|
||||||
[am_cv_pathless_PYTHON],[
|
|
||||||
for am_cv_pathless_PYTHON in _AM_PYTHON_INTERPRETER_LIST none; do
|
|
||||||
test "$am_cv_pathless_PYTHON" = none && break
|
|
||||||
LYX_PYTHON_CHECK_VERSION([$am_cv_pathless_PYTHON], [break])
|
|
||||||
done])
|
|
||||||
# Set $PYTHON to the absolute path of $am_cv_pathless_PYTHON.
|
|
||||||
if test "$am_cv_pathless_PYTHON" = none; then
|
|
||||||
PYTHON=:
|
|
||||||
else
|
|
||||||
AC_PATH_PROG([PYTHON], [$am_cv_pathless_PYTHON])
|
|
||||||
fi
|
|
||||||
am_display_PYTHON=$am_cv_pathless_PYTHON
|
|
||||||
fi
|
|
||||||
|
|
||||||
if test "$PYTHON" = : ; then
|
|
||||||
AC_MSG_ERROR([no suitable Python interpreter found])
|
|
||||||
fi
|
|
||||||
])
|
|
||||||
|
|
||||||
# LYX_PYTHON_CHECK_VERSION(PROG, [ACTION-IF-TRUE], [ACTION-IF-FALSE])
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
# Run ACTION-IF-TRUE if the Python interpreter PROG has version >= py2_ver or py3_ver.
|
|
||||||
# Run ACTION-IF-FALSE otherwise.
|
|
||||||
AC_DEFUN([LYX_PYTHON_CHECK_VERSION],
|
|
||||||
[prog="import sys
|
|
||||||
version = sys.version_info@<:@:3@:>@
|
|
||||||
sys.exit(not ((py2_ver) <= version < (3,0,0) or version >= (py3_ver)))"
|
|
||||||
AS_IF([AM_RUN_LOG([$1 -c "$prog"])], [$2], [$3])])
|
|
@ -56,12 +56,12 @@ int timeout_ms()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static string const python23_call(string const & binary, bool verbose = false)
|
static string const python_call(string const & binary, bool verbose = false)
|
||||||
{
|
{
|
||||||
const string version_info = " -c \"from __future__ import print_function; import sys; print(sys.version_info[:2], end='')\"";
|
const string version_info = " -c \"import sys; print(sys.version_info[:2], end='')\"";
|
||||||
// Default to "python" if no binary is given.
|
// Default to "python3" if no binary is given.
|
||||||
if (binary.empty())
|
if (binary.empty())
|
||||||
return "python -tt";
|
return "python3";
|
||||||
|
|
||||||
if (verbose)
|
if (verbose)
|
||||||
lyxerr << "Examining " << binary << "\n";
|
lyxerr << "Examining " << binary << "\n";
|
||||||
@ -80,14 +80,12 @@ static string const python23_call(string const & binary, bool verbose = false)
|
|||||||
|
|
||||||
int major = convert<int>(sm.str(1));
|
int major = convert<int>(sm.str(1));
|
||||||
int minor = convert<int>(sm.str(2));
|
int minor = convert<int>(sm.str(2));
|
||||||
if((major == 2 && minor < 7) || (major == 3 && minor < 5))
|
if((major < 3) || (major == 3 && minor < 8))
|
||||||
return string();
|
return string();
|
||||||
|
|
||||||
if (verbose)
|
if (verbose)
|
||||||
lyxerr << "Found Python " << out.result << "\n";
|
lyxerr << "Found Python " << out.result << "\n";
|
||||||
// Add the -tt switch so that mixed tab/whitespace
|
return binary;
|
||||||
// indentation is an error
|
|
||||||
return binary + " -tt";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -102,15 +100,14 @@ static string const find_python_binary()
|
|||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
// Check through python launcher whether python 3 is
|
// Check through python launcher whether python 3 is
|
||||||
// installed on computer.
|
// installed on computer.
|
||||||
string command = python23_call("py -3");
|
string command = python_call("py -3");
|
||||||
#else
|
#else
|
||||||
// Check whether python3 in PATH is the right one.
|
// Check whether python3 in PATH is the right one.
|
||||||
string command = python23_call("python3");
|
string command = python_call("python3");
|
||||||
#endif // _WIN32
|
#endif // _WIN32
|
||||||
if (!command.empty())
|
if (!command.empty())
|
||||||
return command;
|
return command;
|
||||||
|
|
||||||
#ifndef _WIN32
|
|
||||||
// python3 does not exists, let us try to find python3.x in PATH
|
// python3 does not exists, let us try to find python3.x in PATH
|
||||||
// the search is probably broader than required
|
// the search is probably broader than required
|
||||||
// but we are trying hard to find a valid python binary
|
// but we are trying hard to find a valid python binary
|
||||||
@ -125,59 +122,18 @@ static string const find_python_binary()
|
|||||||
for (auto const & bin2 : list) {
|
for (auto const & bin2 : list) {
|
||||||
string const binary = "\"" + addName(localdir,
|
string const binary = "\"" + addName(localdir,
|
||||||
bin2.toLocal8Bit().constData()) + "\"";
|
bin2.toLocal8Bit().constData()) + "\"";
|
||||||
command = python23_call(binary, true);
|
command = python_call(binary, true);
|
||||||
if (!command.empty())
|
if (!command.empty())
|
||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif // !_WIN32
|
|
||||||
|
|
||||||
// python 3 was not found let us look for python 2
|
|
||||||
#ifdef _WIN32
|
|
||||||
command = python23_call("py -2");
|
|
||||||
#else
|
|
||||||
command = python23_call("python2");
|
|
||||||
#endif // _WIN32
|
|
||||||
if (!command.empty())
|
if (!command.empty())
|
||||||
return command;
|
return command;
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
// python launcher is not installed, let cmd auto check
|
|
||||||
// PATH for a python.exe
|
|
||||||
command = python23_call("python");
|
|
||||||
if (!command.empty())
|
|
||||||
return command;
|
|
||||||
|
|
||||||
//failed, prepare to search PATH manually
|
|
||||||
vector<string> const path = getEnvPath("PATH");
|
|
||||||
lyxerr << "Manually looking for python in PATH ...\n";
|
|
||||||
QString const exeName = "python*";
|
|
||||||
#else
|
|
||||||
// python2 does not exists, let us try to find python2.x in PATH
|
|
||||||
// the search is probably broader than required
|
|
||||||
// but we are trying hard to find a valid python binary
|
|
||||||
lyxerr << "Looking for python 2.x ...\n";
|
|
||||||
QString const exeName = "python2*";
|
|
||||||
#endif // _WIN32
|
|
||||||
|
|
||||||
for (auto const & bin : path) {
|
|
||||||
QString const dir = toqstr(bin);
|
|
||||||
string const localdir = dir.toLocal8Bit().constData();
|
|
||||||
QDir qdir(dir);
|
|
||||||
qdir.setFilter(QDir::Files | QDir::Executable);
|
|
||||||
QStringList list = qdir.entryList(QStringList(exeName));
|
|
||||||
for (auto const & bin2 : list) {
|
|
||||||
string const binary = "\"" + addName(localdir,
|
|
||||||
bin2.toLocal8Bit().constData()) + "\"";
|
|
||||||
command = python23_call(binary, true);
|
|
||||||
if (!command.empty())
|
|
||||||
return command;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If this happens all hope is lost that this is a sane system
|
// If this happens all hope is lost that this is a sane system
|
||||||
lyxerr << "Warning: No python v2.x or 3.x binary found.\n";
|
lyxerr << "Warning: No Python 3.x binary found.\n";
|
||||||
return python23_call("");
|
return python_call("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -194,12 +150,12 @@ string const python(bool reset)
|
|||||||
|
|
||||||
bool hasPython()
|
bool hasPython()
|
||||||
{
|
{
|
||||||
return !(python23_call(python()).empty());
|
return !(python_call(python()).empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
string const python_info()
|
string const python_info()
|
||||||
{
|
{
|
||||||
const string info_version = " -c \"from __future__ import print_function; import sys; print('{} ({})'.format(sys.version.split()[0],sys.executable), end='')\"";
|
const string info_version = " -c \"import sys; print('{} ({})'.format(sys.version.split()[0],sys.executable), end='')\"";
|
||||||
if (!hasPython())
|
if (!hasPython())
|
||||||
return("None");
|
return("None");
|
||||||
return (runCommand(python() + info_version).result);
|
return (runCommand(python() + info_version).result);
|
||||||
|
Loading…
Reference in New Issue
Block a user