Skip to content

Commit

Permalink
improved setup.py for installing python extension
Browse files Browse the repository at this point in the history
  • Loading branch information
mdrasmus committed Jul 6, 2015
1 parent c119b40 commit 2bc6004
Show file tree
Hide file tree
Showing 74 changed files with 113 additions and 73 deletions.
32 changes: 2 additions & 30 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,35 +53,7 @@ SCRIPTS = bin/*
PROGS = bin/arg-sample bin/arg-summarize bin/smc2bed
BINARIES = $(PROGS) $(SCRIPTS)

ARGWEAVER_SRC = \
src/compress.cpp \
src/emit.cpp \
src/est_popsize.cpp \
src/fs.cpp \
src/hmm.cpp \
src/IntervalIterator.cpp \
src/itree.cpp \
src/local_tree.cpp \
src/logging.cpp \
src/matrices.cpp \
src/mem.cpp \
src/model.cpp \
src/newick.cpp \
src/parsing.cpp \
src/ptree.cpp \
src/recomb.cpp \
src/sample_arg.cpp \
src/sample_thread.cpp \
src/seq.cpp \
src/states.cpp \
src/sequences.cpp \
src/tabix.cpp \
src/thread.cpp \
src/total_prob.cpp \
src/track.cpp \
src/trans.cpp \
src/Tree.cpp \
src/t2exp.cpp
ARGWEAVER_SRC = $(shell ls src/argweaver/*.cpp)

# src/prior.cpp
# src/expm/matrix_exponential.cpp
Expand Down Expand Up @@ -195,7 +167,7 @@ gtest:
#-----------------------------
# install

install: $(BINARIES) $(LIBARGWEAVER_SHARED_INSTALL)
install: $(BINARIES)
mkdir -p $(prefix)/bin
cp $(BINARIES) $(prefix)/bin
$(PYTHON) setup.py install --prefix=$(prefix)
Expand Down
32 changes: 24 additions & 8 deletions argweaver/ctypes_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,31 @@ def wrapper(*args):


def load_library(path, lib):
errors = []

try:
# use library from source path
libdir = os.path.join(os.path.dirname(__file__), *path)
return cdll.LoadLibrary(os.path.join(libdir, lib))
except Exception, e:
# search for lib in library path
try:
return cdll.LoadLibrary(lib)
except Exception, e2:
print >>sys.stderr, e
print >>sys.stderr, e2
return None
except Exception as error:
errors.append(error)

# Search for lib in library path.
try:
return cdll.LoadLibrary(lib)
except Exception as error:
errors.append(error)

# Search PYTHONPATH for shared library.
for path in sys.path:
filename = os.path.join(path, lib)
if os.path.exists(filename):
try:
return cdll.LoadLibrary(filename)
except Exception as error:
errors.append(error)

# Display import errors.
for error in errors:
print >>sys.stderr, error
return None
6 changes: 3 additions & 3 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
nose
pyflakes
pep8
nose=1.3.7
pyflakes=0.9.2
pep8=1.5.6

23 changes: 22 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,21 @@
import argweaver
VERSION = argweaver.PROGRAM_VERSION_TEXT

scripts = [os.path.join('bin', x) for x in os.listdir('bin')]

def get_files(path, ext=''):
"""
Get all files in a directory with a extension.
"""
files = []
for filename in os.listdir(path):
if filename.endswith(ext):
files.append(os.path.join(path, filename))
return files


scripts = get_files('bin')
lib_src = get_files('src/argweaver', '.cpp')


setup(
name='argweaver',
Expand All @@ -25,4 +39,11 @@

packages=['argweaver', 'argweaver.deps.rasmus', 'argweaver.deps.compbio'],
scripts=scripts,

ext_modules=[
Extension(
'libargweaver',
lib_src,
)
],
)
22 changes: 11 additions & 11 deletions src/arg-sample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
#include <unistd.h>

// arghmm includes
#include "compress.h"
#include "ConfigParam.h"
#include "emit.h"
#include "fs.h"
#include "logging.h"
#include "mem.h"
#include "parsing.h"
#include "sample_arg.h"
#include "sequences.h"
#include "total_prob.h"
#include "track.h"
#include "argweaver/compress.h"
#include "argweaver/ConfigParam.h"
#include "argweaver/emit.h"
#include "argweaver/fs.h"
#include "argweaver/logging.h"
#include "argweaver/mem.h"
#include "argweaver/parsing.h"
#include "argweaver/sample_arg.h"
#include "argweaver/sequences.h"
#include "argweaver/total_prob.h"
#include "argweaver/track.h"


using namespace argweaver;
Expand Down
22 changes: 11 additions & 11 deletions src/arg-summarize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@
#include <vector>
#include <math.h>
#include <queue>
#include <map>

// arghmm includes
#include "ConfigParam.h"
#include "logging.h"
#include "parsing.h"
#include "track.h"
#include "Tree.h"
#include "tabix.h"
#include "compress.h"
#include "IntervalIterator.h"
#include <set>
#include <map>

// argweaver includes
#include "argweaver/ConfigParam.h"
#include "argweaver/logging.h"
#include "argweaver/parsing.h"
#include "argweaver/track.h"
#include "argweaver/Tree.h"
#include "argweaver/tabix.h"
#include "argweaver/compress.h"
#include "argweaver/IntervalIterator.h"
//#include "allele_age.h"


using namespace argweaver;
using namespace spidir;

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions src/prior.cpp → src/argweaver/prior.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

namespace argweaver {

/*
// Currently, disabled.
static inline double H(int i, int j, double n)
{
Expand Down Expand Up @@ -53,5 +56,7 @@ double prob_coal_counts_matrix(int a, int b, double t, double n)
} // extern "C"
*/

} // namespace argweaver

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 6 additions & 4 deletions src/smc2bed.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#include "getopt.h"
#include <iostream>
#include <fstream>
#include <assert.h>

