Skip to content
This repository was archived by the owner on Apr 23, 2022. It is now read-only.

Commit 91e56fd

Browse files
committed
add print_version method
1 parent b50e780 commit 91e56fd

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

tests/test_main.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ def test_different_compression():
5252
assert len(delta_a) < len(delta_b)
5353

5454

55+
def test_version():
56+
# can't easily test output as capsys doesn't capture output of print_version
57+
xdelta3.print_version()
58+
59+
5560
def test_readme():
5661
value_one = b'wonderful string to demonstrate xdelta3, much of these two strings is the same.'
5762
value_two = b'different string to demonstrate xdelta3, much of these two strings is the same.'

xdelta3/_xdelta3.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,16 @@ static PyObject * xdelta3_execute(PyObject *self, PyObject *args)
5656
return NULL;
5757
}
5858

59+
static PyObject * xdelta3_version(PyObject *self, PyObject *args)
60+
{
61+
int result = main_version();
62+
PyObject *ret = Py_BuildValue("i", result);
63+
return ret;
64+
}
65+
5966
static PyMethodDef xdelta3_methods[] = {
6067
{"execute", xdelta3_execute, METH_VARARGS, "xdelta3 encode or decode"},
68+
{"version", xdelta3_version, METH_VARARGS, "print xdelta3 version info"},
6169
{NULL, NULL, 0, NULL}
6270
};
6371

xdelta3/main.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1+
import sys
12
from enum import IntEnum
23

34
import _xdelta3
45
from _xdelta3 import NoDeltaFound, XDeltaError # noqa
56

7+
from .version import VERSION
8+
69
__all__ = [
710
'NoDeltaFound',
811
'XDeltaError',
912
'Flags',
1013
'encode',
1114
'decode',
15+
'print_version',
1216
]
1317

1418

@@ -85,7 +89,7 @@ def encode(original: bytes, new_value: bytes, flags: int=Flags.COMPLEVEL_9) -> b
8589
return _xdelta3.execute(new_value, original, flags, 0)
8690

8791

88-
def decode(original: bytes, delta: bytes, flags: int=Flags.COMPLEVEL_9):
92+
def decode(original: bytes, delta: bytes, flags: int=Flags.COMPLEVEL_9) -> bytes:
8993
"""
9094
Decode a delta to calculate a new value from the original and a delta.
9195
@@ -98,3 +102,12 @@ def decode(original: bytes, delta: bytes, flags: int=Flags.COMPLEVEL_9):
98102
:return: new byte string from applying delta to original
99103
"""
100104
return _xdelta3.execute(delta, original, flags, 1)
105+
106+
107+
def print_version():
108+
"""
109+
Print version info for xdelta3-python and the xdelta3 c library.
110+
"""
111+
print('xdelta3-python:', VERSION, file=sys.stderr)
112+
print('xdelta3-c library:', file=sys.stderr)
113+
_xdelta3.version()

0 commit comments

Comments
 (0)