From 22d769987cddcde352664457c73d7f3f6b64862b Mon Sep 17 00:00:00 2001
From: Stefan Behnel <stefan_ml@behnel.de>
Date: Mon, 25 Sep 2017 10:38:02 +0200
Subject: [PATCH] Safety fix for #1879: do not raise an exception if setuptools
 hack fails to apply, but warn about it since it's unclear how to handle such
 a case.

---
 Cython/Build/Dependencies.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/Cython/Build/Dependencies.py b/Cython/Build/Dependencies.py
index deb05e247..e9294ca31 100644
--- a/Cython/Build/Dependencies.py
+++ b/Cython/Build/Dependencies.py
@@ -851,7 +851,12 @@ def create_extension_list(patterns, exclude=None, ctx=None, aliases=None, quiet=
 
                 if file not in m.sources:
                     # Old setuptools unconditionally replaces .pyx with .c/.cpp
-                    m.sources.remove(file.rsplit('.')[0] + ('.cpp' if m.language == 'c++' else '.c'))
+                    target_file = file.rsplit('.')[0] + ('.cpp' if m.language == 'c++' else '.c')
+                    try:
+                        m.sources.remove(target_file)
+                    except ValueError:
+                        # never seen this in the wild, but probably better to warn about this unexpected case
+                        print("Warning: Cython source file not found in sources list, adding %s" % file)
                     m.sources.insert(0, file)
                 seen.add(name)
     return module_list, module_metadata
-- 
2.30.9