Skip to content

Commit 18e65d5

Browse files
author
Dilawar Singh
committed
Using python setup.py to build the module.
1 parent 7a8f52d commit 18e65d5

File tree

4 files changed

+68
-150
lines changed

4 files changed

+68
-150
lines changed

CMakeLists.txt

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -368,64 +368,15 @@ if(${_platform_desc} MATCHES ".*(Ubuntu|debian).*")
368368
)
369369
endif()
370370

371-
# Set PYMOOSE binary distribution build and install directories.
372-
# Target for creating bdist. This is handy for creating bdist for packaging.
373-
# Save the binary distribution (tar.gz) to PYMOOSE_BDIST_DIR.
374-
find_package(PythonInterp REQUIRED)
375-
if(NOT PYMOOSE_BDIST_DIR)
376-
set(PYMOOSE_BDIST_DIR ${CMAKE_BINARY_DIR}/bdist)
377-
endif( )
378-
379-
# If no one hsa set the PYMOOSE bdist installation directory, use default.
380-
if(NOT PYMOOSE_BDIST_INSTALL_DIR)
381-
set(PYMOOSE_BDIST_INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/pymoose_bdist_install)
382-
endif()
383-
file(MAKE_DIRECTORY ${PYMOOSE_BDIST_INSTALL_DIR})
384-
385-
# We need a custom name for bdist; same on all platform.
386-
set(_platform "CMAKE" )
387-
set(PYMOOSE_BDIST_FILE ${PYMOOSE_BDIST_DIR}/pymoose-${VERSION_MOOSE}.${_platform}.tar.gz)
388-
message(STATUS "binary distribution file ${PYMOOSE_BDIST_FILE}")
389-
add_custom_target(bdist ALL DEPENDS ${PYMOOSE_BDIST_FILE} )
390-
391-
# Any command using setup.cmake.py must run in the same directory. Use option
392-
# `--relative` to prefix is aways fixed.
393-
add_custom_command( OUTPUT ${PYMOOSE_BDIST_FILE}
394-
COMMAND ${PYTHON_EXECUTABLE} setup.cmake.py bdist_dumb -p ${_platform}
395-
-d ${PYMOOSE_BDIST_DIR} --relative
396-
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/python
397-
COMMENT "bdist is saved to ${PYMOOSE_BDIST_DIR}"
398-
VERBATIM
399-
)
400-
add_custom_command(TARGET bdist POST_BUILD
401-
COMMAND ${CMAKE_COMMAND} -E chdir ${PYMOOSE_BDIST_INSTALL_DIR} tar xf ${PYMOOSE_BDIST_FILE}
402-
COMMENT "Unarchiving bdist file ${PYMOOSE_BDIST_FILE} to ${PYMOOSE_BDIST_INSTALL_DIR}"
403-
VERBATIM
404-
)
405-
406-
# Copy python files from source to current binary directory. Make sure to call
407-
# this before building bdist.
408-
file(GLOB_RECURSE PYTHON_SRCS "${CMAKE_SOURCE_DIR}/python/*")
409-
add_custom_target(copy_pymoose DEPENDS ${PYTHON_SRCS}
410-
COMMAND ${CMAKE_COMMAND} -E copy_directory
411-
${CMAKE_CURRENT_SOURCE_DIR}/python ${CMAKE_CURRENT_BINARY_DIR}/python
412-
COMMENT "Copying required python files and other files to build directory"
413-
VERBATIM
414-
)
415-
416-
add_dependencies( bdist copy_pymoose )
417-
add_dependencies( copy_pymoose _moose )
418371

419372
######################### INSTALL ##############################################
420-
421373
install(TARGETS moose.bin DESTINATION bin CONFIGURATIONS Debug)
422374
install(TARGETS libmoose DESTINATION lib CONFIGURATIONS Debug)
423375

424376
# install pymoose bdist.
425377
install(DIRECTORY ${PYMOOSE_BDIST_INSTALL_DIR}/
426378
DESTINATION ${CMAKE_INSTALL_PREFIX}
427-
CONFIGURATIONS Release Debug
428-
)
379+
CONFIGURATIONS Release Debug)
429380

430381
# Print message to start build process
431382
if(${CMAKE_BUILD_TOOL} MATCHES "make")
@@ -458,7 +409,6 @@ set(PYMOOSE_TEST_DIRECTORY ${CMAKE_SOURCE_DIR}/tests/python)
458409
# Collect all python script in tests folder and run them.
459410
file(GLOB PY_TEST_SCRIPTS "${PYMOOSE_TEST_DIRECTORY}/test_*.py" )
460411

461-
462412
# Run python tests.
463413
foreach( _test_script ${PY_TEST_SCRIPTS} )
464414
get_filename_component( _test_name ${_test_script} NAME_WE)

pymoose/CMakeLists.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,11 @@ else(APPLE)
110110
${SYSTEM_SHARED_LIBS})
111111
endif()
112112

113-
add_custom_command(TARGET _moose POST_BUILD
114-
COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --cyan
115-
"MOOSE python extention is successfully built. Now "
116-
" Run 'sudo make install' to install it. "
117-
" "
118-
"NOTE: Run 'pip uninstall moose' to uninstall moose."
119-
VERBATIM)
113+
#add_custom_command(TARGET _moose POST_BUILD
114+
# COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --cyan
115+
# "MOOSE python extention is successfully built. Now "
116+
# " Run 'sudo make install' to install it. "
117+
# " "
118+
# "NOTE: Run 'pip uninstall moose' to uninstall moose."
119+
# VERBATIM)
120120

python/setup.cmake.py

Lines changed: 0 additions & 63 deletions
This file was deleted.

setup.py

Lines changed: 60 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,37 @@
1-
__author__ = "Dilawar Singh"
2-
__copyright__ = "Copyright 2019-, Dilawar Singh"
3-
__maintainer__ = "Dilawar Singh"
4-
__email__ = "[email protected]"
1+
__author__ = "Dilawar Singh"
2+
__copyright__ = "Copyright 2019-, Dilawar Singh"
3+
__maintainer__ = "Dilawar Singh"
4+
__email__ = "[email protected]"
55

66
import os
77
import sys
88
import pathlib
99
from setuptools import setup, Extension
1010
from 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

1336
class CMakeExtension(Extension):
1437
def __init__(self, name):
@@ -17,16 +40,16 @@ def __init__(self, name):
1740

1841

1942
class 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

5978
setup(
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+
author_email='[email protected]',
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

Comments
 (0)