From cca2a16e34fe5f7e39ab3d3d0cbc2b3a25f926ce Mon Sep 17 00:00:00 2001
From: Jordan Speicher <uSpike@users.noreply.github.com>
Date: Wed, 8 Apr 2020 17:08:31 -0500
Subject: [PATCH] Only patch when called with "bdist_wheel"

"pip wheel" will call setup.py multiple times, so we should only run "patch" once when setup.py is called with "bdist_wheel".
---
 setup.py | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/setup.py b/setup.py
index 758082ca..41552579 100644
--- a/setup.py
+++ b/setup.py
@@ -148,7 +148,8 @@ def main():
                                                 # https://github.com/skvark/opencv-python/issues/21
         cmake_args.append("-DCMAKE_CXX_FLAGS=-stdlib=libc++")
         cmake_args.append("-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.9")
-        subprocess.check_call("patch -p1 < patches/patchQtPlugins", shell=True)
+        if "bdist_wheel" in sys.argv:
+            subprocess.check_call("patch -p1 < patches/patchQtPlugins", shell=True)
 
     if sys.platform.startswith('linux'):
         cmake_args.append("-DWITH_IPP=OFF")   # tests fail with IPP compiled with
@@ -157,7 +158,8 @@ def main():
     if sys.platform.startswith('linux') and not x64:
         cmake_args.append("-DCMAKE_CXX_FLAGS=-U__STRICT_ANSI__")
         # patch openEXR when building on i386, see: https://github.com/openexr/openexr/issues/128
-        subprocess.check_call("patch -p0 < patches/patchOpenEXR", shell=True)
+        if "bdist_wheel" in sys.argv:
+            subprocess.check_call("patch -p0 < patches/patchOpenEXR", shell=True)
 
 
     if 'CMAKE_ARGS' in os.environ: