Make 7zip support optional
This commit is contained in:
parent
685ce014b6
commit
c469fdb25e
@ -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()
|
||||
|
1
requirements-7Z.txt
Normal file
1
requirements-7Z.txt
Normal file
@ -0,0 +1 @@
|
||||
py7zr
|
@ -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
|
||||
|
@ -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"),
|
||||
|
Loading…
Reference in New Issue
Block a user