Skip to content

Commit

Permalink
fixing build process
Browse files Browse the repository at this point in the history
  • Loading branch information
dfm committed Oct 23, 2019
1 parent 78d318c commit f92f8a2
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 137 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ code/Templates/Builder/MyModel.h
code/Templates/Builder/MyModel.cpp
ms.out
dnest4.lib
build
dist
5 changes: 5 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include LICENSE *.rst python/*.rst *.toml

include code/*.cpp
include code/Distributions/*.cpp
include code/RJObject/ConditionalPriors/*.cpp
7 changes: 4 additions & 3 deletions code/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
CXX = g++
export CXX
CXXFLAGS = -std=c++11 -O3 -march=native -Wall -Wextra -pedantic -DNDEBUG
CXXFLAGS = -std=c++11 -O3 -Wall -Wextra -pedantic -DNDEBUG

SRCS = $(wildcard *.cpp) \
$(wildcard Distributions/*.cpp) \
Expand All @@ -15,6 +13,9 @@ libdnest4.a: $(OBJS)
@echo Creating $@ library
@ar rcs $@ $^

libdnest4: $(OBJS)
$(CXX) ${LDFLAGS} -o $@ $^

examples: $(OBJS) libdnest4.a
make nolib -C Examples/SpikeSlab
make nolib -C Examples/StraightLine
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["setuptools", "wheel", "numpy", "cython"]
build-backend = "setuptools.build_meta"
15 changes: 8 additions & 7 deletions python/dnest4/__init__.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
# -*- coding: utf-8 -*-

__version__ = "0.2.3"
__version__ = "0.2.4"

try:
__DNEST4_SETUP__
except NameError:
__DNEST4_SETUP__ = False

if not __DNEST4_SETUP__:
__all__ = ["DNest4Sampler", "postprocess", "analysis", "my_loadtxt, loadtxt_rows"]
__all__ = [
"DNest4Sampler",
"postprocess",
"analysis",
"my_loadtxt, loadtxt_rows",
]

from . import analysis
from .sampler import DNest4Sampler
from .deprecated import postprocess, postprocess_abc
from .loading import my_loadtxt, loadtxt_rows
from .utils import rand
from .utils import randn
from .utils import randt2
from .utils import randh
from .utils import wrap
from .utils import rand, randn, randt2, randh, wrap

7 changes: 5 additions & 2 deletions python/dnest4/_dnest4.pyx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# distutils: language = c++
# cython: language_level=3, cdivision=True
from __future__ import division

cimport cython
Expand Down Expand Up @@ -32,7 +33,8 @@ cdef extern from "DNest4.h" namespace "DNest4":
cdef cppclass Sampler[T]:
Sampler()
Sampler(unsigned int num_threads, double compression,
const Options options, unsigned save_to_disk)
const Options options, unsigned save_to_disk,
unsigned _adaptive)

# Setup, running, etc.
void initialise(unsigned int first_seed) except +
Expand Down Expand Up @@ -92,6 +94,7 @@ def sample(
# "command line" arguments
seed=None,
double compression=np.exp(1.0),
unsigned int adaptive=0,
):
"""
Sample using a DNest4 model.
Expand Down Expand Up @@ -156,7 +159,7 @@ def sample(

# Declarations.
cdef int i, j, n, error
cdef Sampler[PyModel] sampler = Sampler[PyModel](1, compression, options, 0)
cdef Sampler[PyModel] sampler = Sampler[PyModel](1, compression, options, 0, adaptive)
cdef PyModel* particle
cdef vector[Level] levels
cdef Level level
Expand Down
3 changes: 2 additions & 1 deletion python/dnest4/utils.pyx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
# cython: language_level=3, cdivision=True

__all__ = ["rand", "randn", "randt2", "randh", "wrap"]

cimport cython
Expand Down
124 changes: 0 additions & 124 deletions python/setup.py

This file was deleted.

123 changes: 123 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#!/usr/bin/env python

import os
from setuptools import setup, Extension


if __name__ == "__main__":
import sys

# Publish the library to PyPI.
if "publish" in sys.argv:
os.system("python setup.py sdist upload")
sys.exit()

if "--without-cext" in sys.argv:
sys.argv.remove("--without-cext")
extensions = []

else:
import glob
from itertools import chain

import numpy
from Cython.Build import cythonize

# The root of the DNest4 repo.
basedir = os.path.dirname(os.path.abspath(__file__))

# Set up the C++-extension.
libraries = []
if os.name == "posix":
libraries.append("m")
include_dirs = [
"dnest4",
os.path.join(basedir, "code"),
numpy.get_include(),
]

src = [
os.path.join(basedir, "code", fn)
for fn in chain(
glob.glob(os.path.join(basedir, "code", "*.cpp")),
glob.glob(
os.path.join(basedir, "code", "Distributions", "*.cpp")
),
glob.glob(
os.path.join(
basedir,
"code",
"RJObject",
"ConditionalPriors",
"*.cpp",
)
),
)
]
src += [os.path.join(basedir, "python", "dnest4", "_dnest4.pyx")]

ext = [
Extension(
"dnest4._dnest4",
sources=src,
language="c++",
libraries=libraries,
include_dirs=include_dirs,
extra_compile_args=[
"-std=c++11",
"-Wno-unused-function",
"-Wno-uninitialized",
"-DNO_THREADS",
],
extra_link_args=["-std=c++11"],
),
Extension(
"dnest4.utils",
sources=[
os.path.join(basedir, "python", "dnest4", "utils.pyx")
],
language="c++",
libraries=libraries,
include_dirs=include_dirs,
extra_compile_args=[
"-std=c++11",
"-Wno-unused-function",
"-Wno-uninitialized",
"-DNO_THREADS",
],
extra_link_args=["-std=c++11"],
),
]
extensions = cythonize(ext)

# Hackishly inject a constant into builtins to enable importing of the
# package before the library is built.
if sys.version_info[0] < 3:
import __builtin__ as builtins
else:
import builtins
builtins.__DNEST4_SETUP__ = True
sys.path.insert(0, os.path.join(basedir, "python"))
import dnest4

setup(
name="dnest4",
version=dnest4.__version__,
author="Daniel Foreman-Mackey",
author_email="foreman.mackey@gmail.com",
url="https://github.com/eggplantbren/DNest4",
license="MIT",
packages=["dnest4"],
package_dir={"": "python"},
ext_modules=extensions,
description="Diffusive nested sampling in Python",
long_description=open("python/README.rst").read(),
classifiers=[
# "Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python",
],
)

0 comments on commit f92f8a2

Please sign in to comment.