changeset 7591:5867f45810da

cli: fix 'front-end-build' on Windows (Issue #332) On Windows, the command 'npm' is actually 'npm.cmd', a script and not a PE executable. 'subprocess' will not resolve 'npm' into 'npm.cmd', while it would resolve e.g. 'git' into 'git.exe', as the latter _is_ a PE executable. One solution is to change all references to the problematic scripts by adding the '.cmd' extension explicitly, but this would not be compatible with UNIX systems and thus require special handling. On Windows, the problem can be solved by passing 'shell=True' to subprocess. On UNIX, we don't need shell=True and prefer shell=False. A solution that fits both cases is 'shell=kallithea.is_windows'. Note: on Windows, next to the 'npm.cmd' file (and same for license-checker etc.) there is also a file 'npm' (without extension). It is a shell script (interpreter /bin/sh) for use on Windows with mingw/msys/cygwin. This script will nevertheless never be used by the standard Windows command prompt and is not used by Kallithea.
author Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
date Mon, 18 Mar 2019 22:25:30 +0100
parents de92f48c1375
children ffe900abe3d1
files kallithea/bin/kallithea_cli_front_end.py
diffstat 1 files changed, 5 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/bin/kallithea_cli_front_end.py	Sun Mar 10 20:58:28 2019 +0100
+++ b/kallithea/bin/kallithea_cli_front_end.py	Mon Mar 18 22:25:30 2019 +0100
@@ -42,7 +42,7 @@
 
     if install_deps:
         click.echo("Running 'npm install' to install front-end dependencies from package.json")
-        subprocess.check_call(['npm', 'install'], cwd=front_end_dir)
+        subprocess.check_call(['npm', 'install'], cwd=front_end_dir, shell=kallithea.is_windows)
 
     if generate:
         tmp_dir = os.path.join(front_end_dir, 'tmp')
@@ -61,7 +61,7 @@
         csspath = os.path.join(public_dir, 'css', 'style.css')
         subprocess.check_call([lesscpath, '--source-map',
                 '--source-map-less-inline', lesspath, csspath],
-                cwd=front_end_dir)
+                cwd=front_end_dir, shell=kallithea.is_windows)
 
         click.echo("Preparing Bootstrap JS")
         shutil.copy(os.path.join(front_end_dir, 'node_modules', 'bootstrap', 'dist', 'js', 'bootstrap.js'), os.path.join(public_dir, 'js', 'bootstrap.js'))
@@ -90,13 +90,11 @@
         shutil.copytree(os.path.join(front_end_dir, 'node_modules', 'codemirror'), os.path.join(public_dir, 'codemirror'))
 
         click.echo("Generating LICENSES.txt")
+        license_checker_path = os.path.join(front_end_dir, 'node_modules', '.bin', 'license-checker')
         check_licensing_json_path = os.path.join(tmp_dir, 'licensing.json')
         licensing_txt_path = os.path.join(public_dir, 'LICENSES.txt')
-        subprocess.check_call([
-            os.path.join(front_end_dir, 'node_modules', '.bin', 'license-checker'),
-            '--json',
-            '--out', check_licensing_json_path,
-            ], cwd=front_end_dir)
+        subprocess.check_call([license_checker_path, '--json', '--out', check_licensing_json_path],
+                cwd=front_end_dir, shell=kallithea.is_windows)
         with open(check_licensing_json_path) as jsonfile:
             rows = json.loads(jsonfile.read())
             with open(licensing_txt_path, 'w') as out: