<commit_before>"""
Decorators to make it easier to use Sumatra in your own Python scripts.

Usage:

@capture
def main(parameters, [other_args...]):
    <body of main function>
"""

import time
from sumatra.programs import PythonExecutable
import sys
import os

def capture(main):
    """
    Decorator for a main() function, which will create a new record for this
    execution. The first argument of main() must be a parameter set.
    """
    def wrapped_main(parameters, *args, **kwargs):
        import sumatra.projects
        project = sumatra.projects.load_project()
        main_file = os.path.abspath(sys.modules['__main__'].__file__)
        executable = PythonExecutable(path=sys.executable)
        record = project.new_record(parameters=parameters,
                                    main_file=main_file,
                                    executable=executable)
        parameters.update({"sumatra_label": record.label})
        start_time = time.time()
        main(parameters, *args, **kwargs)
        record.duration = time.time() - start_time
        record.output_data = record.datastore.find_new_files(record.timestamp)
        project.add_record(record)
        project.save()
    return wrapped_main
<commit_msg>Fixed bug in `@capture` decorator<commit_after>"""
Decorators to make it easier to use Sumatra in your own Python scripts.

Usage:

@capture
def main(parameters, [other_args...]):
    <body of main function>
"""

import time
from sumatra.programs import PythonExecutable
import sys
import os

def capture(main):
    """
    Decorator for a main() function, which will create a new record for this
    execution. The first argument of main() must be a parameter set.
    """
    def wrapped_main(parameters, *args, **kwargs):
        import sumatra.projects
        project = sumatra.projects.load_project()
        main_file = os.path.abspath(sys.modules['__main__'].__file__)
        executable = PythonExecutable(path=sys.executable)
        record = project.new_record(parameters=parameters,
                                    main_file=main_file,
                                    executable=executable)
        parameters.update({"sumatra_label": record.label})
        start_time = time.time()
        main(parameters, *args, **kwargs)
        record.duration = time.time() - start_time
        record.output_data = record.datastore.find_new_data(record.timestamp)
        project.add_record(record)
        project.save()
    return wrapped_main

{'fraction_non_alphanumeric': 0.0958684316085038, 'fraction_numerical': 0.0, 'mean_word_length': 2.750375939849624, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3577800', 'n_tokens_mistral': 685, 'n_tokens_neox': 678, 'n_words': 186}