2828# See https://docs.python.org/3/library/distutils.html
2929# setuptools is preferred over distutils. And we are supporting python3 only.
3030from setuptools import setup , Extension , Command
31- from setuptools .command .build_ext import build_ext as _build_ext
31+ from setuptools .command .build_ext import build_ext
3232import subprocess
3333
3434# Global variables.
3939
4040if not os .path .exists (builddir_ ):
4141 os .makedirs (builddir_ )
42+
4243
4344numCores_ = multiprocessing .cpu_count ()
4445
4950
5051
5152class CMakeExtension (Extension ):
53+ # Reference: https://martinopilia.com/posts/2018/09/15/building-python-extension.html
5254 def __init__ (self , name , ** kwargs ):
5355 # don't invoke the original build_ext for this special extension
54- import tempfile
55-
56- # Create a temp file to create a dummy target. This build raises an
57- # exception because sources are empty. With python3 we can fix it by
58- # passing `optional=True` to the argument. With python2 there is no
59- # getaway from it.
60- f = tempfile .NamedTemporaryFile (suffix = '.cpp' , delete = False )
61- f .write (b'int main() { return 1; }' )
62- Extension .__init__ (self , name , sources = [f .name ], ** kwargs )
63- f .close ()
56+ Extension .__init__ (self , name , sources = [], ** kwargs )
6457
6558
6659class TestCommand (Command ):
@@ -79,14 +72,14 @@ def run(self):
7972 os .chdir (sdir_ )
8073
8174
82- class build_ext ( _build_ext ):
75+ class cmake_build_ext ( build_ext ):
8376 user_options = [
8477 ('with-boost' , None , 'Use Boost Libraries (OFF)' ),
8578 ('with-gsl' , None , 'Use Gnu Scienfific Library (ON)' ),
8679 ('with-gsl-static' , None , 'Use GNU Scientific Library (static library) (OFF)' ),
8780 ('debug' , None , 'Build moose in debugging mode (OFF)' ),
8881 ('no-build' , None , 'DO NOT BUILD. (for debugging/development)' ),
89- ] + _build_ext .user_options
82+ ] + build_ext .user_options
9083
9184 def initialize_options (self ):
9285 # Initialize options.
@@ -97,12 +90,12 @@ def initialize_options(self):
9790 self .no_build = 0
9891 self .cmake_options = {}
9992 # super().initialize_options()
100- _build_ext .initialize_options (self )
93+ build_ext .initialize_options (self )
10194
10295 def finalize_options (self ):
10396 # Finalize options.
10497 # super().finalize_options()
105- _build_ext .finalize_options (self )
98+ build_ext .finalize_options (self )
10699 self .cmake_options ['PYTHON_EXECUTABLE' ] = os .path .realpath (sys .executable )
107100 self .cmake_options ['VERSION_MOOSE' ] = version_
108101 if self .with_boost :
@@ -122,7 +115,7 @@ def run(self):
122115 for ext in self .extensions :
123116 self .build_cmake (ext )
124117 # super().run()
125- _build_ext .run (self )
118+ build_ext .run (self )
126119
127120 def build_cmake (self , ext ):
128121 global numCores_
@@ -175,7 +168,7 @@ def build_cmake(self, ext):
175168 ]
176169 },
177170 install_requires = ['numpy' , 'matplotlib' , 'vpython' , 'pybind11' ],
178- extra_requires = {'dev' : ['coverage' , 'pytest' , 'pytest-cov' ]},
179- ext_modules = [CMakeExtension ('dummy ' , optional = True )],
180- cmdclass = {'build_ext' : build_ext , 'test' : TestCommand },
171+ extra_require = {'dev' : ['coverage' , 'pytest' , 'pytest-cov' ]},
172+ ext_modules = [CMakeExtension ('_moose ' , optional = True )],
173+ cmdclass = {'build_ext' : cmake_build_ext , 'test' : TestCommand },
181174)
0 commit comments