remove unnecessary imports, use find_spec

This was flagged by ruff check - if we just want to find out if a
package is available, and don't need to actually import it, we can
use importlib.util.find_spec() to resolve it. This can lead to a
moderate speedup too, since the import might be slow.
This commit is contained in:
Misty De Méo 2025-07-18 14:14:32 -07:00 committed by Misty De Méo
parent 85ae741b5d
commit 0f0ae4fbc3
3 changed files with 9 additions and 21 deletions

View file

@ -18,6 +18,7 @@ limitations under the License.
"""
import importlib.metadata
import importlib.util
import os
import subprocess
@ -47,14 +48,12 @@ def console_scripts():
def cli_commands():
commands = set(console_scripts().keys())
commands.remove("brozzler-wayback")
try:
import gunicorn # noqa: F401
except ImportError:
if not importlib.util.find_spec("gunicorn"):
commands.remove("brozzler-dashboard")
try:
import pywb # noqa: F401
except ImportError:
if not importlib.util.find_spec("pywb"):
commands.remove("brozzler-easy")
return commands