Example #1
0
 def setUp(self, package = HOOKUTILS_TEST_FILES):
     # Fun Python behavior: __import__('mod.submod') returns mod,
     # where as __import__('mod.submod', fromlist = [a non-empty list])
     # returns mod.submod. See the docs on `__import__
     # <http://docs.python.org/library/functions.html#__import__>`_.
     self.mod_list = collect_submodules(__import__(package,
                                                   fromlist = ['']))
Example #2
0
#-----------------------------------------------------------------------------
# Copyright (c) 2013, PyInstaller Development Team.
#
# Distributed under the terms of the GNU General Public License with exception
# for distributing bootloader.
#
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------


from PyInstaller.utils.hooks.hookutils import collect_submodules, collect_data_files

hiddenimports = collect_submodules('sphinx.ext')
datas = collect_data_files('sphinx')
Example #3
0
from PyInstaller.utils.hooks.hookutils import collect_submodules

hiddenimports = collect_submodules('dns')
Example #4
0
def create_py3_base_library(libzip_filename):
    """
    Package basic Python modules into .zip file. The .zip file with basic
    modules is necessary to have on PYTHONPATH for initializing libpython3
    in order to run the frozen executable with Python 3.
    """
    logger.info("Creating base_library.zip for Python 3")

    graph = modulegraph.ModuleGraph(implies=(), debug=1)  # Do not include any default modules in dependencies.
    find_modules.find_needed_modules(
        mf=graph,
        includes=[
            "io",
            "warnings",  # Required by run-time option like ('W ignore', None, 'OPTION')
            # Include all encodings.
        ]
        + collect_submodules("encodings"),
    )

    # TODO Replace this function with something better or something from standard Python library.
    # Helper functions.
    def _write_long(f, x):
        """
        Write a 32-bit int to a file in little-endian order.
        """
        f.write(bytes([x & 0xFF, (x >> 8) & 0xFF, (x >> 16) & 0xFF, (x >> 24) & 0xFF]))

    # Constants same for all .pyc files.

    try:
        # Remove .zip from previous run.
        if os.path.exists(libzip_filename):
            os.remove(libzip_filename)
        logger.debug("Adding python files to base_library.zip")
        # Class zipfile.PyZipFile is not suitable for PyInstaller needs.
        with zipfile.ZipFile(libzip_filename, mode="w") as zf:
            zf.debug = 3
            for mod in graph.flatten():
                if type(mod) in (modulegraph.SourceModule, modulegraph.Package):
                    st = os.stat(mod.filename)
                    timestamp = int(st.st_mtime)
                    size = st.st_size & 0xFFFFFFFF
                    # Name inside a zip archive.
                    # TODO use .pyo suffix if optimize flag is enabled.
                    if type(mod) is modulegraph.Package:
                        new_name = mod.identifier.replace(".", os.sep) + os.sep + "__init__" + ".pyc"
                    else:
                        new_name = mod.identifier.replace(".", os.sep) + ".pyc"

                    # Write code to a file.
                    # This code is similar to py_compile.compile().
                    with io.BytesIO() as fc:
                        # Prepare all data in byte stream file-like object.
                        fc.write(BYTECODE_MAGIC)
                        _write_long(fc, timestamp)
                        _write_long(fc, size)
                        marshal.dump(mod.code, fc)
                        zf.writestr(new_name, fc.getvalue())

    except Exception as e:
        logger.error("base_library.zip could not be created!")
Example #5
0
 def test_6(self):
     self.mod_list = collect_submodules(HOOKUTILS_TEST_FILES +
                                        '.subpkg')
     self.assert_subpackge_equal()
Example #6
0
 def test_5(self):
     self.mod_list = collect_submodules(HOOKUTILS_TEST_FILES)
     self.test_3()
Example #7
0
 def test_0(self):
     # os is a module, not a package.
     with self.assertRaises(AttributeError):
         collect_submodules(__import__('os'))
Example #8
0
#-----------------------------------------------------------------------------
# Copyright (c) 2013, PyInstaller Development Team.
#
# Distributed under the terms of the GNU General Public License with exception
# for distributing bootloader.
#
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------


from PyInstaller.utils.hooks.hookutils import collect_submodules

hiddenimports = collect_submodules('sqlite3')
Example #9
0
# -----------------------------------------------------------------------------
# Copyright (c) 2013, PyInstaller Development Team.
#
# Distributed under the terms of the GNU General Public License with exception
# for distributing bootloader.
#
# The full license is in the file COPYING.txt, distributed with this software.
# -----------------------------------------------------------------------------


from PyInstaller.utils.hooks.hookutils import collect_submodules, collect_data_files

hiddenimports = (
    collect_submodules("docutils.languages")
    + collect_submodules("docutils.writers")
    + collect_submodules("docutils.parsers.rst.languages")
    + collect_submodules("docutils.parsers.rst.directives")
)
datas = collect_data_files("docutils")