<commit_before>import os, cPickle as pickle
import fileutil

class Project(object):
    def __init__(self, name, rootdir, filename, session=None):
        self.name = name
        self.rootdir = rootdir
        self.filename = filename
        self.session = session

def read_project(filename, rootdir):
    with open(filename, "rb") as f:
        session = pickle.loads(f.read())
    return Project("", rootdir, filename, session)

def write_project(project):
    fileutil.mkpath(os.path.dirname(project.filename))
    data = pickle.dumps(project.session, pickle.HIGHEST_PROTOCOL)
    fileutil.atomic_write_file(project.filename, data)<commit_msg>Save sessions in JSON format instead of pickle.<commit_after>import os
import json

import fileutil

class Project(object):
    def __init__(self, name, rootdir, filename, session=None):
        self.name = name
        self.rootdir = rootdir
        self.filename = filename
        self.session = session

def read_project(filename, rootdir):
    with open(filename, "rb") as f:
        session = json.loads(f.read())
    return Project("", rootdir, filename, session)

def write_project(project):
    fileutil.mkpath(os.path.dirname(project.filename))
    data = json.dumps(project.session, indent=2)
    fileutil.atomic_write_file(project.filename, data)
{'fraction_non_alphanumeric': 0.10711553175210406, 'fraction_numerical': 0.0007651109410864575, 'mean_word_length': 3.7737226277372264, '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': '5160438', 'n_tokens_mistral': 392, 'n_tokens_neox': 392, 'n_words': 97}