<commit_before># -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function,
                        unicode_literals)

import importlib
import os
import sys

from future import standard_library
from past.builtins import execfile

from cartoview.app_manager.config import AppsConfig
from cartoview.app_manager.helpers import (change_path_permission,
                                           create_direcotry)
from cartoview.log_handler import get_logger

logger = get_logger(__name__)

standard_library.install_aliases()

# BASE_DIR must be defined in project.settings

CARTOVIEW_APPS = ()
APPS_SETTINGS = []


def create_apps_dir(APPS_DIR):
    if not os.path.exists(APPS_DIR):
        create_direcotry(APPS_DIR)
        if not os.access(APPS_DIR, os.W_OK):
            change_path_permission(APPS_DIR)


def load_apps(APPS_DIR):
    global CARTOVIEW_APPS
    global APPS_SETTINGS
    create_apps_dir(APPS_DIR)
    if APPS_DIR not in sys.path:
        sys.path.append(APPS_DIR)
    apps_file_path = os.path.join(APPS_DIR, "apps.yml")
    apps_config = AppsConfig(apps_file_path)
    for app_config in apps_config:
        if app_config.active:
            try:
                # ensure that the folder is python module
                app_module = importlib.import_module(app_config.name)
                app_dir = os.path.dirname(app_module.__file__)
                app_settings_file = os.path.join(app_dir, 'settings.py')
                if os.path.exists(app_settings_file):
                    # By doing this instead of import, app/settings.py can
                    # refer to local variables from settings.py without
                    # circular imports.
                    app_settings_file = os.path.realpath(app_settings_file)
                    APPS_SETTINGS += (app_settings_file,)
                    # execfile(app_settings_file)
                if app_config.name not in CARTOVIEW_APPS:
                    # app_config.name.__str__() because Django don't like
                    # unicode_literals
                    CARTOVIEW_APPS += (app_config.name.__str__(), )
            except Exception as e:
                print(e.message)
                logger.error(e.message)
<commit_msg>add libs folder to system path<commit_after># -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function,
                        unicode_literals)

import importlib
import os
import sys

from future import standard_library
from past.builtins import execfile

from cartoview.app_manager.config import AppsConfig
from cartoview.app_manager.helpers import (change_path_permission,
                                           create_direcotry)
from cartoview.log_handler import get_logger

logger = get_logger(__name__)

standard_library.install_aliases()

# BASE_DIR must be defined in project.settings

CARTOVIEW_APPS = ()
APPS_SETTINGS = []


def create_apps_dir(APPS_DIR):
    if not os.path.exists(APPS_DIR):
        create_direcotry(APPS_DIR)
        if not os.access(APPS_DIR, os.W_OK):
            change_path_permission(APPS_DIR)


def load_apps(APPS_DIR):
    global CARTOVIEW_APPS
    global APPS_SETTINGS
    create_apps_dir(APPS_DIR)
    if APPS_DIR not in sys.path:
        sys.path.append(APPS_DIR)
    apps_file_path = os.path.join(APPS_DIR, "apps.yml")
    apps_config = AppsConfig(apps_file_path)
    for app_config in apps_config:
        if app_config.active:
            try:
                # ensure that the folder is python module
                app_module = importlib.import_module(app_config.name)
                app_dir = os.path.dirname(app_module.__file__)
                app_settings_file = os.path.join(app_dir, 'settings.py')
                libs_dir = os.path.join(app_dir, 'libs')
                if os.path.exists(app_settings_file):
                    # By doing this instead of import, app/settings.py can
                    # refer to local variables from settings.py without
                    # circular imports.
                    app_settings_file = os.path.realpath(app_settings_file)
                    APPS_SETTINGS += (app_settings_file,)
                    # execfile(app_settings_file)
                if os.path.exists(libs_dir) and libs_dir not in sys.path:
                    sys.path.append(libs_dir)
                if app_config.name not in CARTOVIEW_APPS:
                    # app_config.name.__str__() because Django don't like
                    # unicode_literals
                    CARTOVIEW_APPS += (app_config.name.__str__(), )
            except Exception as e:
                print(e.message)
                logger.error(e.message)

{'fraction_non_alphanumeric': 0.07142857142857142, 'fraction_numerical': 0.000427715996578272, 'mean_word_length': 2.1708474576271186, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7299181', 'n_tokens_mistral': 1405, 'n_tokens_neox': 1349, 'n_words': 298}