Skip to content

0.9.0

Latest

Choose a tag to compare

@github-actions github-actions released this 24 Nov 01:24
a5a0884

Release notes for pymetadata 0.9.0

pymetadata

Changes

  • pymetadata.omex reads and writes COMBINE archives through pymetadata-core, which is now a dependency of pymetadata with a floor of 0.4.0 (#99). There is no pure-python fallback. The public API of Omex, Manifest and ManifestEntry is unchanged.

  • pymetadata is therefore no longer pure python. pymetadata-core is a Rust extension and ships one abi3 wheel per platform, which every CPython from 3.11 on installs: manylinux2014_x86_64 and manylinux2014_aarch64 (linux with glibc), macosx_10_12_x86_64, macosx_11_0_arm64 and win_amd64. On every other platform, e.g. musl based linux (Alpine), linux on armv7, ppc64le or s390x, FreeBSD, 32 bit or ARM Windows, or an implementation other than CPython such as PyPy, pip install pymetadata falls back to the source distribution of the core and compiles it, which needs a Rust toolchain, i.e. cargo; without one the build fails, while pymetadata-core is built rather than while pymetadata is installed. See Installation.

  • Reading is lazy. Omex.from_omex no longer extracts the archive into a temporary directory, Omex.get_path extracts a member when something asks for it. Opening still reads the central directory and the manifest.xml, and reads the first bytes of an unlisted .xml member to classify its format, without inflating the rest of it.

  • A member which nobody touched is copied compressed when the archive is written, without being inflated and compressed again. Its compression method, compressed size and CRC are preserved exactly.

  • The effect, in ms: reading with Omex.from_omex, writing with Omex.to_omex without a change. Median of 15 runs after one uncounted warm-up run. Both columns were taken with scripts/omex_timing.py --runs 15, one after the other on the same machine, the before column on a worktree of the previous release (c42df44), so the two are comparable and you can reproduce them:

    archive size (KiB) entries read before read after write before write after
    BIOMD0000000001.omex 277 16 2.50 0.24 11.56 0.23
    CombineArchiveShowCase.omex 1073 22 6.08 0.74 44.37 0.44
    CompModels.omex 6 6 0.72 0.10 0.48 0.10
    iCGB21FR.omex 1375 23 18.24 1.07 226.68 0.49
  • Reading reads the whole file: the bytes of the archive and the container the core keeps from them. Writing streams into the file, see the entry on Omex.to_omex below.

  • Omex.to_directory writes each member once, straight to its destination. An entry whose file is missing raises a FileNotFoundError which names that file and sets its filename, on every platform: on windows shutil.copy2, which wrote every member before, copies through the CopyFile2 API, whose error names no file at all ([WinError 2] The system cannot find the file specified).

  • One Omex can still be used from several threads. The core gives access to one archive to one thread at a time and refuses a second one, so the calls which reach it, Omex.get_path, Omex.to_omex and Omex.to_directory, are serialized with a lock of the instance. Extracting the members of one archive from a thread pool therefore keeps working, as it did when from_omex extracted everything up front, but the extractions happen one after the other: threads do not make reading one archive faster. Two Omex instances are independent of each other. An Archive of the core which is shared outside of Omex raises pymetadata.omex.ConcurrentUseError, a RuntimeError, instead of the ArchiveBusyError of the binding. Changing the manifest of one Omex from several threads at the same time is not supported.

Behaviour which changed

  • A wrong or missing password raises a ValueError where zipfile raised a RuntimeError. The exception is PasswordError, which pymetadata.omex exports beside ConcurrentUseError: code which catches ValueError keeps working, and code which tells a protected archive from a container which is no archive catches PasswordError.
  • A member with an unsupported compression method, or one which inflates beyond the 1 GiB cap of the core, is refused when its bytes are read, i.e., at Omex.get_path, and no longer when the archive is opened. A member with an unsupported method which the manifest does not list gets its format guessed from its suffix alone; one over the inflate cap is classified from its first bytes, which are read without inflating the rest.
  • A member whose name points outside of the archive, or is absolute, is refused when the archive is opened with a ValueError. zipfile sanitized such a name and read the member, this is deliberate hardening. Omex.is_omex still answers True for such a file, because it asks about the structure of the archive.
  • The manifest.xml of a written archive is serialized by the core: there is no master="false" attribute and the XML declaration is single quoted. The content is the same, the bytes are not.
  • A member which pymetadata writes anew, e.g., an added file or the manifest.xml, carries the zip epoch 1980-01-01 00:00:00 as its modification time, where the previous writer used the time of the write. A member which is copied keeps the date it had in the source archive. The upside is that a written archive is reproducible: identical content gives identical bytes. The core offers no way to set a timestamp in 0.4.0.
  • A member which is copied is not inflated, so a member with a compression method the core cannot inflate, such as bzip2, survives a write unchanged (it stays bzip2), although its bytes are refused when read. Such a member makes a write at a non-default compresslevel, or with a compression other than ZIP_DEFLATED, fail with a ValueError, because those writes inflate every member.
  • A write applies the removals of the manifest to the archive the Omex was read from, so Omex.to_omex is not free of side effects. An entry which was removed from manifest loses its content in that Omex when the archive is written: declaring the location again afterwards and writing a second time fails with a FileNotFoundError, where the previous writer wrote the member again, because it still had every member as a file in the temporary directory. A write which repeats the same entries writes the same bytes again, and a removal before the first write is unaffected.
  • Omex.is_omex is answered by the core, which reads the end of the file and its central directory and no member at all. The names of the container are normalized before the manifest is looked for, so a container whose manifest member is stored as ./manifest.xml instead of manifest.xml is an archive. A file which is no COMBINE archive is logged with one warning naming the missing manifest, where the previous release logged a different one for a file which is no zip. from_omex reads such a container, where the previous release refused it, because from_omex was gated on is_omex.
  • A location which a manifest declares twice is written once, the last entry winning, instead of producing two members of the same name.
  • Omex.to_omex writes the archive through the core into a temporary file next to the target and moves it over the target, so the archive is never held in memory as a whole and the target is either the new archive or untouched. Reading still holds the container: for a 268.5 MB archive the peak of a read and write is 553.5 MB, where 0.8.3 peaked at 37.3 MB because it extracted to a temporary directory and streamed the members from there. A write which cannot be carried out, e.g. a full disk, raises an OSError and leaves the target alone.
  • compression=zipfile.ZIP_STORED is written as deflate at level 0, with a warning, because the core has no stored path. Any other compression than ZIP_DEFLATED also deflates every member again, which gives up the copy of untouched members and its speed.
  • compresslevel keeps its meaning, and -1 is accepted as the default level (9), as with zipfile. A compresslevel outside of 0 to 9 raises a ValueError as before, with a different message.
  • A member which the core deflates, e.g., an added file, the manifest.xml, or any member of a write at a non-default compresslevel, has different bytes than before, because the deflate of the core is not the one of CPython's zlib. The content is identical. A member whose format or master flag changed is not one of them: those live in the manifest, so the member is copied as the blob it is.
  • When an archive is read with from_omex, one warning moved to the logger pymetadata._core_bridge from pymetadata.omex: Entry with location missing in manifest.xml, for a member the manifest does not list (from_directory still logs it under pymetadata.omex). Two are new, both from that logger: a manifest entry which no member of the archive provides is warned about, where it used to be dropped silently (it is still dropped), and an unlisted .xml member whose bytes cannot be read gets its format guessed from its suffix with a warning. The warning about a member which is neither stored nor deflated stays in pymetadata.omex and names the member as the core normalizes it, e.g. ./b.txt instead of b.txt.
  • The message for a file which is not a COMBINE archive changed to Not an OMEX archive, no readable manifest.xml: malformed ...: '<path>'., still a ValueError. Code which matches on the old text needs to be adapted.

Your pymetadata team