From 01cbab33326a85760ec5aac320b2c9066b43cafd Mon Sep 17 00:00:00 2001 From: pyrco <105293448+pyrco@users.noreply.github.com> Date: Mon, 29 Jul 2024 09:59:14 +0200 Subject: [PATCH] Move the selection between the native and Python implementations of lzo and lz4 to dissect.util (#16) Co-authored-by: Jan Willem Brandenburg --- README.md | 12 +++++++++++- dissect/btrfs/stream.py | 6 +----- pyproject.toml | 8 +++++--- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 1a2f7b5..dbd8244 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,17 @@ Information on the supported Python versions can be found in the Getting Started pip install dissect.btrfs ``` -This module is also automatically installed if you install the `dissect` package. +This project decompresses lzo compressed file systems and can use the faster, native (C-based) lzo implementation when +installed, instead of the slower pure Python implementation provided by `dissect.util`. To use these faster +implementations, install the package with the lzo extra: + +```bash +pip install "dissect.btrfs[lzo]" +``` + +Unfortunately there is no binary `python-lzo` wheel for PyPy installations on Windows, so it won't be installed there. + +This module including the lzo extra is also automatically installed if you install the `dissect` package. ## Build and test instructions diff --git a/dissect/btrfs/stream.py b/dissect/btrfs/stream.py index 4d3bee2..3ebe80f 100644 --- a/dissect/btrfs/stream.py +++ b/dissect/btrfs/stream.py @@ -6,13 +6,9 @@ from typing import TYPE_CHECKING, BinaryIO, NamedTuple from uuid import UUID +from dissect.util.compression import lzo from dissect.util.stream import AlignedStream -try: - import lzo -except ImportError: - from dissect.util.compression import lzo - try: import zstandard diff --git a/pyproject.toml b/pyproject.toml index ae7e002..ceb9f80 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,14 +37,16 @@ repository = "https://github.com/fox-it/dissect.btrfs" [project.optional-dependencies] full = [ - # There are no Windows PyPy wheels available for python-lzo - # So we use a pure python fallback for it. - "python-lzo; platform_system != 'Windows' or platform_python_implementation != 'PyPy'", "zstandard", ] gcrc32 = [ "google-crc32c", ] +lzo = [ + # There are no Windows PyPy wheels available for python-lzo + # So we use a pure python fallback for it. + "python-lzo; platform_system != 'Windows' or platform_python_implementation != 'PyPy'", +] dev = [ "dissect.btrfs[full]", "dissect.cstruct>=4.0.dev,<5.0.dev",