Skip to content

Commit 2734adb

Browse files
author
Ivan Dlugos
committed
load setup.py package version from objectbox package
1 parent 6970cbb commit 2734adb

5 files changed

Lines changed: 28 additions & 28 deletions

File tree

objectbox/__init__.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,22 @@
22
from objectbox.builder import Builder
33
from objectbox.model import Model
44
from objectbox.objectbox import ObjectBox
5-
from objectbox.c import NotFoundException
5+
from objectbox.c import NotFoundException, version_core
6+
from objectbox.version import Version
67

78
__all__ = [
89
'Box',
910
'Builder',
1011
'Model',
1112
'ObjectBox',
1213
'NotFoundException',
14+
'version',
15+
'version_info',
1316
]
17+
18+
# Python binding version
19+
version = Version(0, 1, 0, "dev")
20+
21+
22+
def version_info():
23+
return "ObjectBox Python version " + str(version) + " using dynamic library version " + str(version_core)

objectbox/c.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import ctypes.util
22
import os
33
import platform
4+
from objectbox.version import Version
5+
46

57
# This file contains C-API bindings based on the objectbox.h, linking to the 'objectbox' shared library
68

@@ -22,9 +24,18 @@ def shlib_name(library: str) -> str:
2224
lib_path = os.path.join(lib_path, 'lib', platform.machine(), shlib_name('objectbox'))
2325
C = ctypes.CDLL(lib_path)
2426

25-
assert C.obx_version_is_at_least(0, 5, 103) == 1, \
26-
"ObjectBox v0.5.103+ is not installed. " \
27-
"Please upgrade/install by following the instructions at https://github.com/objectbox/objectbox-c"
27+
# load the core library version
28+
__major = ctypes.c_int(0)
29+
__minor = ctypes.c_int(0)
30+
__patch = ctypes.c_int(0)
31+
C.obx_version(ctypes.byref(__major), ctypes.byref(__minor), ctypes.byref(__patch))
32+
33+
# C-api (core library) version
34+
version_core = Version(__major.value, __minor.value, __patch.value)
35+
36+
required_version = "0.5.103"
37+
assert str(version_core) == required_version, \
38+
"Incorrect ObjectBox version loaded: %s instead of expected %s " % (str(version_core), required_version)
2839

2940
# define some basic types
3041
obx_err = ctypes.c_int

objectbox/version.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
import ctypes
2-
from objectbox.c import C
3-
4-
51
class Version:
62
def __init__(self, major: int, minor: int, patch: int, label: str = ""):
73
self.major = major
@@ -14,20 +10,3 @@ def __str__(self):
1410
if len(self.label) > 0:
1511
result += "-" + self.label
1612
return result
17-
18-
19-
# Python binding version
20-
version_python = Version(0, 0, 0, "dev")
21-
22-
# load the core library version
23-
__major = ctypes.c_int(0)
24-
__minor = ctypes.c_int(0)
25-
__patch = ctypes.c_int(0)
26-
C.obx_version(ctypes.byref(__major), ctypes.byref(__minor), ctypes.byref(__patch))
27-
28-
# C-api (core library) version
29-
version_library = Version(__major.value, __minor.value, __patch.value)
30-
31-
32-
def version_info():
33-
return "ObjectBox Python version " + str(version_python) + " using dynamic library version " + str(version_library)

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import setuptools
2+
import objectbox
23

34
with open("README.md", "r") as fh:
45
long_description = fh.read()
56

67
setuptools.setup(
78
name="objectbox",
8-
version="0.1.0",
9+
version=str(objectbox.version),
910
author="ObjectBox",
1011
description="ObjectBox is a superfast database for objects",
1112
long_description=long_description,

tests/test_basics.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import shutil
33
import pytest
44
import objectbox
5-
import objectbox.version
65
from tests.model import TestEntity
76

87
db_name = 'testdata'
@@ -21,7 +20,7 @@ def run_around_tests():
2120

2221

2322
def test_version():
24-
info = objectbox.version.version_info()
23+
info = objectbox.version_info()
2524
assert len(info) > 10
2625

2726

0 commit comments

Comments
 (0)