Skip to content

Commit

Permalink
Merge branch 'improve-setup'
Browse files Browse the repository at this point in the history
  • Loading branch information
mdrasmus committed Jul 16, 2015
2 parents dd899df + e5bc693 commit b32460b
Show file tree
Hide file tree
Showing 79 changed files with 274 additions and 88 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
recursive-include src *.cpp *.h *.inl
34 changes: 3 additions & 31 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 All @@ -215,7 +187,7 @@ $(ALL_OBJS): %.o: %.cpp
$(CXX) -c $(CFLAGS) -o $@ $<

clean:
rm -f $(ALL_OBJS) $(LIBARGWEAVER) $(LIBARGWEAVER_SHARED) $(TEST_OBJS)
rm -f $(ALL_OBJS) $(LIBARGWEAVER) $(LIBARGWEAVER_SHARED) $(TEST_OBJS) $(PROGS)

clean-test:
rm -f $(TEST_OBJS)
Expand Down
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,21 @@ ARGweaver:

## Install

To compile the ARGweaver commands and library use the Makefile:
ARGweaver can be installed using any of the normal Python mechanisms.
For example, to install from [PyPI](https://pypi.python.org/pypi) you
can use [pip](https://github.com/pypa/pip) with the following command:

```
pip install argweaver
```

Alternatively, ARGweaver can be install using the `setup.py` file:

```
python setup.py install
```

Lastly, ARGweaver can be installed using the `Makefile`:

```
make
Expand Down
2 changes: 1 addition & 1 deletion argweaver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
PROGRAM_NAME = u"argweaver"
PROGRAM_VERSION_MAJOR = 0
PROGRAM_VERSION_MINOR = 8
PROGRAM_VERSION_RELEASE = 0
PROGRAM_VERSION_RELEASE = 1
PROGRAM_VERSION = (PROGRAM_VERSION_MAJOR,
PROGRAM_VERSION_MINOR,
PROGRAM_VERSION_RELEASE)
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

139 changes: 135 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,131 @@
# python setup.py install
#

from distutils.core import setup, Extension
from distutils import log
from distutils.core import Command
from distutils.core import Extension
from distutils.core import setup
from distutils.command.build import build as _build
from distutils.command.build_clib import build_clib as _build_clib
from distutils.dep_util import newer_group
from distutils.sysconfig import customize_compiler
import os

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')


# Default to a C++ compiler, if possible.
if os.system('which g++') == 0:
os.environ.setdefault('CC', 'g++')
os.environ.setdefault('CXX', 'g++')


class build(_build):
"""
Add more subcommands to the build command.
"""
sub_commands = _build.sub_commands + [('build_prog', lambda cmd: True)]


class build_prog(_build_clib):
"""
Build subcommand for compiling programs.
This is implemented as subclass of build_clib since compiling a
C/C++ program is very similar to compiling C/C++ library.
"""

description = 'build compiled programs'

# Config. Ideally, we could add this to setup().
progs = [
(
'arg-sample',
{
'sources': lib_src + ['src/arg-sample.cpp'],
}
),
(
'arg-summarize',
{
'sources': lib_src + ['src/arg-summarize.cpp'],
}
),
(
'smc2bed',
{
'sources': lib_src + ['src/smc2bed.cpp'],
}
),
]

def initialize_options(self):
# Call super class.
_build_clib.initialize_options(self)

# Directory for built binaries.
self.build_bin = None

def finalize_options(self):
# Call super class.
_build_clib.finalize_options(self)

self.set_undefined_options('build', ('build_scripts', 'build_bin'))

self.libraries = self.progs
if self.libraries:
self.check_library_list(self.libraries)

def build_libraries(self, libraries):
if not os.path.exists(self.build_bin):
os.makedirs(self.build_bin)

for (prog_name, build_info) in libraries:
sources = build_info.get('sources')
if sources is None or not isinstance(sources, (list, tuple)):
raise DistutilsSetupError, \
("in 'libraries' option ('%s'), " +
"'sources' must be present and must be " +
"a list of source filenames") % prog_name
sources = list(sources)

# Skip build, if program already built.
prog_path = os.path.join(self.build_bin, prog_name)
if not (self.force or newer_group(sources, prog_path, 'newer')):
log.debug("skipping '%s' program (up-to-date)", prog_name)
return

log.info("building '%s' program", prog_name)

macros = build_info.get('macros')
include_dirs = build_info.get('include_dirs')
objects = self.compiler.compile(sources,
output_dir=self.build_temp,
macros=macros,
include_dirs=include_dirs,
debug=self.debug)
self.compiler.link_executable(objects, prog_name,
output_dir=self.build_bin,
debug=self.debug)


setup(
name='argweaver',
Expand All @@ -22,7 +140,20 @@
""",
author='Matt Rasmussen',
author_email='[email protected]',

packages=['argweaver', 'argweaver.deps.rasmus', 'argweaver.deps.compbio'],
cmdclass={
'build': build,
'build_prog': build_prog,
},
packages=[
'argweaver',
'argweaver.deps.rasmus',
'argweaver.deps.compbio',
],
scripts=scripts,
ext_modules=[
Extension(
'libargweaver',
lib_src,
)
],
)
24 changes: 12 additions & 12 deletions src/arg-sample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@
#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;


// version info
#define VERSION_TEXT "0.8"
#define VERSION_TEXT "0.8.1"
#define VERSION_INFO "\
ARGweaver " VERSION_TEXT " \n\
Matt Rasmussen\n\
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
Loading

0 comments on commit b32460b

Please sign in to comment.