<commit_before>import sys
import codecs
import re
import subprocess


__author__ = '<NAME>'


if __name__ == '__main__':
    if len(sys.argv) == 1:
        print('Usage: python rw.py path/to/requirements.txt [app1 [app2 ...]]')
        exit(0)

    req_filename = sys.argv[1]

    req_file = codecs.open(req_filename, 'rt', encoding='utf-8')
    packages = sys.argv[2:]
    new_lines = []
    for line in req_file.readlines():
        new_line = line
        for package in packages:
            if '#egg=%s' % package in line:
                match = re.findall(r'.*@(\S+)#egg=.*', line)
                if match:
                    current_version = match[0]
                    print package, current_version,

                    p1 = subprocess.Popen('pip freeze'.split(), stdout=subprocess.PIPE)
                    p2 = subprocess.Popen(('grep', package), stdin=subprocess.PIPE, stdout=subprocess.PIPE)
                    frozen = p2.communicate(p1.communicate()[0])[0]
                    frozen_match = re.findall(r'.*@(\S+)#egg=.*', frozen)
                    if frozen_match:
                        new_version = frozen_match[0][:8]
                        if new_version != current_version:
                            print '->', new_version
                            new_line = new_line.replace('@%s#egg=' % current_version,
                                                        '@%s#egg=' % new_version)
                        else:
                            print '[up to date]'
                    else:
                        print '[not found in pip freeze]'
        new_lines.append(new_line)
    req_file.close()
    req_file = codecs.open(req_filename, 'wt', encoding='utf-8')
    req_file.writelines(new_lines)
    req_file.close()<commit_msg>executable and shorter commit id (7 chars)<commit_after>#!/usr/bin/env python

import sys
import codecs
import re
import subprocess


__author__ = '<NAME>'


if __name__ == '__main__':
    if len(sys.argv) == 1:
        print('Usage: python rw.py path/to/requirements.txt [app1 [app2 ...]]')
        exit(0)

    req_filename = sys.argv[1]

    req_file = codecs.open(req_filename, 'rt', encoding='utf-8')
    packages = sys.argv[2:]
    new_lines = []
    for line in req_file.readlines():
        new_line = line
        for package in packages:
            if '#egg=%s' % package in line:
                match = re.findall(r'.*@(\S+)#egg=.*', line)
                if match:
                    current_version = match[0]
                    print package, current_version,

                    p1 = subprocess.Popen('pip freeze'.split(), stdout=subprocess.PIPE)
                    p2 = subprocess.Popen(('grep', package), stdin=subprocess.PIPE, stdout=subprocess.PIPE)
                    frozen = p2.communicate(p1.communicate()[0])[0]
                    frozen_match = re.findall(r'.*@(\S+)#egg=.*', frozen)
                    if frozen_match:
                        new_version = frozen_match[0][:7]
                        if new_version != current_version:
                            print '->', new_version
                            new_line = new_line.replace('@%s#egg=' % current_version,
                                                        '@%s#egg=' % new_version)
                        else:
                            print '[up to date]'
                    else:
                        print '[not found in pip freeze]'
        new_lines.append(new_line)
    req_file.close()
    req_file = codecs.open(req_filename, 'wt', encoding='utf-8')
    req_file.writelines(new_lines)
    req_file.close()
{'fraction_non_alphanumeric': 0.125, 'fraction_numerical': 0.009700665188470067, 'mean_word_length': 1.5833929849677881, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '6967634', 'n_tokens_mistral': 1092, 'n_tokens_neox': 1030, 'n_words': 217}