<commit_before>
import os.path
from abc import ABCMeta,abstractmethod

from ems.ioc.container import Container
from ems.event.dispatcher import Dispatcher
from ems.eventhook import EventHook

class App(Container):

    _shortCut = None

    def __init__(self, argv, path):
        super(App, self).__init__()
        self._bootstrappers = [
            EventBootstrapper()
        ]
        self.argv = argv
        self.path = path

        self.starting = EventHook()
        self.started = EventHook()

        self.bootstrapping = EventHook()
        self.bootstrapped = EventHook()

        App._shortCut = self.appInstance

        self.shareInstance(App, self)

    def addBootstrapper(self, bootstrapper):
        if not isinstance(bootstrapper, Bootstrapper):
            raise TypeError('Bootstrapper has to be Bootstrapper (abc)')
        self._bootstrappers.append(bootstrapper)

    def getBootstrappers(self):
        return self._bootstrappers;

    bootstrappers = property(getBootstrappers)

    def start(self, path, argv):

        self.path = path
        self.argv = argv
        self.starting.fire(argv)

        for bootstrapper in self._bootstrappers:
            self.bootstrapping.fire(bootstrapper)
            bootstrapper.bootstrap(self)
            self.bootstrapped.fire(bootstrapper)

        self.started.fire(self)

    def appInstance(self, abstract=None, *args, **kwargs):

        if abstract is None:
            return self

        return self.make(abstract, *args, **kwargs)

    def __call__(self, *args, **kwargs):
        return self.appInstance(*args, **kwargs)

class Bootstrapper(object):

    __metaclass__ = ABCMeta

    @abstractmethod
    def bootstrap(self, app):
        pass

class EventBootstrapper(Bootstrapper):

    def __init__(self):
        self._dispatcher = Dispatcher()

    def bootstrap(self, app):
        self.app = app
        app.alias('events', Dispatcher)
        app.shareInstance('events', self._dispatcher)
        self._injectEventForwards(app)

    def _injectEventForwards(self, app):
        app.bootstrapping += self.fireBootstrapping
        app.bootstrapped += self.fireBootstrapped
        app.started += self.fireStarted

    def fireBootstrapping(self, bootstrapper):
        self._dispatcher.fire('bootstrapping', bootstrapper)

    def fireBootstrapped(self, bootstrapper):
        self._dispatcher.fire('bootstrapped', bootstrapper)

    def fireStarted(self, app):
        self._dispatcher.fire('app.started', app)

def app(abstract=None, *args, **kwargs):
    return App._shortCut(abstract, *args, **kwargs)

def relative_path(path):

    rPath = path.replace(app_path(), "")
    if rPath.startswith(os.path.sep):
        return rPath[1:]
    return rPath

def absolute_path(path):

    if os.path.isabs(path):
        return path

    if not path.startswith(os.path.sep):
        return os.path.join(app_path(), path)

    return path<commit_msg>Return absolute paths if path is no app subpath<commit_after>
import os.path
from abc import ABCMeta,abstractmethod

from ems.ioc.container import Container
from ems.event.dispatcher import Dispatcher
from ems.eventhook import EventHook

class App(Container):

    _shortCut = None

    def __init__(self, argv, path):
        super(App, self).__init__()
        self._bootstrappers = [
            EventBootstrapper()
        ]
        self.argv = argv
        self.path = path

        self.starting = EventHook()
        self.started = EventHook()

        self.bootstrapping = EventHook()
        self.bootstrapped = EventHook()

        App._shortCut = self.appInstance

        self.shareInstance(App, self)

    def addBootstrapper(self, bootstrapper):
        if not isinstance(bootstrapper, Bootstrapper):
            raise TypeError('Bootstrapper has to be Bootstrapper (abc)')
        self._bootstrappers.append(bootstrapper)

    def getBootstrappers(self):
        return self._bootstrappers;

    bootstrappers = property(getBootstrappers)

    def start(self, path, argv):

        self.path = path
        self.argv = argv
        self.starting.fire(argv)

        for bootstrapper in self._bootstrappers:
            self.bootstrapping.fire(bootstrapper)
            bootstrapper.bootstrap(self)
            self.bootstrapped.fire(bootstrapper)

        self.started.fire(self)

    def appInstance(self, abstract=None, *args, **kwargs):

        if abstract is None:
            return self

        return self.make(abstract, *args, **kwargs)

    def __call__(self, *args, **kwargs):
        return self.appInstance(*args, **kwargs)

class Bootstrapper(object):

    __metaclass__ = ABCMeta

    @abstractmethod
    def bootstrap(self, app):
        pass

class EventBootstrapper(Bootstrapper):

    def __init__(self):
        self._dispatcher = Dispatcher()

    def bootstrap(self, app):
        self.app = app
        app.alias('events', Dispatcher)
        app.shareInstance('events', self._dispatcher)
        self._injectEventForwards(app)

    def _injectEventForwards(self, app):
        app.bootstrapping += self.fireBootstrapping
        app.bootstrapped += self.fireBootstrapped
        app.started += self.fireStarted

    def fireBootstrapping(self, bootstrapper):
        self._dispatcher.fire('bootstrapping', bootstrapper)

    def fireBootstrapped(self, bootstrapper):
        self._dispatcher.fire('bootstrapped', bootstrapper)

    def fireStarted(self, app):
        self._dispatcher.fire('app.started', app)

def app(abstract=None, *args, **kwargs):
    return App._shortCut(abstract, *args, **kwargs)

def relative_path(path):

    appPath = app_path()

    if not path.startswith(appPath):
        return path

    rPath = path.replace(appPath, "")
    if rPath.startswith(os.path.sep):
        return rPath[1:]
    return rPath

def absolute_path(path):

    if os.path.isabs(path):
        return path

    if not path.startswith(os.path.sep):
        return os.path.join(app_path(), path)

    return path
{'fraction_non_alphanumeric': 0.10035064284521623, 'fraction_numerical': 0.0003339455668725998, 'mean_word_length': 2.7815656565656566, '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': '3452298', 'n_tokens_mistral': 1809, 'n_tokens_neox': 1738, 'n_words': 390}