<commit_before>import pygame, tempfile, sys
from entrypoint2 import entrypoint
from path import Path
from easyprocess import EasyProcess
from time import sleep
import atexit
import logging, os

log = logging.getLogger(__name__)

rectsize = 50
first = True
refimgpath = None


def run(refimgpath, size=None):

    pygame.display.init()
    pygame.mouse.set_visible(0)
    log.info("pygame modes:%s", pygame.display.list_modes())
    log.info("pygame info:%s", pygame.display.Info())

    if size:
        disp = pygame.display.set_mode(size)
    else:
        disp = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
        if os.environ.get("TRAVIS"):
            # TODO: travis fails without 2nd set_mode.
            disp = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)

    w, h = pygame.display.get_surface().get_size()
    log.info("w, h: %s,%s", w, h)
    i = 0
    for x in range(0, w, rectsize):
        for y in range(0, h, rectsize):
            r = x * 255 / w
            g = y * 255 / h
            b = (i % 5) * 255 / 5
            pygame.draw.rect(disp, (r, g, b), (x, y, rectsize, rectsize))
            i += 1

    pygame.display.update()
    pygame.display.update()
    pygame.display.update()

    if refimgpath:
        log.info("saving %s", refimgpath)
        pygame.image.save(disp, refimgpath)

    clock = pygame.time.Clock()
    running = True
    log.info("start loop")
    while running:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False
        pygame.display.update()
        clock.tick(10)
    pygame.quit()


def init():
    global first, refimgpath
    if first:
        first = False
        d = tempfile.mkdtemp(prefix="fillscreen")
        d = Path(d)
        atexit.register(d.rmtree)
        refimgpath = d / "ref.bmp"
        python = sys.executable
        cmd = [
            python,
            "-m",
            "fillscreen",
            "--saveimage",
            refimgpath,
        ]
        proc = EasyProcess(cmd).start()
        atexit.register(proc.stop)
        while not refimgpath.exists():
            sleep(0.1)
    return refimgpath


@entrypoint
def main(size=None, saveimage=""):
    if size:
        size = map(int, size.split(":"))
        size = tuple(size)

    run(saveimage, size)

<commit_msg>test: wait for ref.png save<commit_after>import pygame, tempfile, sys
from entrypoint2 import entrypoint
from path import Path
from easyprocess import EasyProcess
from time import sleep
import atexit
import logging, os

log = logging.getLogger(__name__)

rectsize = 50
first = True
refimgpath = None


def run(refimgpath, size=None):

    pygame.display.init()
    pygame.mouse.set_visible(0)
    log.info("pygame modes:%s", pygame.display.list_modes())
    log.info("pygame info:%s", pygame.display.Info())

    if size:
        disp = pygame.display.set_mode(size)
    else:
        disp = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
        if os.environ.get("TRAVIS"):
            # TODO: travis fails without 2nd set_mode.
            disp = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)

    w, h = pygame.display.get_surface().get_size()
    log.info("w, h: %s,%s", w, h)
    i = 0
    for x in range(0, w, rectsize):
        for y in range(0, h, rectsize):
            r = x * 255 / w
            g = y * 255 / h
            b = (i % 5) * 255 / 5
            pygame.draw.rect(disp, (r, g, b), (x, y, rectsize, rectsize))
            i += 1

    pygame.display.update()
    pygame.display.update()
    pygame.display.update()

    if refimgpath:
        log.info("saving %s", refimgpath)
        pygame.image.save(disp, refimgpath)
        ready = refimgpath + ".ready"
        open(ready, "a").close()
    clock = pygame.time.Clock()
    running = True
    log.info("start loop")
    while running:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False
        pygame.display.update()
        clock.tick(10)
    pygame.quit()


def init():
    global first, refimgpath
    if first:
        first = False
        d = tempfile.mkdtemp(prefix="fillscreen")
        d = Path(d)
        atexit.register(d.rmtree)
        refimgpath = d / "ref.png"
        python = sys.executable
        cmd = [
            python,
            "-m",
            "fillscreen",
            "--saveimage",
            refimgpath,
        ]
        proc = EasyProcess(cmd).start()
        atexit.register(proc.stop)
        ready = refimgpath + ".ready"
        while not ready.exists():
            sleep(0.1)
    return refimgpath


@entrypoint
def main(size=None, saveimage=""):
    if size:
        size = map(int, size.split(":"))
        size = tuple(size)

    run(saveimage, size)


{'fraction_non_alphanumeric': 0.1268578605819552, 'fraction_numerical': 0.011722838601632824, 'mean_word_length': 2.0471938775510203, 'pattern_counts': {'":': 2, '<': 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': '3906592', 'n_tokens_mistral': 1615, 'n_tokens_neox': 1548, 'n_words': 386}