11# -*- coding: utf-8 -*-
22# This script can also be called directly to build and install the pymoose
33# module.
4+ #
45# Alternatively, you can use cmake build system which provides finer control
56# over the build. This script is called by cmake to install the python module.
7+ #
8+ # This script is compatible with python2.7 and python3+. Therefore use of
9+ # super() is commented out.
10+ #
11+ # NOTES:
12+ # * Python2
13+ # - Update setuptools using `python2 -m pip install setuptools --upgrade --user'.
614
715__author__ = "Dilawar Singh"
816__copyright__ = "Copyright 2019-, Dilawar Singh"
917__maintainer__ = "Dilawar Singh"
10- 18+ 1119
1220import os
1321import sys
1422import subprocess
1523import datetime
1624
17- if sys .version_info [0 ] < 3 :
18- print ("[ERROR] You must use python3.5 or higher.\n "
19- "You used '%s'" % sys .version + " which is not supported." )
20- quit (- 1 )
21-
22- ## TEST IF REQUIRED TOOLS EXISTS.
2325try :
2426 cmakeVersion = subprocess .check_output (["cmake" , "--version" ])
2527except Exception as e :
2628 print ("[ERROR] cmake is not found. Please install cmake." )
2729 quit (- 1 )
2830
29-
3031# See https://docs.python.org/3/library/distutils.html
3132# setuptools is preferred over distutils. And we are supporting python3 only.
3233from setuptools import setup , Extension , Command
3334from setuptools .command .build_ext import build_ext as _build_ext
3435import subprocess
35- from pathlib import Path
3636
3737# Global variables.
38-
39- sdir_ = Path (__file__ ).parent .absolute ()
38+ sdir_ = os .path .dirname (os .path .realpath (__file__ ))
4039stamp = datetime .datetime .now ().strftime ('%Y%m%d' )
41- builddir_ = sdir_ / ('_build_%s' % stamp )
42- builddir_ .mkdir (parents = True , exist_ok = True )
40+ builddir_ = os .path .join (sdir_ , '%s_build_%s' % (sys .version_info [0 ], stamp ))
4341
44- numCores_ = os .cpu_count () - 1
42+ if not os .path .exists (builddir_ ):
43+ os .makedirs (builddir_ )
44+
45+ numCores_ = 4
46+ try :
47+ # Python3 only.
48+ numCores_ = os .cpu_count () - 1
49+ except Exception :
50+ pass
4551
4652version_ = '3.2.dev%s' % stamp
4753
5157class CMakeExtension (Extension ):
5258 def __init__ (self , name ):
5359 # don't invoke the original build_ext for this special extension
54- super ().__init__ (name , sources = [])
55-
60+ Extension .__init__ (self , name , sources = [])
5661
5762class TestCommand (Command ):
5863 user_options = []
@@ -65,8 +70,9 @@ def finalize_options(self):
6570
6671 def run (self ):
6772 print ("[INFO ] Running tests... " )
68- return subprocess .run (["ctest" , "--output-on-failure" , '-j2' ]
69- , cwd = builddir_ )
73+ os .chdir (builddir_ )
74+ self .spawn (["ctest" , "--output-on-failure" , '-j2' ])
75+ os .chdir (sdir_ )
7076
7177class build_ext (_build_ext ):
7278 user_options = [('with-boost' , None , 'Use Boost Libraries (OFF)' )
@@ -82,12 +88,14 @@ def initialize_options(self):
8288 self .debug = 0
8389 self .no_build = 0
8490 self .cmake_options = {}
85- super ().initialize_options ()
91+ # super().initialize_options()
92+ _build_ext .initialize_options (self )
8693
8794 def finalize_options (self ):
8895 # Finalize options.
89- super ().finalize_options ()
90- self .cmake_options ['PYTHON_EXECUTABLE' ] = Path (sys .executable ).resolve ()
96+ # super().finalize_options()
97+ _build_ext .finalize_options (self )
98+ self .cmake_options ['PYTHON_EXECUTABLE' ] = os .path .realpath (sys .executable )
9199 if self .with_boost :
92100 self .cmake_options ['WITH_BOOST' ] = 'ON'
93101 self .cmake_options ['WITH_GSL' ] = 'OFF'
@@ -101,7 +109,8 @@ def run(self):
101109 return
102110 for ext in self .extensions :
103111 self .build_cmake (ext )
104- super ().run ()
112+ # super().run()
113+ _build_ext .run (self )
105114
106115 def build_cmake (self , ext ):
107116 global numCores_
@@ -117,10 +126,9 @@ def build_cmake(self, ext):
117126 self .spawn (['make' , '-j%d' % numCores_ ])
118127 os .chdir (str (sdir_ ))
119128
120- with open (Path ( __file__ ). parent / "README.md" ) as f :
129+ with open (os . path . join ( sdir_ , "README.md" ) ) as f :
121130 readme = f .read ()
122131
123-
124132setup (
125133 name = "pymoose" ,
126134 version = version_ ,
@@ -139,13 +147,14 @@ def build_cmake(self, ext):
139147 # python2 specific version here as well.
140148 install_requires = ['numpy' ],
141149 package_dir = {
142- 'moose' : sdir_ / 'python' / 'moose' ,
143- 'rdesigneur' : sdir_ / 'python' / 'rdesigneur'
150+ 'moose' : os . path . join ( sdir_ , 'python' , 'moose' ) ,
151+ 'rdesigneur' : os . path . join ( sdir_ , 'python' , 'rdesigneur' )
144152 },
145153 package_data = {
146154 'moose' : [
147- '_moose.so' , 'neuroml2/schema/NeuroMLCoreDimensions.xml' ,
148- 'chemUtil/rainbow2.pkl'
155+ '_moose.so'
156+ , os .path .join ('neuroml2' ,'schema' ,'NeuroMLCoreDimensions.xml' )
157+ , os .path .join ('chemUtil' , 'rainbow2.pkl' )
149158 ]
150159 },
151160 ext_modules = [CMakeExtension ('pymoose' )],
0 commit comments