<commit_before># -*- coding: utf-8 -*-
"""
@file
@brief Default values for the Sphinx configuration.
"""
import sys
import os
import datetime
import warnings
from .style_css_template import style_figure_notebook
from .._cst.cst_sphinx import (
    get_epkg_dictionary, latex_preamble, get_intersphinx_mapping)


def set_sphinx_variables(fileconf, module_name, author, year, theme, theme_path, ext_locals,
                         add_extensions=None, bootswatch_theme="spacelab", bootswatch_navbar_links=None,
                         description_latex="", use_mathjax=False, use_lunrsearch=False,
                         enable_disabled_parts="enable_disabled_documented_pieces_of_code",
                         sharepost="facebook-linkedin-twitter-20-body", custom_style=None,
                         extlinks=None, github_user=None, github_repo=None, title=None,
                         book=True, link_resolve=None, nblayout='classic', doc_version=None,
                         branch='master', callback_begin=None):
    """
    Defines variables for :epkg:`Sphinx`.

    @param      fileconf                location of the configuration file
    @param      module_name             name of the module
    @param      author                  author
    @param      year                    year
    @param      theme                   theme to use
    @param      theme_path              theme path (sets ``html_theme_path``)
    @param      ext_locals              context (see `locals <https://docs.python.org/2/library/functions.html#locals>`_)
    @param      add_extensions          additional extensions
    @param      bootswatch_theme        for example, ``spacelab``, look at
                                        `spacelab <https://bootswatch.com/spacelab/>`_
    @param      bootswatch_navbar_links see `sphinx-bootstrap-theme <https://ryan-roemer.github.io/
                                        sphinx-bootstrap-theme/README.html>`_
    @param      description_latex       description latex
    @param      use_mathjax             set up the documentation to use mathjax,
                                        see `sphinx.ext.mathjax
                                        <https://www.sphinx-doc.org/en/master/usage/extensions/math.html>`_,
                                        default option is True
    @param      use_lunrsearch          suggest autocompletion in sphinx,
                                        see `sphinxcontrib-lunrsearch <https://github.com/rmcgibbo/
                                        sphinxcontrib-lunrsearch>`_
    @param      enable_disabled_parts   @see fn remove_undesired_part_for_documentation
    @param      sharepost               add share button to share blog post on usual networks
    @param      custom_style            custom style sheet
    @param      extlinks                parameter `extlinks <https://www.sphinx-doc.org/en/master/ext/extlinks.html#confval-extlinks>`_,
                                        example: ``{'issue': ('https://github.com/sdpython/pyquickhelper/issues/%s', 'issue ')}``
    @param      github_user             git(hub) user
    @param      github_repo             git(hub) project
    @param      title                   if not None, use *title* instead of *module_name* as a title
    @param      book                    the output is a book
    @param      link_resolve            url where the documentation is published,
                                        used for parameter *linkcode_resolve*
    @param      nblayout                ``'classic'`` or ``'table'``, specifies the layout for
                                        the notebook gallery
    @param      doc_version             if not None, overwrites the current version
    @param      branch                  default branch (`'master'` by default)
    @param      callback_begin          function to call when the documentation is generated

    If the parameter *custom_style* is not None, it will call ``app.add_css_file(custom_style)``
    in the setup.

    .. exref::
        :title: Simple configuration file for Sphinx

        We assume a module is configurated using the same
        structure as `pyquickhelper <https://github.com/sdpython/pyquickhelper/>`_.
        The file ``conf.py`` could just contain:

        ::

            # -*- coding: utf-8 -*-
            import sys, os, datetime, re
            import solar_theme
            from pyquickhelper.helpgen.default_conf import set_sphinx_variables

            sys.path.insert(0, os.path.abspath(os.path.join(os.path.split(__file__)[0])))
            set_sphinx_variables(__file__, "pyquickhelper", "<NAME>", 2014,
                                 "solar_theme", solar_theme.theme_path, locals())

            # custom settings
            ...

        *setup.py* must contain a string such as ``__version__ = 3.4``.
        Close to the setup, there must be a file ``version.txt``.
        You overwrite a value by giving a variable another value after the fucntion is called.

        Some parts of the code can be disabled before generating the documentation.
        Those parts are surrounded by::

            # -- HELP BEGIN EXCLUDE --
            import module
            # -- HELP END EXCLUDE --

        If *enable_disabled_parts* is set to a string, these sections will become::

            # -- HELP BEGIN EXCLUDE --
            if hasattr(sys, <enable_disabled_parts>) and sys.<enable_disabled_parts>:
                import module
            # -- HELP END EXCLUDE --

    This example shows what variables this functions sets.

    .. runpython::
        :showcode:

        import alabaster
        from pyquickhelper.helpgen.default_conf import set_sphinx_variables

        import pyquickhelper  # replace by your module

        ext_locals = {}
        set_sphinx_variables("this_file_conf.py",
                             "pyquickhelper",  # replace by your module
                             "module_author", 2019,
                             "readable", alabaster.get_path(),
                             ext_locals, extlinks=dict(
                                 issue=('https://github.com/sdpython/module_name/issues/%s', 'issue')),
                             title="module_name")

        import pprint
        pprint.pprint(ext_locals)

    .. versionchanged:: 1.9
        Uses ``jupyter_sphinx>=0.2``.
    """
    # sphinx_gallery only supports matplotlib.use('agg')
    # and it must be done first.
    try:
        import sphinx_gallery
        import sphinx_gallery.gen_rst
    except ImportError:  # pragma: no cover
        warnings.warn("ImportError: sphinx-gallery.", ImportWarning)
    except ValueError:  # pragma: no cover
        warnings.warn(
            "ImportError: sphinx-gallery.get_rst fails.", ImportWarning)

    # version .txt
    dirconf = os.path.abspath(os.path.dirname(fileconf))
    version_file = os.path.join(dirconf, "..", "..", "..", "version.txt")
    if not os.path.exists(version_file):
        warnings.warn(  # pragma: no cover
            "File '{0}' must contain the commit number (or last part of the version).".format(
                version_file), UserWarning)
        first_line = "0"  # pragma: no cover
    else:
        first_line = get_first_line(version_file)

    # language
    language = "en"

    # main version
    if doc_version is None:
        mod = sys.modules.get(module_name, None)
        if mod is None:  # pragma: no cover
            import importlib
            try:
                mod = importlib.import_module(module_name)
            except (ImportError, ModuleNotFoundError):
                mod = None
            if mod is None:
                raise RuntimeError(
                    "Unknown module version. You should import '{0}' or specify "
                    "'doc_version'.".format(
                        module_name))
        try:
            version = mod.__version__
        except AttributeError:  # pragma: no cover
            raise AttributeError("Unable to find attribute '__version__' in module '{}', "
                                 "__file__='{}'\n--PATH--\n{}".format(
                                     module_name, mod.__file__, "\n".join(sys.path)))
    else:
        version = doc_version  # pragma: no cover

    # settings sphinx
    pygments_style = 'sphinx'

    # personnalization
    project_var_name = module_name  # pylint: disable=W0127
    author = author  # pylint: disable=W0127
    nblayout = nblayout  # pylint: disable=W0127
    year = str(year)
    modindex_common_prefix = [project_var_name + ".", ]
    project = (project_var_name + ' documentation') if title is None else title
    copyright = str(year) + ", " + author
    release = (version if len(version.split('.')) < 3
               else "%s.%s" % (version, first_line))
    html_title = ("%s %s" % (project_var_name, release)
                  ) if title is None else title
    htmlhelp_basename = '%s_doc' % project_var_name
    enable_disabled_parts = enable_disabled_parts  # pylint: disable=W0127
