<commit_before>"""This module contains various tools

Attributes:
    log (logging): logger for this module
    OSX_CLANG_VERSION_DICT (dict): mapping from version number of OSX clang
        to the one of llvm clang.
        Taken from here: https://gist.github.com/yamaya/2924292
    PKG_NAME (str): this package name
"""
from os import path
from os import makedirs
from os import listdir

import sublime
import logging
import tempfile

import re

PKG_NAME = path.basename(path.dirname(path.dirname(__file__)))

OSX_CLANG_VERSION_DICT = {
    '4.2': '3.2',
    '5.0': '3.3',
    '5.1': '3.4',
    '6.0': '3.5',
    '6.1': '3.6',
    '7.0': '3.7',
    '7.3': '3.7'
}

log = logging.getLogger(__name__)


class SublBridge:

    """A small help class that bridges with sublime (maybe will grow)

    Attributes:
        NO_DEFAULT_COMPLETIONS (TYPE): Description
    """

    NO_DEFAULT_COMPLETIONS = sublime.INHIBIT_WORD_COMPLETIONS \
        | sublime.INHIBIT_EXPLICIT_COMPLETIONS

    @staticmethod
    def cursor_pos(view):
        """Get current cursor position. Returns position of the first cursor if
        multiple are present

        Args:
            view (sublime.View): current view

        Returns:
            (row, col): tuple of row and col for cursor position
        """
        pos = view.sel()
        if len(pos) < 1:
            # something is wrong
            return None
        (row, col) = view.rowcol(pos[0].a)
        row += 1
        col += 1
        return (row, col)

    @staticmethod
    def next_line(view):
        """Get next line as text

        Args:
            view (sublime.View): current view

        Returns:
            str: text that the next line contains
        """
        (row, _) = SublBridge.cursor_pos(view)
        point_on_next_line = view.text_point(row, 0)
        line = view.line(point_on_next_line)
        return view.substr(line)


class PosStatus:

    """Enum class for position status

    Attributes:
        COMPLETION_NEEDED (int): completion needed
        COMPLETION_NOT_NEEDED (int): completion not needed
        WRONG_TRIGGER (int): trigger is wrong
    """
    COMPLETION_NEEDED = 0
    COMPLETION_NOT_NEEDED = 1
    WRONG_TRIGGER = 2


class File:
    """Class that handles a path to the file
    """
    __full_path = None
    __last_seen_modification = 0

    def __init__(self, file_path=None):
        """Initialize a new file and create if needed

        Args:
            file_path (str, optional): generate file object from this path
        """
        if not file_path or not path:
            # leave the object unitialized
            log.error(" path not initialized!")
            return
        self.__full_path = path.abspath(file_path)
        # initialize the file
        open(self.__full_path, 'a+').close()

    def full_path(self):
        """Get full path to file.

        Returns:
            str: full path
        """
        return self.__full_path

    def folder(self):
        """Get parent folder to the file.

        Returns:
            str: parent folder of a file
        """
        return path.dirname(self.__full_path)

    def loaded(self):
        """Is the file loaded?
        """
        if self.__full_path:
            return True
        return False

    def was_modified(self):
        """Was the file modified since the last access?

        Returns:
            bool: True if modified, False if not. Creation is modification.
        """
        if not self.loaded():
            return False
        actual_modification_time = path.getmtime(self.__full_path)
        log.debug(" last mod: %s, actual mod: %s",
                  self.__last_seen_modification, actual_modification_time)
        if actual_modification_time > self.__last_seen_modification:
            self.__last_seen_modification = actual_modification_time
            return True
        return False

    @staticmethod
    def search(file_name, from_folder, to_folder, search_content=None):
        """search for a file up the tree

        Args:
            file_name (TYPE): Description
            from_folder (str): path to folder where we start the search
            to_folder (str): path to folder we should not go beyond
            search_content (None, optional): Description

        Returns:
            File: found file
        """
        log.info(" searching '%s' from '%s' to '%s'",
                 file_name, from_folder, to_folder)
        current_folder = from_folder
        one_past_stop_folder = path.dirname(to_folder)
        while current_folder != one_past_stop_folder:
            for file in listdir(current_folder):
                if file == file_name:
                    found_file = File(path.join(current_folder, file))
                    log.info(" found '%s' file: %s",
                             file_name, found_file.full_path())
                    if search_content:
                        if File.contains(found_file.full_path(),
                                         search_content):
                            return found_file
                        else:
                            log.info(" skipping file '%s'. ", found_file)
                            log.info(" no line starts with: '%s'",
                                     search_content)
                            continue
                    # this is reached only if we don't search any content
                    return found_file<commit_msg>debugging<commit_after>"""This module contains various tools

Attributes:
    log (logging): logger for this module
    OSX_CLANG_VERSION_DICT (dict): mapping from version number of OSX clang
        to the one of llvm clang.
        Taken from here: https://gist.github.com/yamaya/2924292
    PKG_NAME (str): this package name
"""
from os import path
from os import makedirs
from os import listdir

