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

Improvements to allow for pip install

- renamed script to setup.py
- Use "make pip" to copy required files in this dir for pip
- Use try/except when importing numpy and cython so as to notify the user
- renamed env vars to plumed_xxx so that there is no risk of clashes

Plumed can now also be installed using

cd python
make pip
pip install --user .

make pip is just needed to bring version information and Plumed.h
in this directory. Might be solved differently in MacPorts / Pypi.
parent d980421c
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,8 @@ ifneq ($(MAKECMDGOALS),clean)
-include ../Makefile.conf
endif
VERSION = $(shell if test -f ../VERSION ; then grep -v \\\# ../VERSION ; else echo "Unknown" ; fi )
.PHONY: all clean install
plumed_compiled := $(wildcard ../src/lib/plumed)
......@@ -19,10 +21,11 @@ ifdef python_bin
all:
@echo Building python interface for PLUMED
unset CXX && unset CC && unset CFLAGS && unset CXXFLAGS && unset LDSHARED && \
program_name=plumed \
include_dir=../src/wrapper \
default_kernel="$$PWD/../src/lib/libplumedKernel.$(SOEXT)" \
$(python_bin) buildPythonInterface.py build_ext -i
plumed_program_name=plumed \
plumed_version=$(VERSION) \
plumed_include_dir=../src/wrapper \
plumed_default_kernel="$$PWD/../src/lib/libplumedKernel.$(SOEXT)" \
$(python_bin) setup.py build_ext -i
else
......@@ -32,5 +35,9 @@ endif
endif
pip:
cp ../src/wrapper/Plumed.h .
cp ../VERSION .
clean:
rm -fr *.so plumed.cpp build
rm -fr *.so plumed.cpp build Plumed.h VERSION
......@@ -24,27 +24,47 @@
#
from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
import numpy
import subprocess
import os
import sys
plumedname = os.getenv("program_name")
plumedname = os.getenv("plumed_program_name")
if plumedname is None:
plumedname = "plumed"
plumedversion = subprocess.check_output(['grep','-v','#','../VERSION']).decode("utf-8")
plumedversion = os.getenv("plumed_version")
if plumedversion is None:
plumedversion = subprocess.check_output(['grep','-v','#','./VERSION']).decode("utf-8")
print( "Module name " + plumedname )
print( "Version number " + plumedversion )
extra_compile_args=['-D__PLUMED_HAS_DLOPEN','-D__PLUMED_WRAPPER_LINK_RUNTIME=1','-D__PLUMED_WRAPPER_CXX=1','-D__PLUMED_WRAPPER_IMPLEMENTATION=1','-D__PLUMED_WRAPPER_EXTERN=0','-D__PLUMED_WRAPPER_CXX_DEFAULT_INVALID=1']
defaultkernel=os.getenv("default_kernel")
defaultkernel=os.getenv("plumed_default_kernel")
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))
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:
include_dirs.append(os.environ["plumed_include_dir"])
except:
include_dirs.append(".")
setup(
name=plumedname,
version=plumedversion,
......@@ -56,7 +76,7 @@ setup(
Extension( name=plumedname,
sources=["plumed.pyx"],
language="c++",
include_dirs=[os.environ["include_dir"], numpy.get_include()],
include_dirs=include_dirs,
extra_compile_args=extra_compile_args
)
])
......
......@@ -313,10 +313,11 @@ ifdef python_bin
cp -pr ../../python install
cd install/python && rm -fr *.so plumed.cpp build && \
unset CXX && unset CC && unset CFLAGS && unset CXXFLAGS && unset LDSHARED && \
program_name="$(program_name)" \
include_dir=../../../wrapper \
default_kernel="$(libdir)/lib$(program_name)Kernel.$(SOEXT)" \
$(python_bin) buildPythonInterface.py build_ext -i
plumed_program_name="$(program_name)" \
plumed_version=$(VERSION) \
plumed_include_dir=../../../wrapper \
plumed_default_kernel="$(libdir)/lib$(program_name)Kernel.$(SOEXT)" \
$(python_bin) setup.py build_ext -i
cp -pr install/python "$(DESTDIR)$(libdir)/$(program_name)/"
endif
ifdef BASH_COMPLETION_DIR
......
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