<commit_before>'''
Pyinstaller hooks
=================

Module that exports pyinstaller related methods and parameters.

Hooks
-----

PyInstaller comes with a default hook for kivy that lists the indirectly
imported modules that pyinstaller would not find on its own using
:func:`get_deps_all`. :func:`hookspath` returns the path to an alternate kivy
hook, ``kivy/tools/packaging/pyinstaller_hooks/kivy-hook.py`` that does not
add these dependencies to its list of hidden imports and they have to be
explicitly included instead.

One can overwrite the default hook by providing on the command line the
``--additional-hooks-dir=HOOKSPATH`` option. Because although the default
hook will still run, the `important global variables
<https://pythonhosted.org/PyInstaller/#hook-global-variables>`_, e.g.
``excludedimports`` and ``hiddenimports`` will be overwritten by the
new hook, if set there.

Additionally, one can add a hook to be run after the default hook by
passing e.g. ``hookspath=[HOOKSPATH]`` to the ``Analysis`` class. In both
cases, ``HOOKSPATH`` is the path to a directory containing a file named
``hook-kivy.py`` that is the pyinstaller hook for kivy to be processed
after the default hook.

hiddenimports
-------------

When a module is imported indirectly, e.g. with ``__import__``, pyinstaller
won't know about it and the module has to be added through ``hiddenimports``.

``hiddenimports`` and other hook variables can be specified within a hook as
described above. Also, these variable can be passed to ``Analysis`` and their
values are then appended to the hook's values for these variables.

Most of kivy's core modules, e.g. video are imported indirectly and therefore
need to be added in hiddenimports. The default PyInstaller hook adds all the
providers. To overwrite, a modified kivy-hook similar to the default hook, such
as :func:`hookspath` that only imports the desired modules can be added. One
then uses :func:`get_deps_minimal` or :func:`get_deps_all` to get the list of
modules and adds them manually in a modified hook or passes them to
``Analysis`` in the spec file.

Hook generator
--------------

:mod:`pyinstaller_hooks` includes a tool to generate a hook which lists
all the provider modules in a list so that one can manually comment out
the providers not to be included. To use, do::

    python -m kivy.tools.packaging.pyinstaller_hooks hook filename

``filename`` is the name and path of the hook file to create. If ``filename``
is not provided the hook is printed to the terminal.
'''

import os
import sys
import pkgutil
import logging
from os.path import dirname, join
import importlib
import subprocess
import re
import glob

import kivy
try:
    from kivy import deps as old_deps
except ImportError:
    old_deps = None
try:
    import kivy_deps
except ImportError:
    kivy_deps = None
from kivy.factory import Factory
from PyInstaller.depend import bindepend

from os import environ
if 'KIVY_DOC' not in environ:
    from PyInstaller.compat import modname_tkinter
    from PyInstaller.utils.hooks import collect_submodules

    curdir = dirname(__file__)

    kivy_modules = [
        'xml.etree.cElementTree',
        'kivy.core.gl'
    ] + collect_submodules('kivy.graphics')
    '''List of kivy modules that are always needed as hiddenimports of
    pyinstaller.
    '''

    excludedimports = [modname_tkinter, '_tkinter', 'twisted']
    '''List of excludedimports that should always be excluded from
    pyinstaller.
    '''

    datas = [
        (kivy.kivy_data_dir,
         os.path.join('kivy_install', os.path.basename(kivy.kivy_data_dir))),
        (kivy.kivy_modules_dir,
         os.path.join('kivy_install', os.path.basename(kivy.kivy_modules_dir)))<commit_msg>List kivy.weakmethod because pyinstaller doesn't see into cython files.<commit_after>'''
Pyinstaller hooks
=================

Module that exports pyinstaller related methods and parameters.

Hooks
-----

PyInstaller comes with a default hook for kivy that lists the indirectly
imported modules that pyinstaller would not find on its own using
:func:`get_deps_all`. :func:`hookspath` returns the path to an alternate kivy
hook, ``kivy/tools/packaging/pyinstaller_hooks/kivy-hook.py`` that does not
add these dependencies to its list of hidden imports and they have to be
explicitly included instead.

One can overwrite the default hook by providing on the command line the
``--additional-hooks-dir=HOOKSPATH`` option. Because although the default
hook will still run, the `important global variables
<https://pythonhosted.org/PyInstaller/#hook-global-variables>`_, e.g.
``excludedimports`` and ``hiddenimports`` will be overwritten by the
new hook, if set there.

Additionally, one can add a hook to be run after the default hook by
passing e.g. ``hookspath=[HOOKSPATH]`` to the ``Analysis`` class. In both
cases, ``HOOKSPATH`` is the path to a directory containing a file named
``hook-kivy.py`` that is the pyinstaller hook for kivy to be processed
after the default hook.

hiddenimports
-------------

When a module is imported indirectly, e.g. with ``__import__``, pyinstaller
won't know about it and the module has to be added through ``hiddenimports``.

``hiddenimports`` and other hook variables can be specified within a hook as
described above. Also, these variable can be passed to ``Analysis`` and their
values are then appended to the hook's values for these variables.

Most of kivy's core modules, e.g. video are imported indirectly and therefore
need to be added in hiddenimports. The default PyInstaller hook adds all the
providers. To overwrite, a modified kivy-hook similar to the default hook, such
as :func:`hookspath` that only imports the desired modules can be added. One
then uses :func:`get_deps_minimal` or :func:`get_deps_all` to get the list of
modules and adds them manually in a modified hook or passes them to
``Analysis`` in the spec file.

Hook generator
--------------

:mod:`pyinstaller_hooks` includes a tool to generate a hook which lists
all the provider modules in a list so that one can manually comment out
the providers not to be included. To use, do::

    python -m kivy.tools.packaging.pyinstaller_hooks hook filename

``filename`` is the name and path of the hook file to create. If ``filename``
is not provided the hook is printed to the terminal.
'''

import os
import sys
import pkgutil
import logging
from os.path import dirname, join
import importlib
import subprocess
import re
import glob

import kivy
try:
    from kivy import deps as old_deps
except ImportError:
    old_deps = None
try:
    import kivy_deps
except ImportError:
    kivy_deps = None
from kivy.factory import Factory
from PyInstaller.depend import bindepend

from os import environ
if 'KIVY_DOC' not in environ:
    from PyInstaller.compat import modname_tkinter
    from PyInstaller.utils.hooks import collect_submodules

    curdir = dirname(__file__)

    kivy_modules = [
        'xml.etree.cElementTree',
        'kivy.core.gl',
        'kivy.weakmethod',
    ] + collect_submodules('kivy.graphics')
    '''List of kivy modules that are always needed as hiddenimports of
    pyinstaller.
    '''

    excludedimports = [modname_tkinter, '_tkinter', 'twisted']
    '''List of excludedimports that should always be excluded from
    pyinstaller.
    '''

    datas = [
        (kivy.kivy_data_dir,
         os.path.join('kivy_install', os.path.basename(kivy.kivy_data_dir))),
        (kivy.kivy_modules_dir,
         os.path.join('kivy_install', os.path.basename(kivy.kivy_modules_dir)))
{'fraction_non_alphanumeric': 0.0844397238449283, 'fraction_numerical': 0.0, 'mean_word_length': 4.107118644067796, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '7053147', 'n_tokens_mistral': 2231, 'n_tokens_neox': 2199, 'n_words': 934}