Skip to content

Commit dd2dde1

Browse files
authored
Merge pull request #9 from mytlogos/main
Format Files according to pep8
2 parents 00d5e0b + d3f18fb commit dd2dde1

File tree

5 files changed

+69
-37
lines changed

5 files changed

+69
-37
lines changed

objectbox/box.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,12 @@ def _put_many(self, objects) -> None:
9292
key = ctypes.c_size_t(k)
9393

9494
# OBX_bytes_array.data[k] = data
95-
obx_bytes_array_set(c_bytes_array_p, key, data[k], len(data[k]))
95+
obx_bytes_array_set(c_bytes_array_p, key,
96+
data[k], len(data[k]))
9697

9798
c_ids = (obx_id * len(ids))(*ids.values())
98-
obx_box_put_many(self._c_box, c_bytes_array_p, c_ids, OBXPutMode_PUT)
99+
obx_box_put_many(self._c_box, c_bytes_array_p,
100+
c_ids, OBXPutMode_PUT)
99101

100102
finally:
101103
obx_bytes_array_free(c_bytes_array_p)
@@ -108,7 +110,8 @@ def get(self, id: int):
108110
with self._ob.read_tx():
109111
c_data = ctypes.c_void_p()
110112
c_size = ctypes.c_size_t()
111-
obx_box_get(self._c_box, id, ctypes.byref(c_data), ctypes.byref(c_size))
113+
obx_box_get(self._c_box, id, ctypes.byref(
114+
c_data), ctypes.byref(c_size))
112115

113116
data = c_voidp_as_bytes(c_data, c_size.value)
114117
return self._entity.unmarshal(data)

objectbox/c.py

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,23 @@ def shlib_name(library: str) -> str:
4141

4242
# initialize the C library
4343
lib_path = os.path.dirname(os.path.realpath(__file__))
44-
lib_path = os.path.join(lib_path, 'lib', \
45-
platform.machine() if platform.system() != 'Darwin' else 'macos-universal', shlib_name('objectbox'))
44+
lib_path = os.path.join(lib_path, 'lib',
45+
platform.machine() if platform.system() != 'Darwin' else 'macos-universal', shlib_name('objectbox'))
4646
C = ctypes.CDLL(lib_path)
4747

4848
# load the core library version
4949
__major = ctypes.c_int(0)
5050
__minor = ctypes.c_int(0)
5151
__patch = ctypes.c_int(0)
52-
C.obx_version(ctypes.byref(__major), ctypes.byref(__minor), ctypes.byref(__patch))
52+
C.obx_version(ctypes.byref(__major), ctypes.byref(
53+
__minor), ctypes.byref(__patch))
5354

5455
# C-api (core library) version
5556
version_core = Version(__major.value, __minor.value, __patch.value)
5657

5758
assert str(version_core) == required_version, \
58-
"Incorrect ObjectBox version loaded: %s instead of expected %s " % (str(version_core), required_version)
59+
"Incorrect ObjectBox version loaded: %s instead of expected %s " % (
60+
str(version_core), required_version)
5961

6062
# define some basic types
6163
obx_err = ctypes.c_int
@@ -195,7 +197,8 @@ def __init__(self, code):
195197
self.code = code
196198
self.message = py_str(C.obx_last_error_message())
197199
name = self.codes[code] if code in self.codes else "n/a"
198-
super(CoreException, self).__init__("%d (%s) - %s" % (code, name, self.message))
200+
super(CoreException, self).__init__(
201+
"%d (%s) - %s" % (code, name, self.message))
199202

200203

201204
class NotFoundException(Exception):
@@ -228,7 +231,6 @@ def fn(name: str, restype: type, argtypes):
228231

229232
if restype is obx_err:
230233
func.errcheck = check_obx_err
231-
pass
232234
elif restype is not None:
233235
func.errcheck = check_result
234236

@@ -257,23 +259,28 @@ def c_voidp_as_bytes(voidp, size):
257259
obx_model = fn('obx_model', OBX_model_p, [])
258260

