Resolved an issue finding the python interpreter on *nix systems, and

Windows 2008 R2 (32 bit), while running the pgAdmin 4 as runtime for
the PostgreSQL one click installers.

- Found a typo in runtime code, we were appending the path using ';' on
  *nix systems too. We should have used ':', and that did not allow the
  os.environ['PATH'] to identify the correct path of the python
  interpreter under the 'venv' directory.

- On Windows 2008, it was not honouring the environment variables, set
  under the Qt application (e.g. pgAdmin4.exe runtime), in the python
  application. (e.g. pgAdmin4.py). We will need to assume that - the
  python interpreter resides under the 'venv' directory outside the
  'bin' directory.

- Also, on windows 2008, it was setting PYTHONHOME environment variable
  to the full path of the pgAdmin4.exe, we need to reset it to 'venv'
  directory, if we find the python interpreter under it.

Thanks Murtuza Zabuawala for tips, and help.
This commit is contained in:
Ashesh Vashi 2017-03-10 21:16:13 +05:30
parent 28deb34283
commit 7767c085c3
2 changed files with 48 additions and 1 deletions

View File

@ -28,15 +28,25 @@ static void add_to_path(QString &python_path, QString path, bool prepend=false)
{
if (!prepend)
{
#if defined(Q_OS_WIN)
if (!python_path.isEmpty() && !python_path.endsWith(";"))
python_path.append(";");
#else
if (!python_path.isEmpty() && !python_path.endsWith(":"))
python_path.append(":");
#endif
python_path.append(path);
}
else
{
#if defined(Q_OS_WIN)
if (!python_path.isEmpty() && !python_path.startsWith(";"))
python_path.prepend(";");
#else
if (!python_path.isEmpty() && !python_path.startsWith(":"))
python_path.prepend(":");
#endif
python_path.prepend(path);
}

View File

@ -227,8 +227,45 @@ class BatchProcess(object):
interpreter = which(u'pythonw.exe', paths)
if interpreter is None:
interpreter = which(u'python.exe', paths)
if interpreter is None and current_app.PGADMIN_RUNTIME:
# We've faced an issue with Windows 2008 R2 (x86) regarding,
# not honouring the environment variables set under the Qt
# (e.g. runtime), and also setting PYTHONHOME same as
# sys.executable (i.e. pgAdmin4.exe).
#
# As we know, we're running it under the runtime, we can assume
# that 'venv' directory will be available outside of 'bin'
# directory.
#
# We would try out luck to find python executable based on that
# assumptions.
bin_path = os.path.dirname(sys.executable)
venv = os.path.realpath(
os.path.join(bin_path, u'..\\venv')
)
interpreter = which(u'pythonw.exe', [venv])
if interpreter is None:
interpreter = which(u'pythonw.exe', [venv])
if interpreter is not None:
# Our assumptions are proven right.
# Let's append the 'bin' directory to the PATH environment
# variable. And, also set PYTHONHOME environment variable
# to 'venv' directory.
os.environ['PATH'] = bin_path + ';' + os.environ['PATH']
os.environ['PYTHONHOME'] = venv
else:
paths.insert(0, os.path.join(u(sys.prefix), u'bin'))
# Let's not use sys.prefix in runtime.
# 'sys.prefix' is not identified on *nix systems for some unknown
# reason, while running under the runtime.
# We're already adding '<installation path>/pgAdmin 4/venv/bin'
# directory in the PATH environment variable. Hence - it will
# anyway be the redundant value in paths.
if not current_app.PGADMIN_RUNTIME:
paths.insert(0, os.path.join(u(sys.prefix), u'bin'))
interpreter = which(u'python', paths)
p = None