<commit_before>import json

'''read the config.json file and make available as a config dict'''

def load_config(path):
    fileobj = open(path)
    c = ""
    for line in fileobj:
        if line.strip().startswith("#"):
            continue
        else:
            c += line
    out = json.loads(c)

    # add some critical defaults if necessary
    if 'facet_field' not in out:
        out['facet_field'] = ''

    return out

config = load_config('config.json')

__all__ = ['config']


''' wrap a config dict in a class if required'''

class Config(object):
    def __init__(self,confdict=config):
        '''Create Configuration object from a configuration dictionary.'''
        self.cfg = confdict
        
    def __getattr__(self, attr):
        return self.cfg.get(attr, None)
        

<commit_msg>[deploy,bugfix][s]: correct config.py to look for config.json relative to config.py rather than just for 'config.json' since latter does not work in deployed environments (e.g. with modwsgi).<commit_after>import os
import json

'''read the config.json file and make available as a config dict'''

def load_config(path):
    fileobj = open(path)
    c = ""
    for line in fileobj:
        if line.strip().startswith("#"):
            continue
        else:
            c += line
    out = json.loads(c)

    # add some critical defaults if necessary
    if 'facet_field' not in out:
        out['facet_field'] = ''

    return out

here = os.path.dirname(__file__)
parent = os.path.dirname(here)
config_path = os.path.join(parent, 'config.json')
config = load_config(config_path)

__all__ = ['config']


''' wrap a config dict in a class if required'''

class Config(object):
    def __init__(self,confdict=config):
        '''Create Configuration object from a configuration dictionary.'''
        self.cfg = confdict
        
    def __getattr__(self, attr):
        return self.cfg.get(attr, None)
        


{'fraction_non_alphanumeric': 0.11186264308012488, 'fraction_numerical': 0.0, 'mean_word_length': 2.7195357833655707, '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': '2714030', 'n_tokens_mistral': 567, 'n_tokens_neox': 560, 'n_words': 186}