259261
# obx_err (OBX_model* model, const char* name, obx_schema_id entity_id, obx_uid entity_uid);
260-
obx_model_entity = fn('obx_model_entity', obx_err, [OBX_model_p, ctypes.c_char_p, obx_schema_id, obx_uid])
262+
obx_model_entity = fn('obx_model_entity', obx_err, [
263+
OBX_model_p, ctypes.c_char_p, obx_schema_id, obx_uid])
261264

262265
# obx_err (OBX_model* model, const char* name, OBXPropertyType type, obx_schema_id property_id, obx_uid property_uid);
263266
obx_model_property = fn('obx_model_property', obx_err,
264267
[OBX_model_p, ctypes.c_char_p, OBXPropertyType, obx_schema_id, obx_uid])
265268

266269
# obx_err (OBX_model* model, OBXPropertyFlags flags);
267-
obx_model_property_flags = fn('obx_model_property_flags', obx_err, [OBX_model_p, OBXPropertyFlags])
270+
obx_model_property_flags = fn('obx_model_property_flags', obx_err, [
271+
OBX_model_p, OBXPropertyFlags])
268272

269273
# obx_err (OBX_model*, obx_schema_id entity_id, obx_uid entity_uid);
270-
obx_model_last_entity_id = fn('obx_model_last_entity_id', None, [OBX_model_p, obx_schema_id, obx_uid])
274+
obx_model_last_entity_id = fn('obx_model_last_entity_id', None, [
275+
OBX_model_p, obx_schema_id, obx_uid])
271276

272277
# obx_err (OBX_model* model, obx_schema_id index_id, obx_uid index_uid);
273-
obx_model_last_index_id = fn('obx_model_last_index_id', None, [OBX_model_p, obx_schema_id, obx_uid])
278+
obx_model_last_index_id = fn('obx_model_last_index_id', None, [
279+
OBX_model_p, obx_schema_id, obx_uid])
274280

275281
# obx_err (OBX_model* model, obx_schema_id relation_id, obx_uid relation_uid);
276-
obx_model_last_relation_id = fn('obx_model_last_relation_id', None, [OBX_model_p, obx_schema_id, obx_uid])
282+
obx_model_last_relation_id = fn('obx_model_last_relation_id', None, [
283+
OBX_model_p, obx_schema_id, obx_uid])
277284

