<commit_before>#!/usr/bin/evn python
# encoding: utf-8

from pprof.project import ProjectFactory, log
from pprof.settings import config
from group import PprofGroup

from os import path
from plumbum import FG, local
from plumbum.cmd import cp, echo, chmod, find


class Povray(PprofGroup):

    """ povray benchmark """

    class Factory:

        def create(self, exp):
            return Povray(exp, "povray", "multimedia")
    ProjectFactory.addFactory("Povray", Factory())

    src_uri = "https://github.com/POV-Ray/povray"
    src_dir = "povray.git"
    boost_src_dir = "boost_1_58_0"
    boost_src_file = boost_src_dir + ".tar.bz2"
    boost_src_uri = "http://sourceforge.net/projects/boost/files/boost/1.58.0/" + boost_src_file

    def download(self):
        from pprof.utils.downloader import Git, Wget
        from plumbum.cmd import tar

        with local.cwd(self.builddir):
            Wget(self.boost_src_uri, self.boost_src_file)
            Git(self.src_uri, self.src_dir)
            tar("xfj", self.boost_src_file)

    def configure(self):
        # First we have to prepare boost for lady povray...
        boost_dir = path.join(self.builddir, self.boost_src_dir)
        boost_prefix = path.join(self.builddir, "boost-install")
        with local.cwd(boost_dir):
            from plumbum.cmd import mkdir
            mkdir(boost_prefix)
            bootstrap = local["./bootstrap.sh"]
            b2 = local["./b2"]
            bootstrap("--prefix=\"{}\"".format(boost_prefix))
            b2("install")

        povray_dir = path.join(self.builddir, self.src_dir)
        with local.cwd(path.join(povray_dir, "unix")):
            from plumbum.cmd import sh
            sh("prebuild.sh")

        with local.cwd(povray_dir):
            from pprof.utils.compiler import clang, clang_cxx
            configure = local["./configure"]
            with local.env(COMPILED_BY="PPROF <<EMAIL>>",
                           CC=clang(),
                           CFLAGS=" ".join(self.cflags),
                           CXX=clang_cxx(),
                           CXXFLAGS=" ".join(self.cflags),
                           LDFLAGS=" ".join(self.ldflags)):
                configure("--with-boost=" + boost_prefix)

    def build(self):
        from plumbum.cmd import make, ln, mv, rm
        povray_dir = path.join(self.builddir, self.src_dir)
        povray_binary = path.join(povray_dir, "unix", self.name)

        with local.cwd(povray_dir):
            rm("-f", povray_binary)
            make & FG
            #make["clean", "all"] & FG
        mv(path.join(povray_dir, "unix", self.name), self.bin_f)
        self.run_f = self.bin_f

    def prepare(self):
        super(Povray, self).prepare()
        cp["-ar", path.join(self.testdir, "cfg"), self.builddir] & FG
        cp["-ar", path.join(self.testdir, "etc"), self.builddir] & FG
        cp["-ar", path.join(self.testdir, "scenes"), self.builddir] & FG
        cp["-ar", path.join(self.testdir, "share"), self.builddir] & FG
        cp["-ar", path.join(self.testdir, "test"), self.builddir] & FG

    def run_tests(self, experiment):
        from plumbum.cmd import mkdir, chmod
        exp = experiment(self.run_f)

        povray_dir = path.join(self.builddir, self.src_dir)
        povray_binary = path.join(povray_dir, "unix", self.name)
        tmpdir = path.join(self.builddir, "tmp")
        povini = path.join(
            self.builddir, "cfg", ".povray", "3.6", "povray.ini")
        scene_dir = path.join(self.builddir, "share", "povray-3.6", "scenes")
        mkdir(tmpdir, retcode=None)

        with open(povray_binary, 'w') as povray:
            povray.write("#!/bin/sh\n")
            povray.write(str(exp) + " \"$@\"")
        chmod("+x", povray_binary)

        render = local[path.join(povray_dir, "scripts",
                                 "render_scene.sh")]
        pov_files = find(scene_dir, "-name", "*.pov").splitlines()
        for pov_f in pov_files:
            from plumbum.cmd import head, grep, sed
            with local.env(POVRAY=povray_binary, INSTALL_DIR=self.builddir,
                           OUTPUT_DIR=tmpdir, POVINI=povini):
                options = ((((head["-n", "50", "\"" + pov_f + "\""] |
                              grep["-E", "'^//[ ]+[-+]{1}[^ -]'"]) |
                             head["-n", "1"]) |
                            sed["s?^//[ ]*??"]) & FG)
                povray = local[povray_binary]<commit_msg>povray: fix call to wrap()<commit_after>#!/usr/bin/evn python
# encoding: utf-8

from pprof.project import ProjectFactory, log
from pprof.settings import config
from group import PprofGroup