import sublime
import logging
import tempfile

import re

PKG_NAME = path.basename(path.dirname(path.dirname(__file__)))

OSX_CLANG_VERSION_DICT = {
    '4.2': '3.2',
    '5.0': '3.3',
    '5.1': '3.4',
    '6.0': '3.5',
    '6.1': '3.6',
    '7.0': '3.7',
    '7.3': '3.7'
}

log = logging.getLogger(__name__)


class SublBridge:

    """A small help class that bridges with sublime (maybe will grow)

    Attributes:
        NO_DEFAULT_COMPLETIONS (TYPE): Description
    """

    NO_DEFAULT_COMPLETIONS = sublime.INHIBIT_WORD_COMPLETIONS \
        | sublime.INHIBIT_EXPLICIT_COMPLETIONS

    @staticmethod
    def cursor_pos(view):
        """Get current cursor position. Returns position of the first cursor if
        multiple are present

        Args:
            view (sublime.View): current view

        Returns:
            (row, col): tuple of row and col for cursor position
        """
        pos = view.sel()
        if len(pos) < 1:
            # something is wrong
            return None
        (row, col) = view.rowcol(pos[0].a)
        row += 1
        col += 1
        return (row, col)

    @staticmethod
    def next_line(view):
        """Get next line as text

        Args:
            view (sublime.View): current view

        Returns:
            str: text that the next line contains
        """
        (row, _) = SublBridge.cursor_pos(view)
        point_on_next_line = view.text_point(row, 0)
        line = view.line(point_on_next_line)
        return view.substr(line)


class PosStatus:

    """Enum class for position status

    Attributes:
        COMPLETION_NEEDED (int): completion needed
        COMPLETION_NOT_NEEDED (int): completion not needed
        WRONG_TRIGGER (int): trigger is wrong
    """
    COMPLETION_NEEDED = 0
    COMPLETION_NOT_NEEDED = 1
    WRONG_TRIGGER = 2


class File:
    """Class that handles a path to the file
    """
    __full_path = None
    __last_seen_modification = 0

    def __init__(self, file_path=None):
        """Initialize a new file and create if needed

        Args:
            file_path (str, optional): generate file object from this path
        """
        if not file_path or not path:
            # leave the object unitialized
            log.error(" path not initialized!")
            return
        self.__full_path = path.abspath(file_path)
        # initialize the file
        open(self.__full_path, 'a+').close()

    def full_path(self):
        """Get full path to file.

        Returns:
            str: full path
        """
        return self.__full_path

    def folder(self):
        """Get parent folder to the file.

        Returns:
            str: parent folder of a file
        """
        return path.dirname(self.__full_path)

    def loaded(self):
        """Is the file loaded?
        """
        if self.__full_path:
            return True
        return False

    def was_modified(self):
        """Was the file modified since the last access?

        Returns:
            bool: True if modified, False if not. Creation is modification.
        """
        if not self.loaded():
            return False
        actual_modification_time = path.getmtime(self.__full_path)
        log.debug(" last mod: %s, actual mod: %s",
                  self.__last_seen_modification, actual_modification_time)
        if actual_modification_time > self.__last_seen_modification:
            self.__last_seen_modification = actual_modification_time
            return True
        return False

    @staticmethod
    def search(file_name, from_folder, to_folder, search_content=None):
        """search for a file up the tree

        Args:
            file_name (TYPE): Description
            from_folder (str): path to folder where we start the search
            to_folder (str): path to folder we should not go beyond
            search_content (None, optional): Description

        Returns:
            File: found file
        """
        log.info(" searching '%s' from '%s' to '%s'",
                 file_name, from_folder, to_folder)
        current_folder = from_folder
        one_past_stop_folder = path.dirname(to_folder)
        while current_folder != one_past_stop_folder:
            for file in listdir(current_folder):
                if file == file_name:
                    log.info(" looking at: %s", path.join(current_folder, file))
                    found_file = File(path.join(current_folder, file))
                    log.info(" found '%s' file: %s",
                             file_name, found_file.full_path())
                    if search_content:
                        if File.contains(found_file.full_path(),
                                         search_content):
                            return found_file
                        else:
                            log.info(" skipping file '%s'. ", found_file)
                            log.info(" no line starts with: '%s'",
                                     search_content)
                            continue
                    # this is reached only if we don't search any content
                    return found_file
{'fraction_non_alphanumeric': 0.08611136342992097, 'fraction_numerical': 0.00799345989644836, 'mean_word_length': 1.8238009746088741, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '7412389', 'n_tokens_mistral': 3149, 'n_tokens_neox': 3041, 'n_words': 931}