Skip to content
Snippets Groups Projects
Commit 25d7d66f authored by Giovanni Bussi's avatar Giovanni Bussi
Browse files

pypi install without cython

Pypi ships also the plumed.cpp file, so it is not necessary to
ask users to install cython
parent 58aafdf9
No related branches found
No related tags found
No related merge requests found
...@@ -4,14 +4,15 @@ Python wrappers for plumed ...@@ -4,14 +4,15 @@ Python wrappers for plumed
Install using the following commands:: Install using the following commands::
# install dependencies # install dependencies
python -m pip install cython numpy python -m pip install numpy
# install plumed # install plumed
python -m pip 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 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` 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 python
>>> import plumed >>> import plumed
>>> p=plumed.Plumed() >>> p=plumed.Plumed()
...@@ -26,6 +26,7 @@ from setuptools import setup ...@@ -26,6 +26,7 @@ from setuptools import setup
from distutils.extension import Extension from distutils.extension import Extension
import subprocess import subprocess
import os import os
import os.path
import sys import sys
from shutil import copyfile from shutil import copyfile
...@@ -51,18 +52,16 @@ if defaultkernel is not None: ...@@ -51,18 +52,16 @@ if defaultkernel is not None:
extra_compile_args.append("-D__PLUMED_DEFAULT_KERNEL=" + os.path.abspath(defaultkernel)) extra_compile_args.append("-D__PLUMED_DEFAULT_KERNEL=" + os.path.abspath(defaultkernel))
print( "Hardcoded PLUMED_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: try:
import numpy import numpy
except: except:
print('Error: building ' + plumedname + ' requires numpy. Please install it first with pip install numpy') print('Error: building ' + plumedname + ' requires numpy. Please install it first with pip install numpy')
sys.exit(-1) 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()] include_dirs=[numpy.get_include()]
try: try:
...@@ -70,9 +69,44 @@ try: ...@@ -70,9 +69,44 @@ try:
except: except:
include_dirs.append(".") include_dirs.append(".")
def readme(): # allow one to force using cython with env var plumed_force_cython=yes
with open('README.rst') as f: USE_CYTHON = False
return f.read() 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( setup(
name=plumedname, name=plumedname,
...@@ -95,14 +129,7 @@ setup( ...@@ -95,14 +129,7 @@ setup(
author='Gareth A. Tribello', author='Gareth A. Tribello',
author_email='plumed-users@googlegroups.com', author_email='plumed-users@googlegroups.com',
url='http://www.plumed.org', url='http://www.plumed.org',
ext_modules = cythonize([ ext_modules = ext_modules,
Extension( name=plumedname,
sources=["plumed.pyx"],
language="c++",
include_dirs=include_dirs,
extra_compile_args=extra_compile_args
)
]),
zip_safe=False, zip_safe=False,
test_suite='nose.collector' test_suite='nose.collector'
) )
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment