From b6d0d516edeba1e3f6dda083eb62b80e2f656ba5 Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Sat, 14 Sep 2024 10:33:29 +0200 Subject: [PATCH] Make pylibmagic import optional I was trying to use the galaxy-data container for data source tools, but it fails with: ``` Traceback (most recent call last): File "/Users/mvandenb/src/galaxy/test/functional/tools/data_source.py", line 13, in from galaxy.datatypes import sniff File "/usr/local/lib/python3.12/site-packages/galaxy/datatypes/sniff.py", line 40, in import pylibmagic # noqa: F401 # isort:skip ^^^^^^^^^^^^^^^^^ ModuleNotFoundError: No module named 'pylibmagic' ``` pylibmagic is just shipping the magic library and adds it to path, but that's not needed for the data-data container which can use magic just fine. --- lib/galaxy/datatypes/sniff.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/galaxy/datatypes/sniff.py b/lib/galaxy/datatypes/sniff.py index 12a6550bdf6d..0affcde217da 100644 --- a/lib/galaxy/datatypes/sniff.py +++ b/lib/galaxy/datatypes/sniff.py @@ -37,7 +37,11 @@ ) from galaxy.util.path import StrPath -import pylibmagic # noqa: F401 # isort:skip +try: + import pylibmagic # noqa: F401 # isort:skip +except ImportError: + # Not available in conda, but docker image contains libmagic + pass import magic # isort:skip