Add suppor for auto importing dependecies

- No need to use: from .dependencies import *  # NOQA

Signed-off-by: Roberto Rosario <roberto.rosario@mayan-edms.com>
This commit is contained in:
Roberto Rosario
2019-11-10 16:53:29 -04:00
parent cdb1815f49
commit 04f5952ee6
24 changed files with 19 additions and 24 deletions
+14
View File
@@ -2,6 +2,8 @@ from __future__ import print_function, unicode_literals
import fileinput
import json
from importlib import import_module
import logging
import pkg_resources
import shutil
import sys
@@ -158,6 +160,18 @@ class DependencyGroupEntry(object):
class Dependency(object):
_registry = {}
@staticmethod
def initialize():
for app in apps.get_app_configs():
try:
import_module('{}.dependencies'.format(app.name))
except ImportError as exception:
if force_text(exception) not in ('No module named dependencies', 'No module named \'{}.dependencies\''.format(app.name)):
logger.error(
'Error importing %s dependencies.py file; %s', app.name,
exception
)
@staticmethod
def return_sorted(dependencies):
return sorted(dependencies, key=lambda x: x.get_label())