File tree Expand file tree Collapse file tree 3 files changed +9
-21
lines changed Expand file tree Collapse file tree 3 files changed +9
-21
lines changed Original file line number Diff line number Diff line change 1818"""
1919
2020import datetime
21+ import importlib .util
2122import logging
2223import threading
2324from importlib .metadata import version as _version
@@ -414,12 +415,7 @@ def suggest_default_chrome_exe():
414415 "suggest_default_chrome_exe" ,
415416]
416417
417- # TODO try using importlib.util.find_spec to test for dependency presence
418- # rather than try/except on import.
419- # See https://docs.astral.sh/ruff/rules/unused-import/#example
420- try :
421- import doublethink # noqa: F401
422-
418+ if importlib .util .find_spec ("doublethink" ):
423419 # All of these imports use doublethink for real and are unsafe
424420 # to do if doublethink is unavailable.
425421 from brozzler .frontier import RethinkDbFrontier # noqa: F401
@@ -447,8 +443,6 @@ def suggest_default_chrome_exe():
447443 "InvalidJobConf" ,
448444 ]
449445 )
450- except ImportError :
451- pass
452446
453447# we could make this configurable if there's a good reason
454448MAX_PAGE_FAILURES = 3
Original file line number Diff line number Diff line change 1919"""
2020
2121import datetime
22+ import importlib .util
2223import io
2324import json
2425import socket
@@ -100,14 +101,8 @@ def __init__(
100101 if worker_id is not None :
101102 self .logger = self .logger .bind (worker_id = worker_id )
102103
103- # TODO try using importlib.util.find_spec to test for dependency
104- # presence rather than try/except on import.
105- # See https://docs.astral.sh/ruff/rules/unused-import/#example
106-
107104 # We definitely shouldn't ytdlp if the optional extra is missing
108- try :
109- import yt_dlp # noqa: F401
110- except ImportError :
105+ if not importlib .util .find_spec ("yt_dlp" ):
111106 self .logger .info (
112107 "optional yt-dlp extra not installed; setting skip_youtube_dl to True"
113108 )
Original file line number Diff line number Diff line change 1818"""
1919
2020import importlib .metadata
21+ import importlib .util
2122import os
2223import subprocess
2324
@@ -47,14 +48,12 @@ def console_scripts():
4748def cli_commands ():
4849 commands = set (console_scripts ().keys ())
4950 commands .remove ("brozzler-wayback" )
50- try :
51- import gunicorn # noqa: F401
52- except ImportError :
51+ if not importlib .util .find_spec ("gunicorn" ):
5352 commands .remove ("brozzler-dashboard" )
54- try :
55- import pywb # noqa: F401
56- except ImportError :
53+
54+ if not importlib .util .find_spec ("pywb" ):
5755 commands .remove ("brozzler-easy" )
56+
5857 return commands
5958
6059
You can’t perform that action at this time.
0 commit comments