Skip to content

Commit f246b4b

Browse files
author
Mytlogos
committed
format according to autopep8
1 parent 00d5e0b commit f246b4b

File tree

5 files changed

+69
-36
lines changed

5 files changed

+69
-36
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 & 21 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):
@@ -257,23 +260,28 @@ def c_voidp_as_bytes(voidp, size):
257260
obx_model = fn('obx_model', OBX_model_p, [])
258261

259262
# 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])
263+
obx_model_entity = fn('obx_model_entity', obx_err, [
264+
OBX_model_p, ctypes.c_char_p, obx_schema_id, obx_uid])
261265

262266
# obx_err (OBX_model* model, const char* name, OBXPropertyType type, obx_schema_id property_id, obx_uid property_uid);
263267
obx_model_property = fn('obx_model_property', obx_err,
264268
[OBX_model_p, ctypes.c_char_p, OBXPropertyType, obx_schema_id, obx_uid])
265269

266270
# obx_err (OBX_model* model, OBXPropertyFlags flags);
267-
obx_model_property_flags = fn('obx_model_property_flags', obx_err, [OBX_model_p, OBXPropertyFlags])
271+
obx_model_property_flags = fn('obx_model_property_flags', obx_err, [
272+
OBX_model_p, OBXPropertyFlags])
268273

269274
# 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])
275+
obx_model_last_entity_id = fn('obx_model_last_entity_id', None, [
276+
OBX_model_p, obx_schema_id, obx_uid])
271277

272278
# 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])
279+
obx_model_last_index_id = fn('obx_model_last_index_id', None, [
280+
OBX_model_p, obx_schema_id, obx_uid])
274281

275282
# 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])
283+
obx_model_last_relation_id = fn('obx_model_last_relation_id', None, [
284+
OBX_model_p, obx_schema_id, obx_uid])
277285

278286
# obx_err (OBX_model* model, obx_schema_id property_id, obx_uid property_uid);
279287
obx_model_entity_last_property_id = fn('obx_model_entity_last_property_id', obx_err,
@@ -283,19 +291,24 @@ def c_voidp_as_bytes(voidp, size):
283291
obx_opt = fn('obx_opt', OBX_store_options_p, [])
284292

285293
# 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])
294+
obx_opt_directory = fn('obx_opt_directory', obx_err, [
295+
OBX_store_options_p, ctypes.c_char_p])
287296

288297
# 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])
298+
obx_opt_max_db_size_in_kb = fn('obx_opt_max_db_size_in_kb', None, [
299+
OBX_store_options_p, ctypes.c_size_t])
290300

291301
# 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])
302+
obx_opt_file_mode = fn('obx_opt_file_mode', None, [
303+
OBX_store_options_p, ctypes.c_uint])
293304

294305
# 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])
306+
obx_opt_max_readers = fn('obx_opt_max_readers', None, [
307+
OBX_store_options_p, ctypes.c_uint])
296308

297309
# 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])
310+
obx_opt_model = fn('obx_opt_model', obx_err, [
311+
OBX_store_options_p, OBX_model_p])
299312

300313
# void (OBX_store_options* opt);
301314
obx_opt_free = fn('obx_opt_free', None, [OBX_store_options_p])
@@ -335,25 +348,31 @@ def c_voidp_as_bytes(voidp, size):
335348
obx_box_id_for_put = fn('obx_box_id_for_put', obx_id, [OBX_box_p, obx_id])
336349

337350
# 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)])
351+
obx_box_ids_for_put = fn('obx_box_ids_for_put', obx_err, [
352+
OBX_box_p, ctypes.c_uint64, ctypes.POINTER(obx_id)])
339353

340354
# 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])
355+
obx_box_put = fn('obx_box_put', obx_err, [
356+
OBX_box_p, obx_id, ctypes.c_void_p, ctypes.c_size_t])
342357

343358
# 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])
359+
obx_box_put_many = fn('obx_box_put_many', obx_err, [
360+
OBX_box_p, OBX_bytes_array_p, ctypes.POINTER(obx_id), OBXPutMode])
345361

346362
# obx_err (OBX_box* box, obx_id id);
347363
obx_box_remove = fn('obx_box_remove', obx_err, [OBX_box_p, obx_id])
348364

349365
# 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)])
366+
obx_box_remove_all = fn('obx_box_remove_all', obx_err, [
367+
OBX_box_p, ctypes.POINTER(ctypes.c_uint64)])
351368

352369
# 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)])
370+
obx_box_is_empty = fn('obx_box_is_empty', obx_err, [
371+
OBX_box_p, ctypes.POINTER(ctypes.c_bool)])
354372

355373
# 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)])
374+
obx_box_count = fn('obx_box_count', obx_err, [
375+
OBX_box_p, ctypes.c_uint64, ctypes.POINTER(ctypes.c_uint64)])
357376

358377
# OBX_bytes_array* (size_t count);
359378
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)