diff --git a/comicapi/comicarchive.py b/comicapi/comicarchive.py index 34034bb..da4fd83 100644 --- a/comicapi/comicarchive.py +++ b/comicapi/comicarchive.py @@ -28,7 +28,6 @@ import zipfile from typing import cast import natsort -import py7zr import wordninja from comicapi import filenamelexer, filenameparser, utils @@ -37,6 +36,12 @@ from comicapi.comicbookinfo import ComicBookInfo from comicapi.comicinfoxml import ComicInfoXml from comicapi.genericmetadata import GenericMetadata, PageType +try: + import py7zr + + z7_support = True +except ImportError: + z7_support = False try: from unrar.cffi import rarfile @@ -756,15 +761,13 @@ class ComicArchive: self.archiver.path = pathlib.Path(path) def sevenzip_test(self) -> bool: - return py7zr.is_7zfile(self.path) + return z7_support and py7zr.is_7zfile(self.path) def zip_test(self) -> bool: return zipfile.is_zipfile(self.path) def rar_test(self) -> bool: - if rar_support: - return rarfile.is_rarfile(str(self.path)) - return False + return rar_support and rarfile.is_rarfile(str(self.path)) def folder_test(self) -> bool: return self.path.is_dir() diff --git a/requirements-7Z.txt b/requirements-7Z.txt new file mode 100644 index 0000000..014d24e --- /dev/null +++ b/requirements-7Z.txt @@ -0,0 +1 @@ +py7zr diff --git a/requirements.txt b/requirements.txt index 77f2daa..844c274 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,6 @@ importlib_metadata>=3.3.0 natsort>=8.1.0 pathvalidate pillow>=9.1.0 -py7zr pycountry pyicu; sys_platform == 'linux' or sys_platform == 'darwin' rapidfuzz>=2.12.0 diff --git a/tests/comicarchive_test.py b/tests/comicarchive_test.py index 9da035f..004758d 100644 --- a/tests/comicarchive_test.py +++ b/tests/comicarchive_test.py @@ -119,8 +119,11 @@ def test_invalid_zip(tmp_comic): archivers = [ comicapi.comicarchive.ZipArchiver, - comicapi.comicarchive.SevenZipArchiver, comicapi.comicarchive.FolderArchiver, + pytest.param( + comicapi.comicarchive.SevenZipArchiver, + marks=pytest.mark.xfail(not (comicapi.comicarchive.z7_support), reason="7z support"), + ), pytest.param( comicapi.comicarchive.RarArchiver, marks=pytest.mark.xfail(not (comicapi.comicarchive.rar_support and shutil.which("rar")), reason="rar support"),