summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYves-Gwenael Bourhis <yves-gwenael.bourhis@orange.com>2019-07-15 15:49:43 +0200
committerYves-Gwenael Bourhis <yves-gwenael.bourhis@orange.com>2019-07-17 16:23:33 +0200
commit66144165ff39b8b7b5257e141c51a081d498963f (patch)
treee51fafb8288cda3910e182a21af823f647242e32
parent350efbe4f20f9aee13ac52eaaa50c490cd8afa97 (diff)
downloadhorizon-66144165ff39b8b7b5257e141c51a081d498963f.tar.gz
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
-rw-r--r--.pylintrc2
-rw-r--r--openstack_dashboard/management/commands/horizon.wsgi.template28
-rw-r--r--openstack_dashboard/management/commands/make_web_conf.py3
-rw-r--r--tox.ini2
4 files changed, 29 insertions, 6 deletions
diff --git a/.pylintrc b/.pylintrc
index dfd4716d7..2ac0c2876 100644
--- a/.pylintrc
+++ b/.pylintrc
@@ -2,7 +2,7 @@
[MASTER]
# Add <file or directory> 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 cc3bb2453..c079c5705 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
-import os
-import sys
-{% if ACTIVATE_THIS %}
+#!{{ 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
+
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 a1fe7d59b..8501fba41 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 62e068313..a3e72c4de 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.)