You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: INSTALL.rst
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,7 +21,7 @@ Use installed libexiv2
21
21
22
22
In the example above, pip_ installs a "binary wheel_".
23
23
This is pre-compiled and includes a copy of the libexiv2_ library, which makes installation quick and easy.
24
-
Wheels for `python-exiv2`_ are available for Windows, Linux, and MacOS with Python versions from 3.6 to 3.12.
24
+
Wheels for `python-exiv2`_ are available for Windows, Linux, and MacOS with Python versions from 3.6 to 3.13.
25
25
26
26
If your computer already has libexiv2_ installed (typically by your operating system's "package manager") then pip_ might be able to compile `python-exiv2`_ to use it.
27
27
First you need to check what version of python-exiv2 you have::
Copy file name to clipboardExpand all lines: README.rst
+12-7Lines changed: 12 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
python-exiv2 v\ 0.17.3
1
+
python-exiv2 v\ 0.18.0
2
2
======================
3
3
4
4
python-exiv2 is a low level interface (or binding) to the exiv2_ C++ library.
@@ -47,15 +47,17 @@ Please see `USAGE.rst`_ for more help with using the Python interface to libexiv
47
47
Transition to libexiv2 v0.28.x
48
48
------------------------------
49
49
50
-
Before python-exiv2 v0.16 the "binary wheels" available from PyPI_ incorporated libexiv2 v0.27.7 or earlier.
51
-
Binary wheels for python-exiv2 v0.16.3 incorporate libexiv2 v0.28.2, and those for python-exiv2 v0.16.2 incorporate libexiv2 v0.27.7.
52
-
Binary wheels for python-exiv2 v0.17.0 incorporate libexiv2 v0.28.3.
53
-
If your software is currently incompatible with libexiv2 v0.28.x you can use the older version of libexiv2 by explicitly installing python-exiv2 v0.16.2::
50
+
Since python-exiv2 v0.16.3 the "binary wheels" available from PyPI_ incorporate libexiv2 v0.28.2 or later.
51
+
If your software is currently incompatible with libexiv2 v0.28.x you can use an older version of libexiv2 by explicitly installing python-exiv2 v0.16.2::
Alternatively, if you have libexiv2 v0.27.x and its "development headers" installed on your computer, you can install python-exiv2 from source using your system libexiv2::
56
+
57
+
$ pip install --user exiv2 --no-binary :all:
56
58
57
59
There are some changes in the libexiv2 API between v0.27.7 and v0.28.x.
58
-
Future versions of python-exiv2 will all incorporate libexiv2 v0.28.x, so please update your software to use the changed API.
60
+
Eventually python-exiv2 will no longer support libexiv2 v0.27.x, so please update your software to use the changed API.
59
61
60
62
Documentation
61
63
-------------
@@ -97,6 +99,7 @@ Installation
97
99
98
100
Python "binary wheels" are available for Windows, Linux, and MacOS.
99
101
These include the libexiv2 library and should not need any other software to be installed.
102
+
(Although on Windows you might need to update your `MSVC redistributable`_.)
100
103
They can be installed with Python's pip_ package.
101
104
For example, on Windows::
102
105
@@ -119,6 +122,8 @@ Please email [email protected] if you find any problems (or solutions!).
Copy file name to clipboardExpand all lines: USAGE.rst
+53-90Lines changed: 53 additions & 90 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,7 @@ libexiv2 library version
13
13
------------------------
14
14
15
15
Python-exiv2 can be used with any version of libexiv2 from 0.27.0 onwards.
16
-
The "binary wheels" available from PyPI_ currently include a copy of libexiv2 v0.27.7, but if you install from source then python-exiv2 will use whichever version of libexiv2 is installed on your computer.
16
+
The "binary wheels" available from PyPI_ currently include a copy of libexiv2 v0.28.5, but if you install from source then python-exiv2 will use whichever version of libexiv2 is installed on your computer.
17
17
18
18
There are some differences in the API of libexiv2 v0.28.x and v0.27.y.
19
19
Some of these have been "backported" in the Python interface so you can start using the v0.28 methods, e.g. the ``exiv2.DataBuf.data()`` function replaces the ``exiv2.DataBuf.pData_`` attribute.
@@ -51,27 +51,20 @@ Some parts of the interface are deprecated and will eventually be removed.
51
51
Please use Python's ``-Wd`` flag when testing your software to ensure it isn't using deprecated features.
52
52
(Do let me know if I've deprecated a feature you need and can't replace with an alternative.)
53
53
54
-
Enums
55
-
-----
56
-
57
-
The C++ libexiv2 library often uses ``enum`` classes to list related data, such as the value type identifiers stored in `Exiv2::TypeId`_.
58
-
SWIG's default processing of such enums is to add all the values as named constants to the top level of the module, e.g. ``exiv2.asciiString``.
59
-
In python-exiv2 most of the C++ enums are represented by Python enum_ classes, e.g. ``exiv2.TypeId.asciiString`` is a member of ``exiv2.TypeId``.
60
-
61
-
Unfortunately there is no easy way to deprecate the SWIG generated top level constants, but they will eventually be removed from python-exiv2.
62
-
Please ensure you only use the enum classes in your use of python-exiv2.
63
-
64
54
Data structures
65
55
---------------
66
56
67
57
Some parts of the Exiv2 API use structures to hold several related data items.
68
58
For example, the `Exiv2::ExifTags`_ class has a ``tagList()`` method that returns a list of `Exiv2::TagInfo`_ structs.
69
-
In python-exiv2 (since v0.16.2) these structs have dict_ like behaviour, so the members can be accessed more easily:
59
+
Since python-exiv2 v0.18.0 struct member names ending with an underscore ``_`` have aliases without the underscore.
60
+
Since v0.16.2 these structs also have dict_ like behaviour, so the members can be accessed more easily:
70
61
71
62
.. code:: python
72
63
73
64
>>>import exiv2
74
65
>>> info = exiv2.ExifTags.tagList('Image')[0]
66
+
>>>print(info.title)
67
+
Processing Software
75
68
>>>print(info.title_)
76
69
Processing Software
77
70
>>>print(info['title'])
@@ -90,7 +83,8 @@ In python-exiv2 (since v0.16.2) these structs have dict_ like behaviour, so the
90
83
'title': 'Processing Software',
91
84
'typeId': <TypeId.asciiString: 2>}
92
85
93
-
Note that struct member names ending with an underscore have the underscore removed in the dict_ like interface.
86
+
In general it's more efficient to use attribute access (``info.title``) than dict_ access (``info['title']``).
87
+
It is sometimes useful to be able to iterate over the members though, as shown above.
94
88
95
89
Reading data values
96
90
-------------------
@@ -107,7 +101,7 @@ The Python interface uses the value's ``typeId()`` method to determine its type
107
101
Recasting data values
108
102
^^^^^^^^^^^^^^^^^^^^^
109
103
110
-
In earlier versions of python-gphoto2 you could set the type of value returned by ``value()`` or ``getValue()`` by passing an ``exiv2.TypeId`` parameter:
104
+
In old versions of python-gphoto2 you could set the type of value returned by ``value()`` or ``getValue()`` by passing an ``exiv2.TypeId`` parameter:
111
105
112
106
.. code:: python
113
107
@@ -231,14 +225,16 @@ If you don't want to use the data numerically then you can just use strings for
The ``Exiv2::ExifData``, ``Exiv2::IptcData``, and ``Exiv2::XmpData`` classes use C++ iterators to expose private data, for example the ``ExifData`` class has a private member of ``std::list<Exifdatum>`` type.
238
232
The classes have public ``begin()``, ``end()``, and ``findKey()`` methods that return ``std::list`` iterators.
239
-
In C++ you can dereference one of these iterators to access the ``Exifdatum`` object, but Python doesn't have a dereference operator.
233
+
They also have ``[key]`` operators that return a pointer to an ``Exifdatum`` object.
234
+
235
+
In C++ you can dereference one of these pointers to access the ``Exifdatum`` object, but Python doesn't have a dereference operator.
240
236
241
-
This Python interface converts the ``std::list`` iterator to a Python object that has access to all the ``Exifdatum`` object's methods without dereferencing.
237
+
In python-exiv2 the iterators (and references since v0.18.0) are wrapped in a Python object that has access to all the ``Exifdatum`` object's methods without dereferencing.
242
238
For example:
243
239
244
240
.. code:: python
@@ -311,29 +307,11 @@ This allows them to be used in a very Pythonic style:
311
307
Warning: segmentation faults
312
308
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
313
309
314
-
If an iterator is invalidated, e.g. by deleting the datum it points to, then your Python program may crash with a segmentation fault if you try to use the invalid iterator.
315
-
Just as in C++, there is no way to detect that an iterator has become invalid.
316
-
317
-
Segmentation faults
318
-
-------------------
319
-
320
-
There are many places in the libexiv2 C++ API where objects hold references to data in other objects.
321
-
This is more efficient than copying the data, but can cause segmentation faults if an object is deleted while another objects refers to its data.
322
-
323
-
The Python interface tries to protect the user from this but in some cases this is not possible.
324
-
For example, an `Exiv2::Metadatum`_ object holds a reference to data that can easily be invalidated:
310
+
If a pointer is invalidated, e.g. by deleting the datum it points to, then your Python program may crash with a segmentation fault if you try to use the invalid pointer.
311
+
Just as in C++, there is no way to detect that a pointer has become invalid.
325
312
326
-
.. code:: python
327
-
328
-
exifData = image.exifData()
329
-
datum = exifData['Exif.GPSInfo.GPSLatitude']
330
-
print(str(datum.value())) # no problem
331
-
del exifData['Exif.GPSInfo.GPSLatitude']
332
-
print(str(datum.value())) # segfault!
333
-
334
-
Segmentation faults are also easily caused by careless use of iterators or memory blocks, as discussed below.
335
-
There may be other cases where the Python interface doesn't prevent segfaults.
336
-
Please let me know if you find any.
313
+
Since v0.18.0 python-exiv2 (if built with swig >= 4.4) tries to invalidate pointers if the data they point to is deleted.
314
+
Please let me know if you encounter any problems with segmentation faults.
337
315
338
316
Binary data input
339
317
-----------------
@@ -366,23 +344,36 @@ In some cases this includes writing to the data.
366
344
buf = thumb.copy()
367
345
thumb_im =PIL.Image.open(io.BytesIO(buf.data()))
368
346
369
-
In python-exiv2 before v0.15.0 the memory block is converted to an object with a buffer interface.
370
-
A Python memoryview_ can be used to access the data without copying.
371
-
(Converting to bytes_ would make a copy of the data, which we don't usually want.)
347
+
Since version 0.18.0 python-exiv2 releases the memoryview_ if the memory is invalidated (e.g. if the memory block is resized) to prevent problems such as segmentation faults:
372
348
373
-
Warning: segmentation faults
374
-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
349
+
.. code:: python
350
+
351
+
>>> buf = exiv2.DataBuf(b'fred')
352
+
>>> data = buf.data()
353
+
>>>print(bytes(data))
354
+
b'fred'
355
+
>>> buf.resize(128)
356
+
>>>print(bytes(data))
357
+
Traceback (most recent call last):
358
+
File "<stdin>", line 1, in<module>
359
+
ValueError: operation forbidden on released memoryviewobject
360
+
>>>
375
361
376
-
Note that the memory block must not be deleted or resized while the memoryview exists.
377
-
Doing so will invalidate the memoryview and may cause a segmentation fault:
362
+
Although memoryview_ objects can be used in a with_ statement this has no benefit with python-exiv2.
363
+
The memory view's ``release`` method does nothing.
364
+
Releasing any associated resources only happens when the memory view is deleted:
378
365
379
366
.. code:: python
380
367
381
-
buf = exiv2.DataBuf(b'fred')
382
-
data = buf.data()
383
-
print(bytes(data)) # Prints b'fred'
384
-
buf.alloc(128)
385
-
print(bytes(data)) # Prints random values, may segfault
368
+
with buf.data() as data:
369
+
file.write(data)
370
+
del data
371
+
372
+
is equivalent to
373
+
374
+
.. code:: python
375
+
376
+
file.write(buf.data())
386
377
387
378
Buffer interface
388
379
----------------
@@ -398,6 +389,8 @@ For example, you could save a photograph's thumbnail in a separate file like thi
398
389
withopen('thumbnail.jpg', 'wb') as out_file:
399
390
out_file.write(thumb.copy())
400
391
392
+
Use of this buffer interface is deprecated (since python-exiv2 v0.18.0) and the ``data()`` methods described above should be used instead.
393
+
401
394
Image data in memory
402
395
--------------------
403
396
@@ -408,51 +401,19 @@ The buffered data isn't actually read until ``Image::readMetadata`` is called, s
408
401
When ``Image::writeMetadata`` is called exiv2 allocates a new block of memory to store the modified data.
409
402
The ``Image::io`` method returns an `Exiv2::BasicIo`_ object that provides access to this data.
410
403
411
-
The ``BasicIo::mmap`` method allows access to the image file data without unnecessary copying.
412
-
However it is rather error prone, crashing your Python program with a segmentation fault if anything goes wrong.
404
+
The ``BasicIo::mmap`` and ``BasicIo::munmap`` methods allow access to the image file data without unnecessary copying.
405
+
However they are rather error prone, crashing your Python program with a segmentation fault if anything goes wrong.
413
406
414
-
The ``Exiv2::BasicIo`` object must be opened before calling ``mmap()``.
415
-
A Python `context manager`_ can be used to ensure that the ``open()`` and ``mmap()`` calls are paired with ``munmap()`` and ``close()`` calls:
407
+
Since python-exiv2 v0.18.0 it is much easier to use the image's ``data()`` method:
0 commit comments