<commit_before>"""
Manages the lookup tables for the module 
"""

import logging
import inspect
from os.path import samefile

from presets import registerPreset, addToRunQueue

_module_lookup = {}

class PModulePreset(object):
    
    def __init__(self, name):
        self.name = name

    def __call__(self, p):
        addToRunQueue(p, self.name)
        
# a decorator
def pmodule(c):
    name = c._name = c.__name__.lower()

    assert type(name) is str
    
    if name in _module_lookup:
        m = _module_lookup[name]

        cf = inspect.getfile(c)
        mf = inspect.getfile(m)

        if c is not m and cf != mf and not samefile(cf, mf):
            raise NameError("Module '%s' doubly defined (%s, %s)." % (name, cf, mf))
        else:
            return
        
    c.log = logging.getLogger(c._name)

    _module_lookup[name] = c

    registerPreset("r." + name, PModulePreset(name),
                   description = "Runs processing module '%s'." % c.__name__)
    
    return c

def getPModuleClass(name):

    try:
        return _module_lookup[name]
    except KeyError:
        raise NameError("Module '%s' not found." % name)

def isPModule(name):
    return name in _module_lookup<commit_msg>Fixed small bug in determining whether two modules were from the same file, as one could be from the compiled file and one from the uncompiled.<commit_after>"""
Manages the lookup tables for the module 
"""

import logging
import inspect
import re
from os.path import samefile

from presets import registerPreset, addToRunQueue

_module_lookup = {}

class PModulePreset(object):
    
    def __init__(self, name):
        self.name = name

    def __call__(self, p):
        addToRunQueue(p, self.name)
        
# a decorator
def pmodule(c):
    name = c._name = c.__name__.lower()

    assert type(name) is str
    
    if name in _module_lookup:
        m = _module_lookup[name]

        cf = inspect.getfile(c)
        mf = inspect.getfile(m)

        if c is not m and cf != mf and not samefile(cf, mf):

            # It's still possible that one file is the compiled
            # version of the other file.

            if not samefile(cf.replace('.pyc', '.py'), mf.replace('.pyc', '.py')):
                raise NameError("Module '%s' doubly defined (%s, %s)." % (name, cf, mf))
        else:
            return
        
    c.log = logging.getLogger(c._name)

    _module_lookup[name] = c

    registerPreset("r." + name, PModulePreset(name),
                   description = "Runs processing module '%s'." % c.__name__)
    
    return c

def getPModuleClass(name):

    try:
        return _module_lookup[name]
    except KeyError:
        raise NameError("Module '%s' not found." % name)

def isPModule(name):
    return name in _module_lookup
{'fraction_non_alphanumeric': 0.10302593659942363, 'fraction_numerical': 0.0, 'mean_word_length': 2.4199507389162562, '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': '5080225', 'n_tokens_mistral': 873, 'n_tokens_neox': 843, 'n_words': 272}