Author: Nilesh Patra <npatra974@gmail.com>
Description: Don't cythonize while cleaning
Last-Changed: 20 July 2020
--- a/setup.py
+++ b/setup.py
@@ -1,6 +1,5 @@
 from distutils.core import setup
 from setuptools import find_packages, Extension, Command
-from Cython.Build import cythonize
 
 import os
 import sys
@@ -28,44 +27,49 @@
 # extension sources
 macros = []
 
-extensions = [
-    Extension(
-        "sorted_nearest.src.sorted_nearest",
-        ["sorted_nearest/src/sorted_nearest.pyx"],
-        define_macros=macros),
-    Extension(
-        "sorted_nearest.src.max_disjoint_intervals",
-        ["sorted_nearest/src/max_disjoint_intervals.pyx"],
-        define_macros=macros),
-    Extension(
-        "sorted_nearest.src.k_nearest", ["sorted_nearest/src/k_nearest.pyx"],
-        define_macros=macros),
-    Extension(
-        "sorted_nearest.src.k_nearest_ties", ["sorted_nearest/src/k_nearest_ties.pyx"],
-        define_macros=macros),
-    Extension(
-        "sorted_nearest.src.clusters", ["sorted_nearest/src/clusters.pyx"],
-        define_macros=macros),
-    Extension(
-        "sorted_nearest.src.annotate_clusters",
-        ["sorted_nearest/src/annotate_clusters.pyx"],
-        define_macros=macros),
-    Extension(
-        "sorted_nearest.src.cluster_by", ["sorted_nearest/src/cluster_by.pyx"],
-        define_macros=macros),
-    Extension(
-        "sorted_nearest.src.merge_by", ["sorted_nearest/src/merge_by.pyx"],
-        define_macros=macros),
-    Extension(
-        "sorted_nearest.src.introns", ["sorted_nearest/src/introns.pyx"],
-        define_macros=macros),
-    Extension(
-        "sorted_nearest.src.windows", ["sorted_nearest/src/windows.pyx"],
-        define_macros=macros),
-    Extension(
-        "sorted_nearest.src.tiles", ["sorted_nearest/src/tiles.pyx"],
-        define_macros=macros),
-]
+def get_extensions():
+    if "clean" in sys.argv:
+        return []
+    from Cython.Build import cythonize
+    extensions = [
+        Extension(
+            "sorted_nearest.src.sorted_nearest",
+            ["sorted_nearest/src/sorted_nearest.pyx"],
+            define_macros=macros),
+        Extension(
+            "sorted_nearest.src.max_disjoint_intervals",
+            ["sorted_nearest/src/max_disjoint_intervals.pyx"],
+            define_macros=macros),
+        Extension(
+            "sorted_nearest.src.k_nearest", ["sorted_nearest/src/k_nearest.pyx"],
+            define_macros=macros),
+        Extension(
+            "sorted_nearest.src.k_nearest_ties", ["sorted_nearest/src/k_nearest_ties.pyx"],
+            define_macros=macros),
+        Extension(
+            "sorted_nearest.src.clusters", ["sorted_nearest/src/clusters.pyx"],
+            define_macros=macros),
+        Extension(
+            "sorted_nearest.src.annotate_clusters",
+            ["sorted_nearest/src/annotate_clusters.pyx"],
+            define_macros=macros),
+        Extension(
+            "sorted_nearest.src.cluster_by", ["sorted_nearest/src/cluster_by.pyx"],
+            define_macros=macros),
+        Extension(
+            "sorted_nearest.src.merge_by", ["sorted_nearest/src/merge_by.pyx"],
+            define_macros=macros),
+        Extension(
+            "sorted_nearest.src.introns", ["sorted_nearest/src/introns.pyx"],
+            define_macros=macros),
+        Extension(
+            "sorted_nearest.src.windows", ["sorted_nearest/src/windows.pyx"],
+            define_macros=macros),
+        Extension(
+            "sorted_nearest.src.tiles", ["sorted_nearest/src/tiles.pyx"],
+            define_macros=macros),
+    ]
+    return cythonize(extensions, language_level=3)
 
 __version__ = open("sorted_nearest/version.py").readline().split(
     " = ")[1].replace('"', '').strip()
@@ -76,7 +80,7 @@
     name = "sorted_nearest",
     version=__version__,
     packages=find_packages(),
-    ext_modules = cythonize(extensions, language_level=3),
+    ext_modules = get_extensions(),
     install_requires = install_requires,
     description = \
     'Find nearest interval.',
