aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2016-08-16 12:38:01 +0200
committerMattias Andrée <maandree@kth.se>2016-08-16 12:38:01 +0200
commitab5165c215afef4f2bfa0b7e3859e055da493da6 (patch)
tree45c09e8a92435dba789dca88cc43e0731339f6b1
parent... (diff)
downloadpylibcoopgamma-ab5165c215afef4f2bfa0b7e3859e055da493da6.tar.gz
pylibcoopgamma-ab5165c215afef4f2bfa0b7e3859e055da493da6.tar.bz2
pylibcoopgamma-ab5165c215afef4f2bfa0b7e3859e055da493da6.tar.xz
Fix libcoopgamma.py + finish makefile
Signed-off-by: Mattias Andrée <maandree@kth.se>
-rw-r--r--Makefile111
-rw-r--r--src/libcoopgamma.py9
2 files changed, 115 insertions, 5 deletions
diff --git a/Makefile b/Makefile
index e3dd8b8..b398874 100644
--- a/Makefile
+++ b/Makefile
@@ -1,8 +1,21 @@
+PREFIX = /usr
+LIBDIR = $(PREFIX)$(LIB)
+DATADIR = $(PREFIX)$(DATA)
+LICENSEDIR = $(DATADIR)/licenses
+
+PKGNAME = pylibcoopgamma
+
GPP = gpp
CYTHON = cython
PKGCONFIG = pkg-config
+PYTHON = python3
-PY_MAJOR = 3
+PY_MAJOR = $(shell $(PYTHON) --version | cut -d ' ' -f 2 | cut -d . -f 1)
+PY_MINOR = $(shell $(PYTHON) --version | cut -d ' ' -f 2 | cut -d . -f 2)
+PY_VER = $(PY_MAJOR)$(PY_MINOR)
+PY_VERSION = $(PY_MAJOR).$(PY_MINOR)
+
+PYTHONDIR = $(LIBDIR)/python$(PY_VERSION)
OPTIMISE = -O2
LIBS = python$(PY_MAJOR)
@@ -10,8 +23,31 @@ LIBS = python$(PY_MAJOR)
CC_FLAGS = $$($(PKGCONFIG) --cflags $(LIBS)) -std=c99 $(OPTIMISE) -fPIC $(CFLAGS) $(CPPFLAGS)
LD_FLAGS = $$($(PKGCONFIG) --libs $(LIBS)) -lcoopgamma -std=c99 $(OPTIMISE) -shared $(LDFLAGS)
+ifeq ($(shell test $(PY_VER) -ge 35 ; echo $$?),0)
+PY_OPT2_EXT = opt-2.pyc
+else
+PY_OPT2_EXT = pyo
+endif
+
+
+
+.PHONY: all
+all: base
+
+.PHONY: base
+base: lib
+
+.PHONY: lib
+lib: compiled optimised native
-all: bin/libcoopgamma_native.so
+.PHONY: compiled
+compiled: src/__pycache__/libcoopgamma.cpython-$(PY_VER).pyc
+
+.PHONY: optimised
+optimised: src/__pycache__/libcoopgamma.cpython-$(PY_VER).$(PY_OPT2_EXT)
+
+.PHONY: so-files
+native: bin/libcoopgamma_native.so
obj/libcoopgamma_native.pyx: src/libcoopgamma_native.pyx.gpp
@mkdir -p obj
@@ -27,3 +63,74 @@ bin/%.so: obj/%.o
@mkdir -p bin
$(CC) $(LD_FLAGS) -o $@ $^
+src/__pycache__/%.cpython-$(PY_VER).pyc: src/%.py
+ $(PYTHON) -m compileall $<
+
+src/__pycache__/%.cpython-$(PY_VER).$(PY_OPT2_EXT): src/%.py
+ $(PYTHON) -OO -m compileall $<
+
+
+
+.PHONY: install
+install: install-base
+
+.PHONY: install-all
+install-all: install-base
+
+.PHONY: install-base
+install-base: install-lib install-copyright
+
+.PHONY: install-lib
+install-lib: install-source install-compiled install-optimised install-native
+
+.PHONY: install-source
+install-source: src/libcoopgamma.py
+ mkdir -p -- "$(DESTDIR)$(PYTHONDIR)"
+ cp $^ -- "$(DESTDIR)$(PYTHONDIR)"
+
+.PHONY: install-compiled
+install-compiled: src/__pycache__/libcoopgamma.cpython-$(PY_VER).pyc
+ mkdir -p -- "$(DESTDIR)$(PYTHONDIR)/__pycache__"
+ cp $^ -- "$(DESTDIR)$(PYTHONDIR)/__pycache__"
+
+.PHONY: install-optimised
+install-optimised: src/__pycache__/libcoopgamma.cpython-$(PY_VER).$(PY_OPT2_EXT)
+ mkdir -p -- "$(DESTDIR)$(PYTHONDIR)/__pycache__"
+ cp $^ -- "$(DESTDIR)$(PYTHONDIR)/__pycache__"
+
+.PHONY: install-native
+install-native: bin/libcoopgamma_native.so
+ mkdir -p -- "$(DESTDIR)$(PYTHONDIR)"
+ cp $^ -- "$(DESTDIR)$(PYTHONDIR)"
+
+.PHONY: install-copyright
+install-copyright: install-copying install-license
+
+.PHONY: install-copying
+install-copying: COPYING
+ mkdir -p -- "$(DESTDIR)$(LICENSEDIR)/$(PKGNAME)"
+ cp $^ -- "$(DESTDIR)$(LICENSEDIR)/$(PKGNAME)"
+
+.PHONY: install-license
+install-license: LICENSE
+ mkdir -p -- "$(DESTDIR)$(LICENSEDIR)/$(PKGNAME)"
+ cp $^ -- "$(DESTDIR)$(LICENSEDIR)/$(PKGNAME)"
+
+
+
+.PHONY: uninstall
+uninstall:
+ -rm -- "$(DESTDIR)$(LICENSEDIR)/$(PKGNAME)/LICENSE"
+ -rm -- "$(DESTDIR)$(LICENSEDIR)/$(PKGNAME)/COPYING"
+ -rmdir -- "$(DESTDIR)$(LICENSEDIR)/$(PKGNAME)"
+ -rm -- "$(DESTDIR)$(PYTHONDIR)/__pycache__/libcoopgamma.cpython-$(PY_VER).$(PY_OPT2_EXT)"
+ -rm -- "$(DESTDIR)$(PYTHONDIR)/__pycache__/libcoopgamma.cpython-$(PY_VER).pyc"
+ -rm -- "$(DESTDIR)$(PYTHONDIR)/libcoopgamma.py"
+ -rm -- "$(DESTDIR)$(PYTHONDIR)/libcoopgamma_native.so"
+
+
+
+.PHONY: clean
+clean:
+ -rm -r obj bin src/__pycache__
+
diff --git a/src/libcoopgamma.py b/src/libcoopgamma.py
index fe3e57a..162fa23 100644
--- a/src/libcoopgamma.py
+++ b/src/libcoopgamma.py
@@ -447,7 +447,7 @@ class FilterTable:
and `filters[0].priority` are undefined.
'''
def __init__(self, red_size : int = None, green_size : int = None, blue_size : int = None,
- depth : Depth = None, filters : list):
+ depth : Depth = None, filters : list = None):
'''
Constructor
@@ -466,7 +466,10 @@ class FilterTable:
self.green_size = green_size
self.blue_size = blue_size
self.depth = depth
- self.filters = list(QueriedFilter(*f) if isinstance(f, tuple) else f for f in filters)
+ if filters is None:
+ self.filters
+ else:
+ self.filters = list(QueriedFilter(*f) if isinstance(f, tuple) else f for f in filters)
def make_ramps(self) -> Ramps:
'''
@@ -939,7 +942,7 @@ class Context:
(successful, value) = value
if successful:
raise ErrorReport.create_error(value)
- return FilterTable:(*value)
+ return FilterTable(*value)
def get_gamma_sync(self, query : FilterQuery) -> FilterTable:
'''