From cf27da53375d1a322f2195ca3b73b4911b8f48d9 Mon Sep 17 00:00:00 2001
From: "huang.zhiping" <huang.zhiping@99cloud.net>
Date: Sun, 10 Jun 2018 01:21:23 +0800
Subject: [PATCH] fix tox python3 overrides

We want to default to running all tox environments under python 3, so
set the basepython value in each environment.

We do not want to specify a minor version number, because we do not
want to have to update the file every time we upgrade python.

We do not want to set the override once in testenv, because that
breaks the more specific versions used in default environments like
py35 and py36.

To install horizon, check python3 version and set target directory
in postinstall script on package.json.

Change-Id: I181b2a204f6998c24aa188b83a66c596cfb44f1c
Co-Authored-By: Shu Muto <shu.mutow@gmail.com>
---
 package.json           |  2 +-
 tox.ini                | 18 ++++++++++--------
 zaqar_ui/karma.conf.js |  7 ++++++-
 3 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/package.json b/package.json
index ce719ab..5fc9131 100644
--- a/package.json
+++ b/package.json
@@ -24,7 +24,7 @@
   },
   "dependencies": {},
   "scripts": {
-    "postinstall": "if [ ! -d .tox ] || [ ! -d .tox/karma ]; then tox -ekarma --notest; python3.5 -m pip install -U -t ./.tox/karma/lib/python3.5/site-packages/ ../horizon; fi",
+    "postinstall": "if [ ! -d .tox ] || [ ! -d .tox/karma ]; then tox -ekarma --notest; python3 -m pip install -U -t ./.tox/karma/lib/`python3 -V|tr -d ' '|tr 'P' 'p'|cut -c -9`/site-packages/ ../horizon; fi",
     "lint": "eslint --no-color zaqar_ui/static",
     "lintq": "eslint --quiet zaqar_ui/static",
     "test": "karma start zaqar_ui/karma.conf.js --single-run"
diff --git a/tox.ini b/tox.ini
index b32f182..58b7fb1 100644
--- a/tox.ini
+++ b/tox.ini
@@ -25,10 +25,11 @@ commands =
   pip install -e ../horizon
 
 [testenv:venv]
+basepython = python3
 commands = {posargs}
 
 [testenv:pep8]
-basepython = python3.5
+basepython = python3
 commands = flake8 {posargs}
 
 [flake8]
@@ -37,6 +38,7 @@ max-complexity = 20
 
 
 [testenv:cover]
+basepython = python3
 commands =
   coverage erase
   coverage run {toxinidir}/manage.py test zaqar_ui
@@ -75,7 +77,7 @@ commands =
   {[testenv]commands}
 
 [testenv:eslint]
-basepython = python3.5
+basepython = python3
 whitelist_externals =
   npm
 commands =
@@ -83,10 +85,10 @@ commands =
   npm run lint
 
 # NOTE(shu-mutow): The "postinstall" script on package.json will install horizon
-# from master branch into py35 environment for testing javascripts.
+# from master branch into python3.x environment for testing javascripts.
 # Horizon from master is needed to be cloned into ../horizon on both local and CI.
 [testenv:karma]
-basepython = python3.5
+basepython = python3
 whitelist_externals =
   {[testenv:eslint]whitelist_externals}
 commands =
@@ -94,14 +96,14 @@ commands =
   npm run test
 
 [testenv:karma-local]
-basepython = python3.5
+basepython = python3
 whitelist_externals =
   {[testenv:eslint]whitelist_externals}
 commands =
   {[testenv:karma]commands}
 
 [testenv:docs]
-basepython = python3.5
+basepython = python3
 deps =
   -c{env:UPPER_CONSTRAINTS_FILE:https://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt}
   -r{toxinidir}/doc/requirements.txt
@@ -109,7 +111,7 @@ commands=
   sphinx-build -W -b html doc/source doc/build/html
 
 [testenv:docs-local]
-basepython = python3.5
+basepython = python3
 deps =
   {[testenv:docs]deps}
 commands=
@@ -117,7 +119,7 @@ commands=
   {[testenv:docs]commands}
 
 [testenv:releasenotes]
-basepython = python3.5
+basepython = python3
 deps =
   {[testenv:docs]deps}
 commands =
diff --git a/zaqar_ui/karma.conf.js b/zaqar_ui/karma.conf.js
index 561c826..1846946 100644
--- a/zaqar_ui/karma.conf.js
+++ b/zaqar_ui/karma.conf.js
@@ -16,10 +16,15 @@
 
 var fs = require('fs');
 var path = require('path');
+var child_process = require("child_process");
 
 module.exports = function (config) {
   // This tox venv is setup in the post-install npm step
-  var toxPath = '../.tox/karma/lib/python3.5/site-packages/';
+  var pythonVersion = "python3.";
+  var stdout = child_process.execFileSync("python3", ["--version"]);
+  pythonVersion += stdout.toString().split(".")[1];
+  var toxPath = '../.tox/karma/lib/' + pythonVersion + '/site-packages/';
+  console.log("Karma will check on directory: ", toxPath);
 
   config.set({
     preprocessors: {