<commit_before>import __builtin__
import logging
from os import path as ospath
import sys

from pysutils.datastructures import BlankObject, OrderedDict, OrderedSet
from pysutils.error_handling import raise_unexpected_import_error
from pysmvt import ag, settings

log = logging.getLogger(__name__)

class HierarchyImportError(ImportError):
    """
        Used to signal an import error when a request is made to the hierarchy
        tools that can not be filled. Its distinguishable from ImportError so
        that if you receive an ImportError when doing hiearchy processing, you
        know the import error is not from the hierarchy itself but from some
        import in one of the modules the hieararchy lookup accessed.
    """

class FileNotFound(Exception):
    """
        raised when a file is not found in findfile()
    """


class HierarchyManager(object):

    def __init__(self):
        self.builtin_import = __builtin__.__import__
        self.replace_builtin()

    def replace_builtin(self):
        __builtin__.__import__ = self.pysmvt_import
        log.debug('HierarchyManager replaced __builtin__.__import__')

    def restore_builtin(self):
        __builtin__.__import__ = self.builtin_import
        log.debug('HierarchyManager restored __builtin__.__import__')

    def pysmvt_import(self, name, globals={}, locals={}, fromlist=[], level=-1):
        instack_collection = ImportOverrideHelper.doimport(name, fromlist)
        if instack_collection:
            return instack_collection
        return self.builtin_import(name, globals, locals, fromlist, level)
hm = HierarchyManager()


def listapps(reverse=False):
    if reverse:
        apps = list(settings.supporting_apps)
        apps.reverse()
        apps.append(settings.app_package)
        return apps
    return [settings.app_package] + settings.supporting_apps

def listplugins(reverse=False):
    """
        a flat list of the namespace of each enabled plugin
    """
    retval = list(OrderedSet([pname for _, pname, _ in list_plugin_mappings()]))
    if reverse:
        retval.reverse()
    return retval

def list_plugin_mappings(target_plugin=None, reverse=False, inc_apps=False):<commit_msg>listplugins now uses UniqueList instead of OrderedSet<commit_after>import __builtin__
import logging
from os import path as ospath
import sys

from pysutils.datastructures import BlankObject, OrderedDict, UniqueList
from pysutils.error_handling import raise_unexpected_import_error
from pysmvt import ag, settings

log = logging.getLogger(__name__)

class HierarchyImportError(ImportError):
    """
        Used to signal an import error when a request is made to the hierarchy
        tools that can not be filled. Its distinguishable from ImportError so
        that if you receive an ImportError when doing hiearchy processing, you
        know the import error is not from the hierarchy itself but from some
        import in one of the modules the hieararchy lookup accessed.
    """

class FileNotFound(Exception):
    """
        raised when a file is not found in findfile()
    """


class HierarchyManager(object):

    def __init__(self):
        self.builtin_import = __builtin__.__import__
        self.replace_builtin()

    def replace_builtin(self):
        __builtin__.__import__ = self.pysmvt_import
        log.debug('HierarchyManager replaced __builtin__.__import__')

    def restore_builtin(self):
        __builtin__.__import__ = self.builtin_import
        log.debug('HierarchyManager restored __builtin__.__import__')

    def pysmvt_import(self, name, globals={}, locals={}, fromlist=[], level=-1):
        instack_collection = ImportOverrideHelper.doimport(name, fromlist)
        if instack_collection:
            return instack_collection
        return self.builtin_import(name, globals, locals, fromlist, level)
hm = HierarchyManager()


def listapps(reverse=False):
    if reverse:
        apps = list(settings.supporting_apps)
        apps.reverse()
        apps.append(settings.app_package)
        return apps
    return [settings.app_package] + settings.supporting_apps

def listplugins(reverse=False):
    """
        a flat list of the namespace of each enabled plugin
    """
    ul = UniqueList()
    for _, pname, _ in list_plugin_mappings():
        ul.append(pname)
    retval = list(ul)
    if reverse:
        retval.reverse()
    return retval

def list_plugin_mappings(target_plugin=None, reverse=False, inc_apps=False):
{'fraction_non_alphanumeric': 0.07240529029365612, 'fraction_numerical': 0.0004483299708585519, 'mean_word_length': 3.516194331983806, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3175566', 'n_tokens_mistral': 1222, 'n_tokens_neox': 1224, 'n_words': 376}