#include "Tree.h"
#include "compress.h"
#include "getopt.h"
#include "parsing.h"
// argweaver includes
#include "argweaver/Tree.h"
#include "argweaver/compress.h"
#include "argweaver/parsing.h"


using namespace spidir;
using namespace argweaver;
Expand Down
34 changes: 29 additions & 5 deletions test/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,41 @@
from rasmus.testing import make_clean_dir


def run_cmd(cmd):
assert os.system(cmd) == 0
def run_cmd(cmd, ret_code=0):
"""
Run shell command and assert success exit code.
"""
assert os.system(cmd) == ret_code


def test_install():
def test_install_prog():
"""
Test installing ARGweaver.
Test installing ARGweaver program.
Use Makefile to install.
"""

make_clean_dir("test/tmp/install")
run_cmd("python setup.py clean > /dev/null")
run_cmd("make install prefix=test/tmp/install > /dev/null")
run_cmd("PYTHONPATH=test/tmp/install python -c 'import argweaver'")
run_cmd("PYTHONPATH=test/tmp/install python -c 'import argweaver; "
"assert argweaver.argweaverc.argweaverclib'")
assert os.path.exists("test/tmp/install/bin/arg-sample")


def test_install_lib():
"""
Test installing ARGweaver python lib.
Use setup.py to install and check that module can be imported.
Also ensure that c library is installed.
"""

make_clean_dir("test/tmp/install")
run_cmd("python setup.py clean > /dev/null")
run_cmd(
"python setup.py install --prefix=test/tmp/install "
"--install-lib=test/tmp/install/lib/python/site-packages > /dev/null")
run_cmd("cd test; PYTHONPATH=tmp/install/lib/python/site-packages "
"python -c 'import argweaver; "
"assert argweaver.argweaverc.argweaverclib'")

0 comments on commit 2bc6004

Please sign in to comment.