<commit_before>import os

from compress.utils import get_output_filename, media_root
from compress.versioning.base import VersioningBase

def max_mtime(files):
    return int(max([os.stat(media_root(f)).st_mtime for f in files]))

class MTimeVersioning(VersioningBase):
    
    def get_version(self, source_files):
        mtime = max_mtime(source_files)
        try:
            return str(int(mtime))
        except ValueError:
            return str(mtime)
        
    def needs_update(self, output_file, source_files, version):

        output_file_name = get_output_filename(output_file, version)
        compressed_file_full = media_root(output_file_name)

        return (os.stat(compressed_file_full).st_mtime < version), version
            
        <commit_msg>Fixed bug in mtime versioning that caused re-generation of files every time. Make sure to treat mtimes as ints to avoid comparision errors. Thanks jbmendelson for the bug report.<commit_after>import os

from compress.utils import get_output_filename, media_root
from compress.versioning.base import VersioningBase

class MTimeVersioning(VersioningBase):

    def get_version(self, source_files):

        # Return the modification time for the newest source file
        return str(max([int(os.stat(media_root(f)).st_mtime) for f in source_files]))

    def needs_update(self, output_file, source_files, version):

        output_file_name = get_output_filename(output_file, version)
        compressed_file_full = media_root(output_file_name)

        return (int(os.stat(compressed_file_full).st_mtime) < int(version)), version


{'fraction_non_alphanumeric': 0.07418952618453865, 'fraction_numerical': 0.0, 'mean_word_length': 3.908256880733945, 'pattern_counts': {'":': 0, '<': 5, '<?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': '6871754', 'n_tokens_mistral': 472, 'n_tokens_neox': 463, 'n_words': 120}