mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +01:00
use different loading for python 3
This commit is contained in:
parent
0de4a563ee
commit
9ff8366ca4
1 changed files with 16 additions and 4 deletions
|
|
@ -1,9 +1,12 @@
|
|||
import os
|
||||
import sys
|
||||
import types
|
||||
import importlib
|
||||
import inspect
|
||||
import logging
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
PY3 = sys.version_info[0] == 3
|
||||
|
||||
|
||||
def modules_from_path(folder_path):
|
||||
|
|
@ -39,11 +42,20 @@ def modules_from_path(folder_path):
|
|||
try:
|
||||
# Prepare module object where content of file will be parsed
|
||||
module = types.ModuleType(mod_name)
|
||||
module.__file__ = full_path
|
||||
|
||||
with open(full_path) as _stream:
|
||||
# Execute content and store it to module object
|
||||
exec(_stream.read(), module.__dict__)
|
||||
if PY3:
|
||||
# Use loader so module has full specs
|
||||
module_loader = importlib.machinery.SourceFileLoader(
|
||||
mod_name, full_path
|
||||
)
|
||||
module_loader.exec_module(module)
|
||||
else:
|
||||
# Execute module code and store content to module
|
||||
with open(full_path) as _stream:
|
||||
# Execute content and store it to module object
|
||||
exec(_stream.read(), module.__dict__)
|
||||
|
||||
module.__file__ = full_path
|
||||
|
||||
modules.append(module)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue