From d939d999903bb59388bf504760a4ae5407213520 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Thu, 7 Jul 2022 14:31:42 +0300 Subject: Replace 'magic' with builtin 'mimetypes' Use the builtin mimetypes which gives better results --- scripts/qc.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'scripts') diff --git a/scripts/qc.py b/scripts/qc.py index de01bb7..2057cd6 100644 --- a/scripts/qc.py +++ b/scripts/qc.py @@ -2,10 +2,9 @@ import os import sys import argparse +import mimetypes from typing import Union, Callable -import magic - from quality_control.utils import make_progress_calculator from quality_control.errors import InvalidValue, DuplicateHeading from quality_control.parsing import ( @@ -15,9 +14,10 @@ from quality_control.parsing import ( collect_errors) -def is_file_mime(filepath, mimetype): +def is_file_mime(filepath:str, mimetype:str) -> bool: """Check that `filepath` has a mimetype of `mimetype` or `text/plain`""" - return magic.from_file(filepath, mime=True) in ("text/plain", mimetype) + the_type = mimetypes.guess_type(filepath)[0] + return the_type in ("text/plain", mimetype) def cli_argument_parser(): """Create the parser for the CLI arguments""" -- cgit v1.2.3