From 66144165ff39b8b7b5257e141c51a081d498963f Mon Sep 17 00:00:00 2001 From: Yves-Gwenael Bourhis Date: Mon, 15 Jul 2019 15:49:43 +0200 Subject: [PATCH] Use the python real executable Use the real python executable as shebang Use exec instead of execfile if using python 3 Change-Id: I8acea40851c7e9dc248751be967859b2b9430af7 Closes-Bug: #1836580 --- .pylintrc | 2 +- .../management/commands/horizon.wsgi.template | 30 +++++++++++++++---- .../management/commands/make_web_conf.py | 3 ++ tox.ini | 2 +- 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/.pylintrc b/.pylintrc index dfd4716d7b..2ac0c2876a 100644 --- a/.pylintrc +++ b/.pylintrc @@ -2,7 +2,7 @@ [MASTER] # Add to the black list. It should be a base name, not a # path. You may set this option multiple times. -ignore=test,tests,tests.py,local_settings.py +ignore=test,tests,tests.py,local_settings.py,horizon_wsgi.py [Messages Control] disable= diff --git a/openstack_dashboard/management/commands/horizon.wsgi.template b/openstack_dashboard/management/commands/horizon.wsgi.template index cc3bb24539..c079c57052 100644 --- a/openstack_dashboard/management/commands/horizon.wsgi.template +++ b/openstack_dashboard/management/commands/horizon.wsgi.template @@ -1,11 +1,31 @@ -#!/usr/bin/env python +#!{{ PYTHON_EXEC }} +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +{% if ACTIVATE_THIS %} +activate_this = '{{ ACTIVATE_THIS }}' +{% if PY2 %} +execfile(activate_this, dict(__file__=activate_this)) +{% elif PY3 %} +exec( + compile(open(activate_this, "rb").read(), activate_this, 'exec'), + dict(__file__=activate_this) +) +{% endif %} +# We import now instead of at the top of the module to use the virtual env +{% endif %} import os import sys -{% if ACTIVATE_THIS %} -activate_this = '{{ ACTIVATE_THIS }}' -execfile(activate_this, dict(__file__=activate_this)) -{% endif %} sys.path.insert(0, '{{ PROJECT_ROOT }}') os.environ['DJANGO_SETTINGS_MODULE'] = '{{ DJANGO_SETTINGS_MODULE }}' diff --git a/openstack_dashboard/management/commands/make_web_conf.py b/openstack_dashboard/management/commands/make_web_conf.py index a1fe7d59bc..8501fba410 100644 --- a/openstack_dashboard/management/commands/make_web_conf.py +++ b/openstack_dashboard/management/commands/make_web_conf.py @@ -78,6 +78,9 @@ context = template.Context({ 'SSLKEY': '/etc/pki/tls/private/ca.key', 'CACERT': None, 'PROCESSES': multiprocessing.cpu_count() + 1, + 'PY2': six.PY2, + 'PY3': six.PY3, + 'PYTHON_EXEC': sys.executable, }) context['PROJECT_ROOT'] = os.path.dirname(context['PROJECT_PATH']) diff --git a/tox.ini b/tox.ini index 62e068313c..a3e72c4ded 100644 --- a/tox.ini +++ b/tox.ini @@ -177,7 +177,7 @@ commands = bandit-baseline -r horizon openstack_auth openstack_dashboard -n5 -x [flake8] filename = *.py,django.wsgi -exclude = .git,.tox,dist,*lib/python*,*egg,build,panel_template,dash_template,local_settings.py,*/local/*,*/test/test_plugins/*,.ropeproject,node_modules,openstack_dashboard/enabled/* +exclude = .git,.tox,dist,*lib/python*,*egg,build,panel_template,dash_template,local_settings.py,*/local/*,*/test/test_plugins/*,.ropeproject,node_modules,openstack_dashboard/enabled/*,horizon_wsgi.py # W504 line break after binary operator # (W503 and W504 are incompatible and we need to choose one of them. # Existing codes follows W503, so we disable W504.)