Skip to content

Commit

Permalink
Lazy load external libraries when needed
Browse files Browse the repository at this point in the history
- Improves start-up time
- Prevents immediate failure if the libraries cannot be imported
- Other core functionalities can thus be preserved
- Resolves #17 as an official workaround
  • Loading branch information
arkrow committed Aug 15, 2023
1 parent 9cb24a1 commit 8c63013
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
6 changes: 4 additions & 2 deletions pymusiclooper/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
import shutil
from typing import Tuple

import soundfile
import taglib
import lazy_loader as lazy

from .analysis import find_best_loop_points
from .audio import MLAudio
from .playback import PlaybackHandler

# Lazy-load external libraries when they're needed
soundfile = lazy.load("soundfile")
taglib = lazy.load("taglib")

class MusicLooper:
def __init__(
Expand Down
4 changes: 3 additions & 1 deletion pymusiclooper/playback.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import threading

import numpy as np
import sounddevice as sd
import lazy_loader as lazy
from rich.progress import BarColumn, Progress, TextColumn

from .console import rich_console

# Lazy-load sounddevice
sd = lazy.load("sounddevice")

class PlaybackHandler:
def __init__(self) -> None:
Expand Down
4 changes: 3 additions & 1 deletion pymusiclooper/youtube.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os

import yt_dlp
import lazy_loader as lazy

yt_dlp = lazy.load("yt_dlp")


class YtdLogger:
Expand Down

0 comments on commit 8c63013

Please sign in to comment.