Blob Blame History Raw
From 36c73b2e4a6a6f8dee8d35b66ac8ce6ca72daea5 Mon Sep 17 00:00:00 2001
From: Elliott Sales de Andrade <quantum.analyst@gmail.com>
Date: Tue, 19 Mar 2019 19:07:25 -0400
Subject: [PATCH 5/9] Check cpuinfo only when needed.

The cpuinfo module does not support s390x and fails to import, but we
don't really need it since we've set CFLAGS. Move the import later so
it's only used when actually checking CPU instruction support.

Signed-off-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
---
 setup.py | 50 ++++++++++++++++++++++++++++----------------------
 1 file changed, 28 insertions(+), 22 deletions(-)

diff --git a/setup.py b/setup.py
index 89237eb..b107b65 100644
--- a/setup.py
+++ b/setup.py
@@ -4,7 +4,6 @@ from glob import glob
 import os
 import subprocess
 from setuptools import setup, Extension
-import cpuinfo
 import sys
 from distutils.command.build_ext import build_ext
 from distutils.errors import CCompilerError, DistutilsExecError, \
@@ -23,32 +22,39 @@ PY2 = sys.version_info[0] == 2
 PY3 = sys.version_info[0] == 3
 
 
-# determine CPU support for SSE2 and AVX2
-cpu_info = cpuinfo.get_cpu_info()
-flags = cpu_info.get('flags', [])
-have_sse2 = 'sse2' in flags
-have_avx2 = 'avx2' in flags
-disable_sse2 = 'DISABLE_NUMCODECS_SSE2' in os.environ
-disable_avx2 = 'DISABLE_NUMCODECS_AVX2' in os.environ
-if PY2 and os.name == 'nt':
-    # force no AVX2 on windows PY27
-    disable_avx2 = True
-
 # setup common compile arguments
 have_cflags = 'CFLAGS' in os.environ
 base_compile_args = list()
 if have_cflags:
     # respect compiler options set by user
-    pass
-elif os.name == 'posix':
-    if disable_sse2:
-        base_compile_args.append('-mno-sse2')
-    elif have_sse2:
-        base_compile_args.append('-msse2')
-    if disable_avx2:
-        base_compile_args.append('-mno-avx2')
-    elif have_avx2:
-        base_compile_args.append('-mavx2')
+    have_sse2 = have_avx2 = False
+    disable_sse2 = disable_avx2 = True
+else:
+    disable_sse2 = 'DISABLE_NUMCODECS_SSE2' in os.environ
+    disable_avx2 = 'DISABLE_NUMCODECS_AVX2' in os.environ
+    if PY2 and os.name == 'nt':
+        # force no AVX2 on windows PY27
+        disable_avx2 = True
+
+    if not disable_avx2 or not disable_sse2:
+        # determine CPU support for SSE2 and AVX2
+        import cpuinfo
+        cpu_info = cpuinfo.get_cpu_info()
+        flags = cpu_info.get('flags', [])
+        have_sse2 = 'sse2' in flags
+        have_avx2 = 'avx2' in flags
+    else:
+        have_sse2 = have_avx2 = False
+
+    if os.name == 'posix':
+        if disable_sse2:
+            base_compile_args.append('-mno-sse2')
+        elif have_sse2:
+            base_compile_args.append('-msse2')
+        if disable_avx2:
+            base_compile_args.append('-mno-avx2')
+        elif have_avx2:
+            base_compile_args.append('-mavx2')
 # workaround lack of support for "inline" in MSVC when building for Python 2.7 64-bit
 if PY2 and os.name == 'nt':
     base_compile_args.append('-Dinline=__inline')
-- 
2.21.0