<commit_before># coding: utf-8
# Copyright 2013 The Font Bakery Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# See AUTHORS.txt for the list of Authors and LICENSE.txt for the License.
import logging
import os
import os.path as op
import yaml

from bakery_cli import pipe
from bakery_cli.system import shutil


class BakeryTaskSet(object):

    def create_task(self, message):
        pass

    def close_task(self, task, failed=False):
        pass


BAKERY_CONFIGURATION_DEFAULTS = op.join(op.dirname(__file__), 'defaults.yaml')


def copy_single_file(src, dest, log):
    """ Copies single filename from src directory to dest directory """
    if op.exists(src) and op.isfile(src):
        shutil.copy(src, dest, log=log)


def bin2unistring(string):
    if b'\000' in string:
        string = string.decode('utf-16-be')
        return string.encode('utf-8')
    else:
        return string


class Bakery(object):
    """ Class to handle all parts of bakery process.

    Attributes:

        root: Absolute path of directory where user project placed
        project_dir: Project directory name (eg. 12.in)
        build_dir: Build directory name (eg. 21.abcdef)
        builds_dir: Builds directory name (eg. 12.out)

    All arguments will be appended to `root`. Eg:

    >>> b = Bakery("/home/user", "projectclone", build_dir="build",
    ...            builds_dir="out")
    >>> b.build_dir
    '/home/user/out/build'
    >>> b.project_root
    '/home/user/projectclone'
    >>> b.builds_dir
    '/home/user/out'
    """

    def __init__(self, root, project_dir, builds_dir='', build_dir='build'):
        self.rootpath = op.abspath(root)

        self.build_dir = op.join(self.rootpath, builds_dir, build_dir)

        self.project_root = op.join(self.rootpath, project_dir)
        self.builds_dir = op.join(self.rootpath, builds_dir)

        self.taskset = BakeryTaskSet()

        self.pipes = [
            pipe.Copy,
            pipe.PyFontaine,
            pipe.UpstreamLint,
            pipe.Build,
            pipe.Metadata,
            pipe.MetadataLint
        ]

        self.logger = logging.getLogger(__name__)
        self.logger.setLevel(logging.DEBUG)

        # create console handler and set level to debug
        ch = logging.StreamHandler()
        ch.setLevel(logging.DEBUG)

        # create formatter
        formatter = logging.Formatter('%(message)s')

        # add formatter to ch
        ch.setFormatter(formatter)

        # add ch to logger
        self.logger.addHandler(ch)

        # chf = logging.FileHandler(op.join(self.build_dir, 'buildlog.txt'))
        # chf.setFormatter(formatter)
        # chf.setLevel(logging.DEBUG)
        # self.logger.addHandler(chf)

    def init_taskset(self, taskset):
        """ Defines object to use TaskSet interface. Default: BakeryTaskSet

        TaskSet must have 2 implemented functions

        - create_task(): Task<commit_msg>Move pyfontaine to the end of the bake process #470<commit_after># coding: utf-8
# Copyright 2013 The Font Bakery Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# See AUTHORS.txt for the list of Authors and LICENSE.txt for the License.
import logging
import os
import os.path as op
import yaml

from bakery_cli import pipe
from bakery_cli.system import shutil


class BakeryTaskSet(object):

    def create_task(self, message):
        pass

    def close_task(self, task, failed=False):
        pass


BAKERY_CONFIGURATION_DEFAULTS = op.join(op.dirname(__file__), 'defaults.yaml')


def copy_single_file(src, dest, log):
    """ Copies single filename from src directory to dest directory """
    if op.exists(src) and op.isfile(src):
        shutil.copy(src, dest, log=log)


def bin2unistring(string):
    if b'\000' in string:
        string = string.decode('utf-16-be')
        return string.encode('utf-8')
    else:
        return string


class Bakery(object):
    """ Class to handle all parts of bakery process.

    Attributes:

        root: Absolute path of directory where user project placed
        project_dir: Project directory name (eg. 12.in)
        build_dir: Build directory name (eg. 21.abcdef)
        builds_dir: Builds directory name (eg. 12.out)

    All arguments will be appended to `root`. Eg:

    >>> b = Bakery("/home/user", "projectclone", build_dir="build",
    ...            builds_dir="out")
    >>> b.build_dir
    '/home/user/out/build'
    >>> b.project_root
    '/home/user/projectclone'
    >>> b.builds_dir
    '/home/user/out'
    """

    def __init__(self, root, project_dir, builds_dir='', build_dir='build'):
        self.rootpath = op.abspath(root)

        self.build_dir = op.join(self.rootpath, builds_dir, build_dir)

        self.project_root = op.join(self.rootpath, project_dir)
        self.builds_dir = op.join(self.rootpath, builds_dir)

        self.taskset = BakeryTaskSet()

        self.pipes = [
            pipe.Copy,
            pipe.UpstreamLint,
            pipe.Build,
            pipe.Metadata,
            pipe.MetadataLint,
            pipe.PyFontaine
        ]

        self.logger = logging.getLogger(__name__)
        self.logger.setLevel(logging.DEBUG)

        # create console handler and set level to debug
        ch = logging.StreamHandler()
        ch.setLevel(logging.DEBUG)

        # create formatter
        formatter = logging.Formatter('%(message)s')

        # add formatter to ch
        ch.setFormatter(formatter)

        # add ch to logger
        self.logger.addHandler(ch)

        # chf = logging.FileHandler(op.join(self.build_dir, 'buildlog.txt'))
        # chf.setFormatter(formatter)
        # chf.setLevel(logging.DEBUG)
        # self.logger.addHandler(chf)

    def init_taskset(self, taskset):
        """ Defines object to use TaskSet interface. Default: BakeryTaskSet

        TaskSet must have 2 implemented functions

        - create_task(): Task
{'fraction_non_alphanumeric': 0.09873162294609397, 'fraction_numerical': 0.007062554050158547, 'mean_word_length': 2.7106951871657756, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4512298', 'n_tokens_mistral': 2096, 'n_tokens_neox': 1996, 'n_words': 616}