<commit_before>import json
import os.path
from collections import Mapping, Sequence
from configparser import ConfigParser

from six import string_types

from .color_printer import ColorPrinter
from .util import get_file_name


class Base(ColorPrinter):

    def __init__(self, file_name=None, section=None, extender=None, colors=None):
        """Initialize config file name and section.

        The file name will be selected from the following list, in order
        of precedence:

            - Explicitly passed file name
            - If the environment variable `LOCAL_SETTINGS_FILE` is set,
              its value will be used
            - Otherwise, local.cfg in the current working directory will
              be used

        The section will be selected from the following list, in order
        of precedence:

            - Explicitly passed section
            - Section passed via file name (using file_name#section
              syntax)
            - The section that's being extended, if applicable
            - The only section in the file, *iff* there's exactly one
              section
            - [DEFAULT]

        """
        super(Base, self).__init__(colors)

        if not file_name:
            file_name = get_file_name()
            parsed_section = None
        elif '#' in file_name:
            file_name, parsed_section = file_name.rsplit('#', 1)
        else:
            parsed_section = None

        if section:
            pass
        elif parsed_section:
            section = parsed_section
        elif extender:
            section = extender.section
        else:
            parser = self._make_parser()
            with open(file_name) as fp:
                parser.read_file(fp)
            sections = parser.sections()
            if len(sections) == 1:<commit_msg>Fix relative path issue when extending<commit_after>import json
import os.path
from collections import Mapping, Sequence
from configparser import ConfigParser

from six import string_types

from .color_printer import ColorPrinter
from .util import get_file_name


class Base(ColorPrinter):

    def __init__(self, file_name=None, section=None, extender=None, colors=None):
        """Initialize config file name and section.

        The file name will be selected from the following list, in order
        of precedence:

            - Explicitly passed file name
            - If the environment variable `LOCAL_SETTINGS_FILE` is set,
              its value will be used
            - Otherwise, local.cfg in the current working directory will
              be used

        The section will be selected from the following list, in order
        of precedence:

            - Explicitly passed section
            - Section passed via file name (using file_name#section
              syntax)
            - The section that's being extended, if applicable
            - The only section in the file, *iff* there's exactly one
              section
            - [DEFAULT]

        """
        super(Base, self).__init__(colors)

        if not file_name:
            file_name = get_file_name()
            parsed_section = None
        elif '#' in file_name:
            file_name, parsed_section = file_name.rsplit('#', 1)
        else:
            parsed_section = None

        if extender and not os.path.isabs(file_name):
            # When a file is extended by another (the "extender"),
            # ensure that the path to the extended file is correct.
            file_name = os.path.join(os.path.dirname(extender.file_name), file_name)

        if section:
            pass
        elif parsed_section:
            section = parsed_section
        elif extender:
            section = extender.section
        else:
            parser = self._make_parser()
            with open(file_name) as fp:
                parser.read_file(fp)
            sections = parser.sections()
            if len(sections) == 1:
{'fraction_non_alphanumeric': 0.060821084642676125, 'fraction_numerical': 0.0010136847440446021, 'mean_word_length': 1.9258710155670868, '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': '317807', 'n_tokens_mistral': 990, 'n_tokens_neox': 962, 'n_words': 361}