Skip to content
This repository was archived by the owner on Nov 3, 2022. It is now read-only.

Commit ac30142

Browse files
committed
Run in inside a docker image to tweak.
1 parent 8bee4d0 commit ac30142

File tree

1 file changed

+38
-29
lines changed

1 file changed

+38
-29
lines changed

setup.py

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,48 @@
55

66
import os
77
import sys
8+
import subprocess
9+
10+
#### TEST IF REQUIRED TOOLS EXISTS.
11+
if sys.version_info[0] < 3:
12+
print("[ERROR] You must use python3.5 or higher. "
13+
"You used %s" % sys.version + " which is not supported.")
14+
quit(-1)
15+
16+
try:
17+
cmakeVersion = subprocess.check_output(["cmake", "--version"])
18+
print("[INFO ] CMake found: %s" % cmakeVersion.decode('utf8'))
19+
20+
except Exception as e:
21+
print(f"[ERROR] cmake is not found. Please install cmake.", file=sys.stderr)
22+
quit(-1)
23+
24+
25+
# See https://docs.python.org/3/library/distutils.html
26+
# setuptools is preferred over distutils. And we are supporting python3 only.
27+
from setuptools import setup, Extension, Command
28+
from setuptools.command.build_ext import build_ext
29+
import subprocess
830
import pathlib
9-
from setuptools import setup, Extension
10-
from setuptools.command.build_ext import build_ext as build_ext_orig
31+
32+
# Global variables.
1133

1234
sdir_ = pathlib.Path().absolute()
35+
builddir_ = sdir_ / '_build'
36+
builddir_.mkdir(parents=True, exist_ok=True)
1337
numCores_ = os.cpu_count() - 1
1438

15-
version = '3.1.2'
39+
version_ = '3.1.2'
1640

1741
# importlib is available only for python3. Since we build wheels, prefer .so
1842
# extension. This way a wheel built by any python3.x will work with any python3.
19-
suffix = '.so'
20-
try:
21-
import importlib.machinery
22-
suffix = importlib.machinery.EXTENSION_SUFFIXES[-1]
23-
except Exception as e:
24-
print('[WARN] Failed to determine importlib suffix')
25-
suffix = '.so'
26-
print('[INFO] Suffix for python SO: %s' % suffix)
2743

2844
class CMakeExtension(Extension):
2945
def __init__(self, name):
3046
# don't invoke the original build_ext for this special extension
3147
super().__init__(name, sources=[])
3248

33-
class build_ext(build_ext_orig):
49+
class build_ext_cmake(build_ext):
3450
def run(self):
3551
for ext in self.extensions:
3652
self.build_cmake(ext)
@@ -39,38 +55,30 @@ def run(self):
3955
def build_cmake(self, ext):
4056
global numCores_
4157
global sdir_
42-
43-
# These dirs will be created in build_py, so if you don't have
44-
# any python sources to bundle, the dirs will be missing
45-
build_temp = pathlib.Path(self.build_temp)
46-
build_temp.mkdir(parents=True, exist_ok=True)
47-
extdir = pathlib.Path(self.get_ext_fullpath(ext.name))
48-
extdir.mkdir(parents=True, exist_ok=True)
58+
print("\n==========================================================\n")
59+
print("[INFO ] Building pymoose in %s ..." % builddir_)
4960

5061
# example of cmake args
5162
config = 'Debug' if self.debug else 'Release'
5263
cmake_args = [
5364
'-DPYTHON_EXECUTABLE=%s' % sys.executable,
65+
'-DVERSION_MOOSE=%s' % version_,
5466
'-DCMAKE_BUILD_TYPE=%s' % config
5567
]
56-
57-
print("[INFO ] Building pymoose in %s ..." % build_temp)
5868
build_args = ['--config', config, '--', '-j%d' % numCores_]
59-
os.chdir(str(build_temp))
69+
os.chdir(str(builddir_))
6070
self.spawn(['cmake', str(sdir_)] + cmake_args)
61-
if not self.dry_run:
71+
if not self.dry_run:
6272
self.spawn(['cmake', '--build', '.'] + build_args)
6373
os.chdir(str(sdir_))
6474

65-
66-
67-
6875
with open("README.md") as f:
6976
readme = f.read()
7077

78+
7179
setup(
7280
name="pymoose",
73-
version=version,
81+
version=version_,
7482
description= 'Python scripting interface of MOOSE Simulator (https://moose.ncbs.res.in)',
7583
long_description=readme,
7684
long_description_content_type='text/markdown',
@@ -83,17 +91,18 @@ def build_cmake(self, ext):
8391
'rdesigneur', 'moose', 'moose.SBML', 'moose.genesis', 'moose.neuroml',
8492
'moose.neuroml2', 'moose.chemUtil', 'moose.chemMerge'
8593
],
94+
# python2 specific version here as well.
8695
install_requires=['numpy'],
8796
package_dir={
8897
'moose': os.path.join('python', 'moose'),
8998
'rdesigneur': os.path.join('python', 'rdesigneur')
9099
},
91100
package_data={
92101
'moose': [
93-
'_moose' + suffix, 'neuroml2/schema/NeuroMLCoreDimensions.xml',
102+
'_moose.so', 'neuroml2/schema/NeuroMLCoreDimensions.xml',
94103
'chemUtil/rainbow2.pkl'
95104
]
96105
},
97106
ext_modules=[CMakeExtension('.')],
98-
cmdclass={'build_ext': build_ext, 'test': DiscoverTest},
107+
cmdclass={'build_ext': build_ext_cmake},
99108
)

0 commit comments

Comments
 (0)