<commit_msg>show less in default_conf.py<commit_after># -*- coding: utf-8 -*-
"""
@file
@brief Default values for the Sphinx configuration.
"""
import sys
import os
import datetime
import warnings
from .style_css_template import style_figure_notebook
from .._cst.cst_sphinx import (
    get_epkg_dictionary, latex_preamble, get_intersphinx_mapping)


def set_sphinx_variables(fileconf, module_name, author, year, theme, theme_path, ext_locals,
                         add_extensions=None, bootswatch_theme="spacelab", bootswatch_navbar_links=None,
                         description_latex="", use_mathjax=False, use_lunrsearch=False,
                         enable_disabled_parts="enable_disabled_documented_pieces_of_code",
                         sharepost="facebook-linkedin-twitter-20-body", custom_style=None,
                         extlinks=None, github_user=None, github_repo=None, title=None,
                         book=True, link_resolve=None, nblayout='classic', doc_version=None,
                         branch='master', callback_begin=None):
    """
    Defines variables for :epkg:`Sphinx`.

    @param      fileconf                location of the configuration file
    @param      module_name             name of the module
    @param      author                  author
    @param      year                    year
    @param      theme                   theme to use
    @param      theme_path              theme path (sets ``html_theme_path``)
    @param      ext_locals              context (see `locals <https://docs.python.org/2/library/functions.html#locals>`_)
    @param      add_extensions          additional extensions
    @param      bootswatch_theme        for example, ``spacelab``, look at
                                        `spacelab <https://bootswatch.com/spacelab/>`_
    @param      bootswatch_navbar_links see `sphinx-bootstrap-theme <https://ryan-roemer.github.io/
                                        sphinx-bootstrap-theme/README.html>`_
    @param      description_latex       description latex
    @param      use_mathjax             set up the documentation to use mathjax,
                                        see `sphinx.ext.mathjax
                                        <https://www.sphinx-doc.org/en/master/usage/extensions/math.html>`_,
                                        default option is True
    @param      use_lunrsearch          suggest autocompletion in sphinx,
                                        see `sphinxcontrib-lunrsearch <https://github.com/rmcgibbo/
                                        sphinxcontrib-lunrsearch>`_
    @param      enable_disabled_parts   @see fn remove_undesired_part_for_documentation
    @param      sharepost               add share button to share blog post on usual networks
    @param      custom_style            custom style sheet
    @param      extlinks                parameter `extlinks <https://www.sphinx-doc.org/en/master/ext/extlinks.html#confval-extlinks>`_,
                                        example: ``{'issue': ('https://github.com/sdpython/pyquickhelper/issues/%s', 'issue ')}``
    @param      github_user             git(hub) user
    @param      github_repo             git(hub) project
    @param      title                   if not None, use *title* instead of *module_name* as a title
    @param      book                    the output is a book
    @param      link_resolve            url where the documentation is published,
                                        used for parameter *linkcode_resolve*
    @param      nblayout                ``'classic'`` or ``'table'``, specifies the layout for
                                        the notebook gallery
    @param      doc_version             if not None, overwrites the current version
    @param      branch                  default branch (`'master'` by default)
    @param      callback_begin          function to call when the documentation is generated

    If the parameter *custom_style* is not None, it will call ``app.add_css_file(custom_style)``
    in the setup.

    .. exref::
        :title: Simple configuration file for Sphinx

        We assume a module is configurated using the same
        structure as `pyquickhelper <https://github.com/sdpython/pyquickhelper/>`_.
        The file ``conf.py`` could just contain:

        ::

            # -*- coding: utf-8 -*-
            import sys, os, datetime, re
            import solar_theme
            from pyquickhelper.helpgen.default_conf import set_sphinx_variables

            sys.path.insert(0, os.path.abspath(os.path.join(os.path.split(__file__)[0])))
            set_sphinx_variables(__file__, "pyquickhelper", "<NAME>", 2014,
                                 "solar_theme", solar_theme.theme_path, locals())

            # custom settings
            ...

        *setup.py* must contain a string such as ``__version__ = 3.4``.
        Close to the setup, there must be a file ``version.txt``.
        You overwrite a value by giving a variable another value after the fucntion is called.

        Some parts of the code can be disabled before generating the documentation.
        Those parts are surrounded by::

            # -- HELP BEGIN EXCLUDE --
            import module
            # -- HELP END EXCLUDE --

        If *enable_disabled_parts* is set to a string, these sections will become::

            # -- HELP BEGIN EXCLUDE --
            if hasattr(sys, <enable_disabled_parts>) and sys.<enable_disabled_parts>:
                import module
            # -- HELP END EXCLUDE --

    This example shows what variables this functions sets.

    .. runpython::
        :showcode:

        import alabaster
        from pyquickhelper.helpgen.default_conf import set_sphinx_variables

        import pyquickhelper  # replace by your module

        ext_locals = {}
        set_sphinx_variables("this_file_conf.py",
                             "pyquickhelper",  # replace by your module
                             "module_author", 2019,
                             "readable", alabaster.get_path(),
                             ext_locals, extlinks=dict(
                                 issue=('https://github.com/sdpython/module_name/issues/%s', 'issue')),
                             title="module_name")

        import pprint
        pprint.pprint(ext_locals)

    .. versionchanged:: 1.9
        Uses ``jupyter_sphinx>=0.2``.
    """
    # sphinx_gallery only supports matplotlib.use('agg')
    # and it must be done first.
    try:
        import sphinx_gallery
        import sphinx_gallery.gen_rst
    except ImportError:  # pragma: no cover
        warnings.warn("ImportError: sphinx-gallery.", ImportWarning)
    except ValueError:  # pragma: no cover
        warnings.warn(
            "ImportError: sphinx-gallery.get_rst fails.", ImportWarning)

    # version .txt
    dirconf = os.path.abspath(os.path.dirname(fileconf))
    version_file = os.path.join(dirconf, "..", "..", "..", "version.txt")
    if not os.path.exists(version_file):
        warnings.warn(  # pragma: no cover
            "File '{0}' must contain the commit number (or last part of the version).".format(
                version_file), UserWarning)
        first_line = "0"  # pragma: no cover
    else:
        first_line = get_first_line(version_file)

    # language
    language = "en"

    # main version
    if doc_version is None:
        mod = sys.modules.get(module_name, None)
        if mod is None:  # pragma: no cover
            import importlib
            try:
                mod = importlib.import_module(module_name)
            except (ImportError, ModuleNotFoundError):
                mod = None
            if mod is None:
                raise RuntimeError(
                    "Unknown module version. You should import '{0}' or specify "
                    "'doc_version'.".format(
                        module_name))
        try:
            version = mod.__version__
        except AttributeError:  # pragma: no cover
            raise AttributeError("Unable to find attribute '__version__' in module '{}', "
                                 "__file__='{}'\n--PATH--\n{}".format(
                                     module_name, mod.__file__, "\n".join(sys.path)))
    else:
        version = doc_version  # pragma: no cover

    # settings sphinx
    pygments_style = 'sphinx'

    # personnalization
    project_var_name = module_name  # pylint: disable=W0127
    author = author  # pylint: disable=W0127
    nblayout = nblayout  # pylint: disable=W0127
    year = str(year)
    modindex_common_prefix = [project_var_name + ".", ]
    project = (project_var_name + ' documentation') if title is None else title
    copyright = str(year) + ", " + author
    release = (version if len(version.split('.')) < 3
               else "%s.%s" % (version, first_line))
    html_title = ("%s %s" % (project_var_name, release)
                  ) if title is None else title
    htmlhelp_basename = '%s_doc' % project_var_name
    enable_disabled_parts = enable_disabled_parts  # pylint: disable=W0127

    html_show_copyright = False
    html_show_sphinx = False

{'fraction_non_alphanumeric': 0.08720197314332694, 'fraction_numerical': 0.0044943820224719105, 'mean_word_length': 1.8019041769041768, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 18, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 36, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4140851', 'n_tokens_mistral': 4983, 'n_tokens_neox': 4735, 'n_words': 1303}