278285
# obx_err (OBX_model* model, obx_schema_id property_id, obx_uid property_uid);
279286
obx_model_entity_last_property_id = fn('obx_model_entity_last_property_id', obx_err,
@@ -283,19 +290,24 @@ def c_voidp_as_bytes(voidp, size):
283290
obx_opt = fn('obx_opt', OBX_store_options_p, [])
284291

285292
# obx_err (OBX_store_options* opt, const char* dir);
286-
obx_opt_directory = fn('obx_opt_directory', obx_err, [OBX_store_options_p, ctypes.c_char_p])
293+
obx_opt_directory = fn('obx_opt_directory', obx_err, [
294+
OBX_store_options_p, ctypes.c_char_p])
287295

288296
# void (OBX_store_options* opt, size_t size_in_kb);
289-
obx_opt_max_db_size_in_kb = fn('obx_opt_max_db_size_in_kb', None, [OBX_store_options_p, ctypes.c_size_t])
297+
obx_opt_max_db_size_in_kb = fn('obx_opt_max_db_size_in_kb', None, [
298+
OBX_store_options_p, ctypes.c_size_t])
290299

291300
# void (OBX_store_options* opt, int file_mode);
292-
obx_opt_file_mode = fn('obx_opt_file_mode', None, [OBX_store_options_p, ctypes.c_uint])
301+
obx_opt_file_mode = fn('obx_opt_file_mode', None, [
302+
OBX_store_options_p, ctypes.c_uint])
293303

294304
# void (OBX_store_options* opt, int max_readers);
295-
obx_opt_max_readers = fn('obx_opt_max_readers', None, [OBX_store_options_p, ctypes.c_uint])
305+
obx_opt_max_readers = fn('obx_opt_max_readers', None, [
306+
OBX_store_options_p, ctypes.c_uint])
296307

297308
# obx_err (OBX_store_options* opt, OBX_model* model);
298-
obx_opt_model = fn('obx_opt_model', obx_err, [OBX_store_options_p, OBX_model_p])
309+
obx_opt_model = fn('obx_opt_model', obx_err, [
310+
OBX_store_options_p, OBX_model_p])
299311

300312
# void (OBX_store_options* opt);
301313
obx_opt_free = fn('obx_opt_free', None, [OBX_store_options_p])
@@ -335,25 +347,31 @@ def c_voidp_as_bytes(voidp, size):
335347
obx_box_id_for_put = fn('obx_box_id_for_put', obx_id, [OBX_box_p, obx_id])
336348

337349
# obx_err (OBX_box* box, uint64_t count, obx_id* out_first_id);
338-
obx_box_ids_for_put = fn('obx_box_ids_for_put', obx_err, [OBX_box_p, ctypes.c_uint64, ctypes.POINTER(obx_id)])
350+
obx_box_ids_for_put = fn('obx_box_ids_for_put', obx_err, [
351+
OBX_box_p, ctypes.c_uint64, ctypes.POINTER(obx_id)])
339352

340353
# obx_err (OBX_box* box, obx_id id, const void* data, size_t size);
341-
obx_box_put = fn('obx_box_put', obx_err, [OBX_box_p, obx_id, ctypes.c_void_p, ctypes.c_size_t])
354+
obx_box_put = fn('obx_box_put', obx_err, [
355+
OBX_box_p, obx_id, ctypes.c_void_p, ctypes.c_size_t])
342356

343357
# obx_err (OBX_box* box, const OBX_bytes_array* objects, const obx_id* ids, OBXPutMode mode);
344-
obx_box_put_many = fn('obx_box_put_many', obx_err, [OBX_box_p, OBX_bytes_array_p, ctypes.POINTER(obx_id), OBXPutMode])
358+
obx_box_put_many = fn('obx_box_put_many', obx_err, [
359+
OBX_box_p, OBX_bytes_array_p, ctypes.POINTER(obx_id), OBXPutMode])
345360

346361
# obx_err (OBX_box* box, obx_id id);
347362
obx_box_remove = fn('obx_box_remove', obx_err, [OBX_box_p, obx_id])
348363

349364
# obx_err (OBX_box* box, uint64_t* out_count);
350-
obx_box_remove_all = fn('obx_box_remove_all', obx_err, [OBX_box_p, ctypes.POINTER(ctypes.c_uint64)])
365+
obx_box_remove_all = fn('obx_box_remove_all', obx_err, [
366+
OBX_box_p, ctypes.POINTER(ctypes.c_uint64)])
351367

352368
# obx_err (OBX_box* box, bool* out_is_empty);
353-
obx_box_is_empty = fn('obx_box_is_empty', obx_err, [OBX_box_p, ctypes.POINTER(ctypes.c_bool)])
369+
obx_box_is_empty = fn('obx_box_is_empty', obx_err, [
370+
OBX_box_p, ctypes.POINTER(ctypes.c_bool)])
354371

355372
# obx_err obx_box_count(OBX_box* box, uint64_t limit, uint64_t* out_count);
356-
obx_box_count = fn('obx_box_count', obx_err, [OBX_box_p, ctypes.c_uint64, ctypes.POINTER(ctypes.c_uint64)])
373+
obx_box_count = fn('obx_box_count', obx_err, [
374+
OBX_box_p, ctypes.c_uint64, ctypes.POINTER(ctypes.c_uint64)])
357375

358376
# OBX_bytes_array* (size_t count);
359377
obx_bytes_array = fn('obx_bytes_array', OBX_bytes_array_p, [ctypes.c_size_t])

objectbox/model/entity.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ class _Entity(object):
2323
def __init__(self, cls, id: int, uid: int):
2424
# currently, ID and UID are mandatory and are not fetched from the model.json
2525
if id <= 0:
26-
raise Exception("invalid or no 'id; given in the @Entity annotation")
26+
raise Exception(
27+
"invalid or no 'id; given in the @Entity annotation")
2728

2829
if uid <= 0:
29-
raise Exception("invalid or no 'uid' given in the @Entity annotation")
30+
raise Exception(
31+
"invalid or no 'uid' given in the @Entity annotation")
3032

3133
self.cls = cls
3234
self.name = cls.__name__
@@ -48,15 +50,17 @@ def fill_properties(self):
4850
variables = dict(vars(self.cls))
4951

5052
# filter only subclasses of Property
51-
variables = {k: v for k, v in variables.items() if issubclass(type(v), Property)}
53+
variables = {k: v for k, v in variables.items(
54+
) if issubclass(type(v), Property)}
5255

5356
for k, prop in variables.items():
5457
prop._name = k
5558
self.properties.append(prop)
5659

5760
if prop._is_id:
5861
if self.id_property:
59-
raise Exception("duplicate ID property: '%s' and '%s'" % (self.id_property._name, prop._name))
62+
raise Exception("duplicate ID property: '%s' and '%s'" % (
63+
self.id_property._name, prop._name))
6064
self.id_property = prop
6165

6266
if prop._fb_type == flatbuffers.number_types.UOffsetTFlags:
@@ -106,7 +110,8 @@ def marshal(self, object, id: int) -> bytearray:
106110
if val:
107111
builder.PrependUOffsetTRelative(val)
108112
else:
109-
val = id if prop == self.id_property else self.get_value(object, prop)
113+
val = id if prop == self.id_property else self.get_value(
114+
object, prop)
110115
builder.Prepend(prop._fb_type, val)
111116

112117
builder.Slot(prop._fb_slot)

objectbox/model/model.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,28 @@ def entity(self, entity: _Entity, last_property_id: IdUid):
4343

4444
entity.last_property_id = last_property_id
4545

46-
obx_model_entity(self._c_model, c_str(entity.name), entity.id, entity.uid)
46+
obx_model_entity(self._c_model, c_str(
47+
entity.name), entity.id, entity.uid)
4748

4849
for v in entity.properties:
49-
obx_model_property(self._c_model, c_str(v._name), v._ob_type, v._id, v._uid)
50+
obx_model_property(self._c_model, c_str(
51+
v._name), v._ob_type, v._id, v._uid)
5052
if v._flags != 0:
5153
obx_model_property_flags(self._c_model, v._flags)
5254

53-
obx_model_entity_last_property_id(self._c_model, last_property_id.id, last_property_id.uid)
55+
obx_model_entity_last_property_id(
56+
self._c_model, last_property_id.id, last_property_id.uid)
5457

5558
# called by Builder
5659
def _finish(self):
5760
if self.last_relation_id:
58-
obx_model_last_relation_id(self._c_model, self.last_relation_id.id, self.last_relation_id.uid)
61+
obx_model_last_relation_id(
62+
self._c_model, self.last_relation_id.id, self.last_relation_id.uid)
5963

6064
if self.last_index_id:
61-
obx_model_last_index_id(self._c_model, self.last_index_id.id, self.last_index_id.uid)
65+
obx_model_last_index_id(
66+
self._c_model, self.last_index_id.id, self.last_index_id.uid)
6267

6368
if self.last_entity_id:
64-
obx_model_last_entity_id(self._c_model, self.last_entity_id.id, self.last_entity_id.uid)
69+
obx_model_last_entity_id(
70+
self._c_model, self.last_entity_id.id, self.last_entity_id.uid)

objectbox/objectbox.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from objectbox.c import *
1717
import objectbox.transaction
1818

19+
1920
class ObjectBox:
2021
def __init__(self, c_store: OBX_store_p):
2122
self._c_store = c_store
@@ -28,4 +29,3 @@ def read_tx(self):
2829

2930
def write_tx(self):
3031
return objectbox.transaction.write(self)
31-

0 commit comments

Comments
 (0)