diff --git a/python/README.rst b/python/README.rst index 210ce3e1398e0bdf61e38865249d06064cbc9e7a..30a0244b3a4bcfe30c3405e9004dd6e6b95008f9 100644 --- a/python/README.rst +++ b/python/README.rst @@ -4,14 +4,15 @@ Python wrappers for plumed Install using the following commands:: # install dependencies - python -m pip install cython numpy + python -m pip install numpy # install plumed python -m pip install plumed WARNING: You will need to also build and install the plumed library (see http://www.plumed.org) and set the environment variable `PLUMED_KERNEL` to point to the file `libplumedKernel.so` (or `libplumedKernel.dylib`). Something like this should work:: - PLUMED_KERNEL=/path/to/libplumedKernel.so + export PLUMED_KERNEL=/path/to/libplumedKernel.so python >>> import plumed >>> p=plumed.Plumed() + diff --git a/python/setup.py b/python/setup.py index ffc5fbef62b5bd8fe27d569ff925869d40ba8107..6d9fdae9a66819d7ec2c7e6049639eac53aac6f5 100644 --- a/python/setup.py +++ b/python/setup.py @@ -26,6 +26,7 @@ from setuptools import setup from distutils.extension import Extension import subprocess import os +import os.path import sys from shutil import copyfile @@ -51,18 +52,16 @@ if defaultkernel is not None: extra_compile_args.append("-D__PLUMED_DEFAULT_KERNEL=" + os.path.abspath(defaultkernel)) print( "Hardcoded PLUMED_KERNEL " + os.path.abspath(defaultkernel)) +def readme(): + with open('README.rst') as f: + return f.read() + try: import numpy except: print('Error: building ' + plumedname + ' requires numpy. Please install it first with pip install numpy') sys.exit(-1) -try: - from Cython.Build import cythonize -except: - print('Error: building ' + plumedname + ' requires cython. Please install it first with pip install cython') - sys.exit(-1) - include_dirs=[numpy.get_include()] try: @@ -70,9 +69,44 @@ try: except: include_dirs.append(".") -def readme(): - with open('README.rst') as f: - return f.read() +# allow one to force using cython with env var plumed_force_cython=yes +USE_CYTHON = False +try: + if(os.environ["plumed_force_cython"]=="yes"): + print('plumed_force_cython=yes') + USE_CYTHON = True +except: + pass + +# if plumed.cpp is available, do not need cython +if not USE_CYTHON: + if not os.path.isfile("plumed.cpp"): + print('plumed.cpp not found, cython is needed') + USE_CYTHON = True + +# try to import cython +if USE_CYTHON: + try: + print('importing cython') + from Cython.Build import cythonize + extension="pyx" + except: + print('Error: building ' + plumedname + ' requires cython. Please install it first with pip install cython') + sys.exit(-1) +else: + print('using available plumed.cpp file') + extension="cpp" + +ext_modules=[Extension( + name=plumedname, + sources=["plumed." + extension], + language="c++", + include_dirs=include_dirs, + extra_compile_args=extra_compile_args + )] + +if USE_CYTHON: + ext_modules=cythonize(ext_modules) setup( name=plumedname, @@ -95,14 +129,7 @@ setup( author='Gareth A. Tribello', author_email='plumed-users@googlegroups.com', url='http://www.plumed.org', - ext_modules = cythonize([ - Extension( name=plumedname, - sources=["plumed.pyx"], - language="c++", - include_dirs=include_dirs, - extra_compile_args=extra_compile_args - ) - ]), + ext_modules = ext_modules, zip_safe=False, test_suite='nose.collector' )