mirror of
https://github.com/internetarchive/brozzler.git
synced 2025-07-29 01:28:37 -04:00
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:
parent
85ae741b5d
commit
0f0ae4fbc3
3 changed files with 9 additions and 21 deletions
|
@ -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
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue