Skip to content

Commit

Permalink
refactor: update mac detection functions and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zackees committed Feb 1, 2025
1 parent c9de200 commit e8c5828
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
16 changes: 11 additions & 5 deletions src/transcribe_anything/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,22 @@
PROCESS_TIMEOUT = 4 * 60 * 60


def is_mac_arm():
def is_mac_arm() -> bool:
"""Returns true if mac arm like m1, m2, etc."""
if platform.system() != "Darwin":
return False # Not a Mac
else:

# Using uname to get the machine hardware name can indicate the architecture
machine = os.uname().machine # pylint: disable=no-member
# Using uname to get the machine hardware name can indicate the architecture
machine = os.uname().machine # type: ignore[attr-defined]

# ARM architectures can be 'arm64' or 'aarch64' depending on the platform
return machine in ["arm64", "aarch64"]
# ARM architectures can be 'arm64' or 'aarch64' depending on the platform
return machine in ["arm64", "aarch64"]


def is_mac() -> bool:
"""Returns True if the OS is macOS."""
return platform.system() == "Darwin"


def sanitize_filename(string: str) -> str:
Expand Down
5 changes: 3 additions & 2 deletions tests/test_insane_whisper_cmd_arg.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
import unittest

from transcribe_anything.api import transcribe
from transcribe_anything.util import has_nvidia_smi, is_mac_arm
from transcribe_anything.util import has_nvidia_smi, is_mac

HERE = os.path.abspath(os.path.dirname(__file__))
LOCALFILE_DIR = os.path.join(HERE, "localfile")
TESTS_DATA_DIR = os.path.join(LOCALFILE_DIR, "text_video_api_insane", "en")

CAN_RUN_TEST = has_nvidia_smi() or is_mac_arm()

CAN_RUN_TEST = has_nvidia_smi() and not is_mac()


class InsaneWhisperModeTester(unittest.TestCase):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_insanely_fast_whisper.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
get_cuda_info,
run_insanely_fast_whisper,
)
from transcribe_anything.util import has_nvidia_smi, is_mac_arm
from transcribe_anything.util import has_nvidia_smi, is_mac

HERE = Path(os.path.abspath(os.path.dirname(__file__)))
LOCALFILE_DIR = HERE / "localfile"
TESTS_DATA_DIR = LOCALFILE_DIR / "text_video_insane" / "en"
TEST_WAV = LOCALFILE_DIR / "video.wav"

CAN_RUN_TEST = has_nvidia_smi() or is_mac_arm()
CAN_RUN_TEST = has_nvidia_smi() and not is_mac()


class InsanelFastWhisperTester(unittest.TestCase):
Expand Down

0 comments on commit e8c5828

Please sign in to comment.