Skip to content

Commit

Permalink
Add setup_magick_home
Browse files Browse the repository at this point in the history
  • Loading branch information
tanghaibao committed May 14, 2024
1 parent e07a049 commit dee700b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
26 changes: 22 additions & 4 deletions jcvi/apps/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import logging
import os
import os.path as op
import platform
import shutil
import signal
import sys
Expand Down Expand Up @@ -1206,13 +1207,30 @@ def Popen(cmd, stdin=None, stdout=PIPE, debug=False, shell="/bin/bash"):
return proc


def is_macOS():
def get_system_processor() -> Tuple[str, str]:
"""
Check if current OS is macOS, this impacts mostly plotting code.
Get the system and processor information.
"""
import platform
return platform.system(), platform.processor()

return platform.system() == "Darwin"

def is_macOS_arm() -> bool:
"""
Check if the system is macOS on ARM.
"""
system, processor = get_system_processor()
return system == "Darwin" and "arm" in processor


def setup_magick_home():
"""
Set MAGICK_HOME for ImageMagick.
"""
if "MAGICK_HOME" not in os.environ:
if is_macOS_arm():
magick_home = "/opt/homebrew/opt/imagemagick"
os.environ["MAGICK_HOME"] = magick_home
logger.info("Set MAGICK_HOME to `%s`", magick_home)


def popen(cmd, debug=True, shell="/bin/bash"):
Expand Down
4 changes: 4 additions & 0 deletions jcvi/graphics/grabseeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@

import numpy as np

from ..apps.base import setup_magick_home

setup_magick_home()

from PIL.Image import open as iopen
from pyefd import elliptic_fourier_descriptors
from pytesseract import image_to_string
Expand Down

0 comments on commit dee700b

Please sign in to comment.