Skip to content

Commit

Permalink
Removed tiledb dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
davisp committed Dec 1, 2023
1 parent aa701da commit e5e2b78
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 60 deletions.
13 changes: 0 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
To Build TileDB
===

```bash
$ cd ~/wherever
$ git clone https://github.com/TileDB-Inc/TileDB tiledb
$ cd tiledb
$ mkdir build
$ cd build
$ ../bootstrap --enable=ccache,serialization --prefix=/opt/tiledb
$ make -j$(nproc) && make -C tiledb -j$(nproc) install
```

To Reproduce
===

Expand Down
64 changes: 44 additions & 20 deletions main.cc
Original file line number Diff line number Diff line change
@@ -1,46 +1,70 @@
#include <pybind11/pybind11.h>
#include <iostream>

#include "tiledb/tiledb"
#include "tiledb/tiledb_experimental"
#include <pybind11/pybind11.h>

using namespace tiledb;
namespace py = pybind11;

void init_enums(py::module& m) {
py::enum_<tiledb_query_type_t>(m, "QueryType")
.value("READ", TILEDB_READ)
.value("WRITE", TILEDB_WRITE)
.value("DELETE", TILEDB_DELETE)
.value("MODIFY_EXCLUSIVE", TILEDB_MODIFY_EXCLUSIVE);
}
class MyContext {
public:
MyContext() : msg_("Can I be a mongoose dog?") {
std::cerr << "Context Constructor: " << (void*) this << std::endl;
}

~MyContext() {
std::cerr << "Context Destructor: " << (void*) this << std::endl;
}

std::string get() const {
return msg_;
}

private:
std::string msg_;
};

class MyGroup {
public:
MyGroup(const MyContext& ctx, const std::string& uri) : ctx_(ctx), uri_(uri) {
std::cerr << "Group Constructor: " << (void*) this << std::endl;
std::cerr << "Group Context: " << (void*) &ctx_ << std::endl;
throw std::runtime_error("Look! A squirrel!");
}

~MyGroup() {
std::cerr << "Group Destructor: " << (void*) this << std::endl;
}

std::string dump(bool) {
return ctx_.get();
}

private:
const MyContext& ctx_;
std::string uri_;
};

void init_context(py::module &m) {
py::class_<Context>(m, "Context")
py::class_<MyContext>(m, "Context")
.def(py::init());
}

std::string do_dump(Group& group, bool recursive) {
std::string do_dump(MyGroup& group, bool recursive) {
std::cerr << "DUMPING GROUP: " << (void*) &group << std::endl;
auto ret = group.dump(recursive);
std::cerr << "FINISHED DUMPING GROUP: " << (void*) &group << std::endl;
return ret;
}

void init_group(py::module &m) {
py::class_<Group>(m, "Group")
py::class_<MyGroup>(m, "Group")
.def(
py::init<const Context &, const std::string &, tiledb_query_type_t>(),
py::init<const MyContext &, const std::string &>(),
py::keep_alive<1, 2>())
.def(py::init<const Context &, const std::string &, tiledb_query_type_t,
const Config &>(),
py::keep_alive<1, 2>())
.def("_dump", do_dump);

}

PYBIND11_MODULE(errortest, m) {
m.doc() = "Test exceptions from contructors";
init_enums(m);
init_context(m);
init_group(m);
}
9 changes: 2 additions & 7 deletions run.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
#!/usr/bin/env bash

echo "================================================"
echo "This requires libtiledb installed in /opt/tiledb"
echo "================================================"
echo ""

if [ -f "errortest.cpython-311-darwin.so" ]; then
rm errortest.cpython-311-darwin.so
if [ -d "./build" ]; then
rm -rf "./build/"
fi

python3 -m venv venv
Expand Down
21 changes: 2 additions & 19 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,11 @@
from pybind11.setup_helpers import Pybind11Extension, build_ext
from setuptools import setup

INC_DIRS = [
'/opt/tiledb/include',
'/Users/davisp/github/tiledb/py-tiledb/venv/lib/python3.11/site-packages/pybind11/include'
]
DEF_MACROS = []
LIB_DIRS = ['/opt/tiledb/lib']
LIBS = ['tiledb']
LFLAGS = ['-stdlib=libc++', '-Wl,-rpath,/opt/tiledb/lib']
CXXFLAGS = ['-std=c++17', '-Wno-deprecated-declarations']

ext_modules = [
Pybind11Extension(
"errortest",
["main.cc"],
include_dirs=INC_DIRS,
define_macros=DEF_MACROS,
library_dirs=LIB_DIRS,
libraries=LIBS,
extra_link_args=LFLAGS,
extra_compile_args=CXXFLAGS + ["-fvisibility=hidden"],
language="c++",
),
["main.cc"]
)
]

setup(ext_modules=ext_modules, cmdclass={"build_ext": build_ext})
2 changes: 1 addition & 1 deletion tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Group(errortest.Group):
def __init__(self, uri):
try:
ctx = errortest.Context()
super().__init__(ctx, uri, errortest.QueryType.WRITE)
super().__init__(ctx, uri)
except Exception as exc:
print(exc)
raise
Expand Down

0 comments on commit e5e2b78

Please sign in to comment.