Commit 6bd21102356a4f846899fc8e353b23b78cb36820
1 parent
d1b18fa7
Exists in
master
Added a command to setup.py to build plugins
Showing
1 changed file
with
45 additions
and
6 deletions
Show diff stats
setup.py
| 1 | +import distutils.cmd | ||
| 2 | +import distutils.log | ||
| 1 | import os | 3 | import os |
| 4 | +import pathlib | ||
| 5 | +import subprocess | ||
| 2 | import sys | 6 | import sys |
| 3 | from distutils.core import setup | 7 | from distutils.core import setup |
| 4 | from distutils.extension import Extension | 8 | from distutils.extension import Extension |
| @@ -7,12 +11,16 @@ import numpy | @@ -7,12 +11,16 @@ import numpy | ||
| 7 | from Cython.Build import cythonize | 11 | from Cython.Build import cythonize |
| 8 | from Cython.Distutils import build_ext | 12 | from Cython.Distutils import build_ext |
| 9 | 13 | ||
| 10 | -if sys.platform == 'darwin': | ||
| 11 | - unix_copt = ['-Xpreprocessor', '-fopenmp', '-lomp'] | ||
| 12 | - unix_lopt = ['-Xpreprocessor', '-fopenmp', '-lomp'] | 14 | +if sys.platform == "darwin": |
| 15 | + unix_copt = ["-Xpreprocessor", "-fopenmp", "-lomp"] | ||
| 16 | + unix_lopt = ["-Xpreprocessor", "-fopenmp", "-lomp"] | ||
| 13 | else: | 17 | else: |
| 14 | - unix_copt = ['-fopenmp',] | ||
| 15 | - unix_lopt = ['-fopenmp',] | 18 | + unix_copt = [ |
| 19 | + "-fopenmp", | ||
| 20 | + ] | ||
| 21 | + unix_lopt = [ | ||
| 22 | + "-fopenmp", | ||
| 23 | + ] | ||
| 16 | 24 | ||
| 17 | 25 | ||
| 18 | copt = {"msvc": ["/openmp"], "mingw32": ["-fopenmp"], "unix": unix_copt} | 26 | copt = {"msvc": ["/openmp"], "mingw32": ["-fopenmp"], "unix": unix_copt} |
| @@ -35,8 +43,39 @@ class build_ext_subclass(build_ext): | @@ -35,8 +43,39 @@ class build_ext_subclass(build_ext): | ||
| 35 | build_ext.build_extensions(self) | 43 | build_ext.build_extensions(self) |
| 36 | 44 | ||
| 37 | 45 | ||
| 46 | +class BuildPluginsCommand(distutils.cmd.Command): | ||
| 47 | + """ | ||
| 48 | + A custom command to build all plugins with cython code. | ||
| 49 | + """ | ||
| 50 | + | ||
| 51 | + description = "Build all plugins with cython code" | ||
| 52 | + user_options = [] | ||
| 53 | + | ||
| 54 | + def initialize_options(self): | ||
| 55 | + pass | ||
| 56 | + | ||
| 57 | + def finalize_options(self): | ||
| 58 | + pass | ||
| 59 | + | ||
| 60 | + def run(self): | ||
| 61 | + compilable_plugins = ["porous_creation", "remove_tiny_objects"] | ||
| 62 | + inv_folder = pathlib.Path(__file__).parent.resolve() | ||
| 63 | + plugins_folder = inv_folder.joinpath("plugins") | ||
| 64 | + for p in compilable_plugins: | ||
| 65 | + plugin_folder = plugins_folder.joinpath(p) | ||
| 66 | + self.announce("Compiling plugin: {}".format(p), level=distutils.log.INFO) | ||
| 67 | + os.chdir(plugin_folder) | ||
| 68 | + subprocess.check_call( | ||
| 69 | + [sys.executable, "setup.py", "build_ext", "--inplace"] | ||
| 70 | + ) | ||
| 71 | + os.chdir(inv_folder) | ||
| 72 | + | ||
| 73 | + | ||
| 38 | setup( | 74 | setup( |
| 39 | - cmdclass={"build_ext": build_ext_subclass}, | 75 | + cmdclass={ |
| 76 | + "build_ext": build_ext_subclass, | ||
| 77 | + "build_plugins": BuildPluginsCommand, | ||
| 78 | + }, | ||
| 40 | ext_modules=cythonize( | 79 | ext_modules=cythonize( |
| 41 | [ | 80 | [ |
| 42 | Extension( | 81 | Extension( |