Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: import libmagic only when its needed #1083

Merged
merged 4 commits into from
Nov 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion kapitan/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import collections
import json
import logging
import magic
import math
import os
import re
Expand Down Expand Up @@ -532,6 +531,14 @@ def make_request(source):
def unpack_downloaded_file(file_path, output_path, content_type):
"""unpacks files of various MIME type and stores it to the output_path"""

try:
import magic
except ImportError:
logger.error(
"Error with unpacking content: libmagic is not installed. Install it with 'apt install libmagic1' or 'apk|brew install libmagic'"
)
sys.exit(1)

if content_type == None or content_type == "application/octet-stream":
if re.search(r"^Zip archive data.*", magic.from_file(file_path)):
content_type = "application/zip"
Expand Down