Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion leapp/snactor/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import importlib
import os
import pkgutil
import socket
import sys

from leapp.utils.i18n import _ # noqa; pylint: disable=redefined-builtin
from leapp.snactor import commands
Expand Down Expand Up @@ -30,7 +32,11 @@ def _load_commands_from(path):
for importer, name, is_pkg in pkgutil.iter_modules([pkg_path]):
if is_pkg:
continue
mod = importer.find_module(name).load_module(name)
spec = importer.find_spec(name)
mod = importlib.util.module_from_spec(spec)
Comment on lines +35 to +36
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how that would work, but since both find_spec and module_from_spec were added in python 3.4 and python 3.5, should we covert both of them inside a condition to only load if that's the specific version? If that code runs on python2.7, that will probably fail. If snactor doesn't run on python 2.7 at all, it might be fine 🤔

image

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I will add the condition, this is still work in progress.

sys.modules[name] = mod
spec.loader.exec_module(mod)

if hasattr(mod.cli, 'command'):
if not mod.cli.command.parent:
cli.command.add_sub(mod.cli.command)
Expand Down