<commit_before>from django.conf import settings
from django.conf.urls import url
from django.contrib.staticfiles import finders
from django.http.response import HttpResponse
from closure.tracker import analyze_modules
from pathlib import Path
import logging
import io
import json
import os
import fcntl
from hashlib import sha256

log = logging.getLogger(__name__)

PATHS_URL = "/closure/paths.js"

def load_closure_config():
    '''
    Load the JSON closure config from the file given in the
    ``CLOSURE_CONFIG`` setting or from ``closure-cofnig.js``,
    ``CLOSURE_CONFIG`` is not present in the configuration.
    
    :return: The parsed JSON object from the closure-util JSON input file. 
    '''
    
    configfile = getattr(settings,"CLOSURE_CONFIG","closure-config.json")
    
    absfile = finders.find(configfile)
    
    with io.open(absfile) as fh:
        return os.path.dirname(absfile),json.load(fh)
    
def lock_closure_config(exclusive):

    configfile = getattr(settings,"CLOSURE_CONFIG","closure-config.json")
    
    absfile = finders.find(configfile)
    
    fh = io.open(absfile+".lock",mode="w")
    
    try:
        fcntl.lockf(fh,fcntl.LOCK_EX if exclusive else fcntl.LOCK_SH)
    except:
        fh.close()
        raise
    
    return fh

def open_closure_cache(mode):

    configfile = getattr(settings,"CLOSURE_CONFIG","closure-config.json")
    
    absfile = finders.find(configfile)
    
    return io.open(absfile+".cache",mode=mode)

def get_main_js_urls():
        
    with lock_closure_config(True):<commit_msg>Do not try to lock the closure config in production mode.<commit_after>from django.conf import settings
from django.conf.urls import url
from django.contrib.staticfiles import finders
from django.http.response import HttpResponse
from closure.tracker import analyze_modules
from pathlib import Path
import logging
import io
import json
import os
import fcntl
from hashlib import sha256

log = logging.getLogger(__name__)

PATHS_URL = "/closure/paths.js"

def load_closure_config():
    '''
    Load the JSON closure config from the file given in the
    ``CLOSURE_CONFIG`` setting or from ``closure-cofnig.js``,
    ``CLOSURE_CONFIG`` is not present in the configuration.
    
    :return: The parsed JSON object from the closure-util JSON input file. 
    '''
    
    configfile = getattr(settings,"CLOSURE_CONFIG","closure-config.json")
    
    absfile = finders.find(configfile)
    
    with io.open(absfile) as fh:
        return os.path.dirname(absfile),json.load(fh)
    
def lock_closure_config(exclusive):

    configfile = getattr(settings,"CLOSURE_CONFIG","closure-config.json")
    
    absfile = finders.find(configfile)
    
    fh = io.open(absfile+".lock",mode="w")
    
    try:
        fcntl.lockf(fh,fcntl.LOCK_EX if exclusive else fcntl.LOCK_SH)
    except:
        fh.close()
        raise
    
    return fh

def open_closure_cache(mode):

    configfile = getattr(settings,"CLOSURE_CONFIG","closure-config.json")
    
    absfile = finders.find(configfile)
    
    return io.open(absfile+".cache",mode=mode)

def get_main_js_urls():
        
    if not settings.DEBUG:
        return None

    with lock_closure_config(True):
{'fraction_non_alphanumeric': 0.09501557632398754, 'fraction_numerical': 0.001869158878504673, 'mean_word_length': 3.4289655172413793, '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': '7272112', 'n_tokens_mistral': 1012, 'n_tokens_neox': 996, 'n_words': 252}