<commit_before># -*- coding: utf-8 -*-

import os
import contextlib

from PyQt5 import QtCore

from . import __app_name__
from . import helperutils


def _qsettings_group_factory(settings: QtCore.QSettings):
    @contextlib.contextmanager
    def qsettings_group_context(group_name: str):
        settings.beginGroup(group_name)
        yield settings
        settings.endGroup()

    return qsettings_group_context


class SettingsMeta(type):
    _instance = None

    def __call__(cls, *args, **kwargs):
        if cls._instance is None:
            cls._instance = super(SettingsMeta, cls).__call__(*args, **kwargs)
        return cls._instance


class Settings(metaclass=SettingsMeta):
    """Stores application settings
    """

    def __init__(self, parent: QtCore.QObject = None):
        self._filename = os.path.normpath(
            os.path.join(helperutils.get_app_config_dir(), __app_name__ + '.ini'))

        self._settings = QtCore.QSettings(self._filename, QtCore.QSettings.IniFormat, parent)
        self._settings_group = _qsettings_group_factory(self._settings)

    @property
    def filename(self):
        return self._filename

    @property
    def group(self):
        return self._settings_group<commit_msg>Add "s" attr for QSettings<commit_after># -*- coding: utf-8 -*-

import os
import contextlib

from PyQt5 import QtCore

from . import __app_name__
from . import helperutils


def _qsettings_group_factory(settings: QtCore.QSettings):
    @contextlib.contextmanager
    def qsettings_group_context(group_name: str):
        settings.beginGroup(group_name)
        yield settings
        settings.endGroup()

    return qsettings_group_context


class SettingsMeta(type):
    _instance = None

    def __call__(cls, *args, **kwargs):
        if cls._instance is None:
            cls._instance = super(SettingsMeta, cls).__call__(*args, **kwargs)
        return cls._instance


class Settings(metaclass=SettingsMeta):
    """Stores application settings
    """

    def __init__(self, parent: QtCore.QObject = None):
        self._filename = os.path.normpath(
            os.path.join(helperutils.get_app_config_dir(), __app_name__ + '.ini'))

        self._settings = QtCore.QSettings(self._filename, QtCore.QSettings.IniFormat, parent)
        self._settings_group = _qsettings_group_factory(self._settings)

    @property
    def filename(self):
        return self._filename

    @property
    def s(self):
        return self._settings

    @property
    def group(self):
        return self._settings_group
{'fraction_non_alphanumeric': 0.09555642941407787, 'fraction_numerical': 0.0015729453401494297, 'mean_word_length': 3.198019801980198, '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': '1277704', 'n_tokens_mistral': 752, 'n_tokens_neox': 736, 'n_words': 166}