<commit_before>#!/usr/bin/env python

from os import path
import filters
import auxfile
from formatters import label
from formatters.backends import latex

__version__ = "0.1"

def make_bibliography(aux_filename, bib_format='bib', bib_encoding=None, latex_encoding=None):
    filename = path.splitext(aux_filename)[0]
    aux_data = auxfile.parse_file(aux_filename)

    bib_parser = filters.find_filter('input', bib_format)
    if bib_encoding is not None:
        try:
            bib_parser.set_encoding(bib_encoding)
        except AttributeError:
            pass

    bib_data = bib_parser.parse_file(path.extsep.join([aux_data.data, bib_parser.extension]))
    
    entries = prepare_entries(bib_data, aux_data)
    del bib_data

    backend = latex
    style = import_style(aux_data.style).Formatter(backend)
    formatted_entries = style.format_entries(entries)
    backend.Writer(latex_encoding).write_bibliography(formatted_entries, path.extsep.join([filename, 'bbl']))

def import_style(name):
    m = __import__('pybtex.formatters.styles', globals(), locals(), [name])
    return getattr(m, name)

def prepare_entries(bib_data, aux_data):
    n = 1
    entries = []
    for key in aux_data.citations:
        print key
        entry = bib_data[key]
        entry.number = n
        entry.key = key
        entry.label = label.number(entry)
        entries.append(entry)
        n += 1
    def l(e):
        return e.label
    entries.sort(key=l)
    return entries

def parse_filename(filename):
    dot = filename.rfind('.')
    if dot == -1:
        return filename, None
    else:
        return (filename[:dot], filename[dot + 1:])
<commit_msg>delete entries right after use (might conserve some memory =)<commit_after>#!/usr/bin/env python

from os import path
import filters
import auxfile
from formatters import label
from formatters.backends import latex

__version__ = "0.1"

def make_bibliography(aux_filename, bib_format='bib', bib_encoding=None, latex_encoding=None):
    filename = path.splitext(aux_filename)[0]
    aux_data = auxfile.parse_file(aux_filename)

    bib_parser = filters.find_filter('input', bib_format)
    if bib_encoding is not None:
        try:
            bib_parser.set_encoding(bib_encoding)
        except AttributeError:
            pass

    bib_data = bib_parser.parse_file(path.extsep.join([aux_data.data, bib_parser.extension]))
    
    entries = prepare_entries(bib_data, aux_data)
    del bib_data

    backend = latex
    style = import_style(aux_data.style).Formatter(backend)
    formatted_entries = style.format_entries(entries)
    del entries
    backend.Writer(latex_encoding).write_bibliography(formatted_entries, path.extsep.join([filename, 'bbl']))

def import_style(name):
    m = __import__('pybtex.formatters.styles', globals(), locals(), [name])
    return getattr(m, name)

def prepare_entries(bib_data, aux_data):
    n = 1
    entries = []
    for key in aux_data.citations:
        print key
        entry = bib_data[key]
        entry.number = n
        entry.key = key
        entry.label = label.number(entry)
        entries.append(entry)
        n += 1
    def l(e):
        return e.label
    entries.sort(key=l)
    return entries

def parse_filename(filename):
    dot = filename.rfind('.')
    if dot == -1:
        return filename, None
    else:
        return (filename[:dot], filename[dot + 1:])

{'fraction_non_alphanumeric': 0.10425280567040757, 'fraction_numerical': 0.004134672179562906, 'mean_word_length': 3.244360902255639, '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': '3903865', 'n_tokens_mistral': 1104, 'n_tokens_neox': 1043, 'n_words': 239}