1- __author__ = "Dilawar Singh"
2- __copyright__ = "Copyright 2019-, Dilawar Singh"
3- __maintainer__ = "Dilawar Singh"
4- 1+ __author__ = "Dilawar Singh"
2+ __copyright__ = "Copyright 2019-, Dilawar Singh"
3+ __maintainer__ = "Dilawar Singh"
4+ 55
66import os
77import sys
88import pathlib
99from setuptools import setup , Extension
1010from setuptools .command .build_ext import build_ext as build_ext_orig
1111
12+ # Read version from VERSION created by cmake file. This file must be present for
13+ # setup.cmake.py to work perfectly.
14+ script_dir = os .path .dirname (os .path .abspath (__file__ ))
15+
16+ # Version file must be available. It MUST be written by cmake. Or create
17+ # it manually before running this script.
18+ with open (os .path .join (script_dir , 'python' , 'VERSION' ), 'r' ) as f :
19+ version = f .read ()
20+ print ('Got %s from VERSION file' % version )
21+
22+ # importlib is available only for python3. Since we build wheels, prefer .so
23+ # extension. This way a wheel built by any python3.x will work with any python3.
24+ suffix = '.so'
25+ try :
26+ import importlib .machinery
27+ suffix = importlib .machinery .EXTENSION_SUFFIXES [- 1 ]
28+ except Exception as e :
29+ print ('[WARN] Failed to determine importlib suffix' )
30+ suffix = '.so'
31+ print ('[INFO] Suffix for python SO: %s' % suffix )
32+
33+ numCores_ = os .cpu_count () - 1
34+
1235
1336class CMakeExtension (Extension ):
1437 def __init__ (self , name ):
@@ -17,16 +40,16 @@ def __init__(self, name):
1740
1841
1942class build_ext (build_ext_orig ):
20-
2143 def run (self ):
2244 for ext in self .extensions :
2345 self .build_cmake (ext )
2446 super ().run ()
2547
2648 def build_cmake (self , ext ):
49+ global numCores_
2750 cwd = pathlib .Path ().absolute ()
2851
29- # these dirs will be created in build_py, so if you don't have
52+ # These dirs will be created in build_py, so if you don't have
3053 # any python sources to bundle, the dirs will be missing
3154 build_temp = pathlib .Path (self .build_temp )
3255 build_temp .mkdir (parents = True , exist_ok = True )
@@ -36,16 +59,12 @@ def build_cmake(self, ext):
3659 # example of cmake args
3760 config = 'Debug' if self .debug else 'Release'
3861 cmake_args = [
39- '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + str (extdir .parent .absolute ()),
40- '-DCMAKE_BUILD_TYPE=' + config
41- ]
42-
43- # example of build args
44- build_args = [
45- '--config' , config ,
46- '--' , '-j4'
62+ '-DPYTHON_EXECUTABLE=%s' % sys .executable ,
63+ '-DCMAKE_BUILD_TYPE=%s' % config
4764 ]
4865
66+ print ("[INFO ] Building pymoose in %s ..." % build_temp )
67+ build_args = ['--config' , config , '--' , '-j%d' % numCores_ ]
4968 os .chdir (str (build_temp ))
5069 self .spawn (['cmake' , str (cwd )] + cmake_args )
5170 if not self .dry_run :
@@ -57,19 +76,31 @@ def build_cmake(self, ext):
5776 readme = f .read ()
5877
5978setup (
60- name = "pymoose" ,
61- version = "3.2.0" ,
62- description = "Multiscale Object Oriented Simulation Engine" ,
63- long_description = readme ,
64- long_description_content_type = 'text/markdown' ,
65- packages = ["pymoose" ],
66- package_dir = {"pymoose" : os .path .join ("python" , "moose" )},
67- package_data = {},
68- ext_modules = [CMakeExtension ('pymoose' )],
69- cmdclass = {'build_ext' : build_ext },
70- install_requires = [ ],
71- author = "Dilawar Singh" ,
72- author_email = "[email protected] " ,
73- url = "http://github.com/BhallaLab/moose-core" ,
74- license = 'GPLv3' ,
79+ name = "pymoose" ,
80+ version = version ,
81+ description = 'Python scripting interface of MOOSE Simulator (https://moose.ncbs.res.in)' ,
82+ long_description = readme ,
83+ long_description_content_type = 'text/markdown' ,
84+ author = 'MOOSERes' ,
85+ 86+ maintainer = 'Dilawar Singh' ,
87+ maintainer_email = '[email protected] ' ,
88+ url = 'http://moose.ncbs.res.in' ,
89+ packages = [
90+ 'rdesigneur' , 'moose' , 'moose.SBML' , 'moose.genesis' , 'moose.neuroml' ,
91+ 'moose.neuroml2' , 'moose.chemUtil' , 'moose.chemMerge'
92+ ],
93+ install_requires = ['numpy' ],
94+ package_dir = {
95+ 'moose' : os .path .join ('python' , 'moose' ),
96+ 'rdesigneur' : os .path .join ('python' , 'rdesigneur' )
97+ },
98+ package_data = {
99+ 'moose' : [
100+ '_moose' + suffix , 'neuroml2/schema/NeuroMLCoreDimensions.xml' ,
101+ 'chemUtil/rainbow2.pkl'
102+ ]
103+ },
104+ ext_modules = [CMakeExtension ('.' )],
105+ cmdclass = {'build_ext' : build_ext },
75106)
0 commit comments