from os import path
from plumbum import FG, local
from plumbum.cmd import cp, echo, chmod, find


class Povray(PprofGroup):

    """ povray benchmark """

    class Factory:

        def create(self, exp):
            return Povray(exp, "povray", "multimedia")
    ProjectFactory.addFactory("Povray", Factory())

    src_uri = "https://github.com/POV-Ray/povray"
    src_dir = "povray.git"
    boost_src_dir = "boost_1_58_0"
    boost_src_file = boost_src_dir + ".tar.bz2"
    boost_src_uri = "http://sourceforge.net/projects/boost/files/boost/1.58.0/" + boost_src_file

    def download(self):
        from pprof.utils.downloader import Git, Wget
        from plumbum.cmd import tar

        with local.cwd(self.builddir):
            Wget(self.boost_src_uri, self.boost_src_file)
            Git(self.src_uri, self.src_dir)
            tar("xfj", self.boost_src_file)

    def configure(self):
        # First we have to prepare boost for lady povray...
        boost_dir = path.join(self.builddir, self.boost_src_dir)
        boost_prefix = path.join(self.builddir, "boost-install")
        with local.cwd(boost_dir):
            from plumbum.cmd import mkdir
            mkdir(boost_prefix)
            bootstrap = local["./bootstrap.sh"]
            b2 = local["./b2"]
            bootstrap("--prefix=\"{}\"".format(boost_prefix))
            b2("install")

        povray_dir = path.join(self.builddir, self.src_dir)
        with local.cwd(path.join(povray_dir, "unix")):
            from plumbum.cmd import sh
            sh("prebuild.sh")

        with local.cwd(povray_dir):
            from pprof.utils.compiler import clang, clang_cxx
            configure = local["./configure"]
            with local.env(COMPILED_BY="PPROF <<EMAIL>>",
                           CC=clang(),
                           CFLAGS=" ".join(self.cflags),
                           CXX=clang_cxx(),
                           CXXFLAGS=" ".join(self.cflags),
                           LDFLAGS=" ".join(self.ldflags)):
                configure("--with-boost=" + boost_prefix)

    def build(self):
        from plumbum.cmd import make, ln, mv, rm
        povray_dir = path.join(self.builddir, self.src_dir)
        povray_binary = path.join(povray_dir, "unix", self.name)

        with local.cwd(povray_dir):
            rm("-f", povray_binary)
            make & FG
            #make["clean", "all"] & FG
        mv(path.join(povray_dir, "unix", self.name), self.bin_f)
        self.run_f = self.bin_f

    def prepare(self):
        super(Povray, self).prepare()
        cp["-ar", path.join(self.testdir, "cfg"), self.builddir] & FG
        cp["-ar", path.join(self.testdir, "etc"), self.builddir] & FG
        cp["-ar", path.join(self.testdir, "scenes"), self.builddir] & FG
        cp["-ar", path.join(self.testdir, "share"), self.builddir] & FG
        cp["-ar", path.join(self.testdir, "test"), self.builddir] & FG

    def run_tests(self, experiment):
        from plumbum.cmd import mkdir, chmod
        exp = wrap(self.run_f, experiment(self.run_f))

        povray_dir = path.join(self.builddir, self.src_dir)
        povray_binary = path.join(povray_dir, "unix", self.name)
        tmpdir = path.join(self.builddir, "tmp")
        povini = path.join(
            self.builddir, "cfg", ".povray", "3.6", "povray.ini")
        scene_dir = path.join(self.builddir, "share", "povray-3.6", "scenes")
        mkdir(tmpdir, retcode=None)

        with open(povray_binary, 'w') as povray:
            povray.write("#!/bin/sh\n")
            povray.write(str(exp) + " \"$@\"")
        chmod("+x", povray_binary)

        render = local[path.join(povray_dir, "scripts",
                                 "render_scene.sh")]
        pov_files = find(scene_dir, "-name", "*.pov").splitlines()
        for pov_f in pov_files:
            from plumbum.cmd import head, grep, sed
            with local.env(POVRAY=povray_binary, INSTALL_DIR=self.builddir,
                           OUTPUT_DIR=tmpdir, POVINI=povini):
                options = ((((head["-n", "50", "\"" + pov_f + "\""] |
                              grep["-E", "'^//[ ]+[-+]{1}[^ -]'"]) |
                             head["-n", "1"]) |
                            sed["s?^//[ ]*??"]) & FG)
                povray = local[povray_binary]
{'fraction_non_alphanumeric': 0.14704894165080076, 'fraction_numerical': 0.004703774218837496, 'mean_word_length': 2.0592668722165124, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3285440', 'n_tokens_mistral': 3026, 'n_tokens_neox': 2991, 'n_words': 564}