Skip to content

Commit

Permalink
fix: failed addons import (#368)
Browse files Browse the repository at this point in the history
  • Loading branch information
ocervell committed Apr 30, 2024
1 parent db4f71b commit aee7ede
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 66 deletions.
36 changes: 18 additions & 18 deletions secator/cli.py
Expand Up @@ -592,6 +592,24 @@ def health(json, debug):
table.add_row(*row)
status['secator'] = info

# Check addons
console.print('\n:wrench: [bold gold3]Checking installed addons ...[/]')
table = get_health_table()
with Live(table, console=console):
for addon in ['worker', 'google', 'mongodb', 'redis', 'dev', 'trace', 'build']:
addon_var = ADDONS_ENABLED[addon]
info = {
'name': addon,
'version': None,
'status': 'ok' if addon_var else 'missing',
'latest_version': None,
'installed': addon_var,
'location': None
}
row = fmt_health_table_row(info, 'addons')
table.add_row(*row)
status['addons'][addon] = info

# Check languages
console.print('\n:wrench: [bold gold3]Checking installed languages ...[/]')
version_cmds = {'go': 'version', 'python3': '--version', 'ruby': '--version'}
Expand All @@ -616,24 +634,6 @@ def health(json, debug):
table.add_row(*row)
status['tools'][tool.__name__] = info

# # Check addons
console.print('\n:wrench: [bold gold3]Checking installed addons ...[/]')
table = get_health_table()
with Live(table, console=console):
for addon in ['worker', 'google', 'mongodb', 'redis', 'dev', 'trace', 'build']:
addon_var = ADDONS_ENABLED[addon]
info = {
'name': addon,
'version': None,
'status': 'ok' if addon_var else 'missing',
'latest_version': None,
'installed': addon_var,
'location': None
}
row = fmt_health_table_row(info, 'addons')
table.add_row(*row)
status['addons'][addon] = info

# Print JSON health
if json:
import json as _json
Expand Down
70 changes: 22 additions & 48 deletions secator/definitions.py
Expand Up @@ -105,56 +105,30 @@
WORDS = 'words'


def is_importable(module_to_import):
import importlib
try:
importlib.import_module(module_to_import)
return True
except ModuleNotFoundError:
return False
except Exception as e:
print(f'Failed trying to import {module_to_import}: {str(e)}')
return False


ADDONS_ENABLED = {}

# Check worker addon
try:
import eventlet # noqa: F401
ADDONS_ENABLED['worker'] = True
except ModuleNotFoundError:
ADDONS_ENABLED['worker'] = False

# Check google addon
try:
import gspread # noqa: F401
ADDONS_ENABLED['google'] = True
except ModuleNotFoundError:
ADDONS_ENABLED['google'] = False

# Check mongodb addon
try:
import pymongo # noqa: F401
ADDONS_ENABLED['mongodb'] = True
except ModuleNotFoundError:
ADDONS_ENABLED['mongodb'] = False

# Check redis addon
try:
import redis # noqa: F401
ADDONS_ENABLED['redis'] = True
except ModuleNotFoundError:
ADDONS_ENABLED['redis'] = False

# Check dev addon
try:
import flake8 # noqa: F401
ADDONS_ENABLED['dev'] = True
except ModuleNotFoundError:
ADDONS_ENABLED['dev'] = False

# Check build addon
try:
import hatch # noqa: F401
ADDONS_ENABLED['build'] = True
except ModuleNotFoundError:
ADDONS_ENABLED['build'] = False

# Check trace addon
try:
import memray # noqa: F401
ADDONS_ENABLED['trace'] = True
except ModuleNotFoundError:
ADDONS_ENABLED['trace'] = False
for addon, module in [
('worker', 'eventlet'),
('google', 'gspread'),
('mongodb', 'pymongo'),
('redis', 'redis'),
('dev', 'flake8'),
('trace', 'memray'),
('build', 'hatch')
]:
ADDONS_ENABLED[addon] = is_importable(module)

# Check dev package
if os.path.exists(f'{ROOT_FOLDER}/pyproject.toml'):
Expand Down

0 comments on commit aee7ede

Please sign in to comment.