Ejemplo n.º 1
0
    def isRelevant(cls):
        """Check whether plugin might be required.

        Returns:
            True if this is a standalone compilation.
        """
        return isStandaloneMode()
Ejemplo n.º 2
0
    def isRelevant(cls):
        """One time only check: may this plugin be required?

        Returns:
            True if this is a standalone compilation.
        """
        return isStandaloneMode()
Ejemplo n.º 3
0
    def createPreModuleLoadCode(self, module):
        """Method called when a module is being imported.

        Notes:
            If full name equals to the binding we insert code to include the dist
            folder in the 'PATH' environment variable (on Windows only).

        Args:
            module: the module object
        Returns:
            Code to insert and descriptive text (tuple), or (None, None).
        """

        # This is only relevant on standalone mode for Windows
        if not isStandaloneMode():
            return

        full_name = module.getFullName()

        if full_name == self.binding_name and isWin32Windows():
            code = """import os
path = os.environ.get("PATH", "")
if not path.startswith(__nuitka_binary_dir):
    os.environ["PATH"] = __nuitka_binary_dir + ";" + path
"""
            yield (
                code,
                "Adding binary folder to runtime 'PATH' environment variable for proper Qt loading.",
            )
Ejemplo n.º 4
0
 def wrapped(*args, **kwargs):
     if isStandaloneMode():
         return func(*args, **kwargs)
     else:
         if inspect.isgeneratorfunction(func):
             return ()
         else:
             return None
Ejemplo n.º 5
0
 def _getImportNameErrorString(module, module_name, name):
     if python_version < 0x340:
         return "cannot import name %s" % name
     if python_version < 0x370:
         return "cannot import name %r" % name
     elif isStandaloneMode():
         return "cannot import name %r from %r" % (name, module_name)
     else:
         return "cannot import name %r from %r (%s)" % (
             name,
             module_name,
             module.__file__ if hasattr(module, "__file__") else "unknown location",
         )
Ejemplo n.º 6
0
def demoteSourceCodeToBytecode(module_name, source_code, filename):
    # Second chance for plugins to modify source code just before turning it
    # to bytecode.
    source_code = Plugins.onFrozenModuleSourceCode(module_name=module_name,
                                                   is_package=False,
                                                   source_code=source_code)

    if isStandaloneMode():
        filename = module_name.asPath() + ".py"

    bytecode = compileSourceToBytecode(source_code, filename)

    bytecode = Plugins.onFrozenModuleBytecode(module_name=module_name,
                                              is_package=False,
                                              bytecode=bytecode)

    return marshal.dumps(bytecode)
Ejemplo n.º 7
0
    def createPostModuleLoadCode(self, module):
        """Create code to load after a module was successfully imported.

        For Qt we need to set the library path to the distribution folder
        we are running from. The code is immediately run after the code
        and therefore makes sure it's updated properly.
        """

        # Only in standalone mode, this will be needed.
        if not isStandaloneMode():
            return

        full_name = module.getFullName()

        if full_name == "%s.QtCore" % self.binding_name:
            code = """\
from __future__ import absolute_import

from %(package_name)s import QCoreApplication
import os

QCoreApplication.setLibraryPaths(
    [
        os.path.join(
           os.path.dirname(__file__),
           "qt-plugins"
        )
    ]
)

os.environ["QML2_IMPORT_PATH"] = os.path.join(
    os.path.dirname(__file__),
    "qml"
)

""" % {
                "package_name": full_name
            }

            yield (
                code,
                """\
Setting Qt library path to distribution folder. We need to avoid loading target
system Qt plugins, which may be from another Qt version.""",
            )
Ejemplo n.º 8
0
    def onModuleEncounter(self, module_filename, module_name, module_kind):
        top_package_name = module_name.getTopLevelPackageName()

        if isStandaloneMode():
            if (top_package_name in _qt_binding_names
                    and top_package_name != self.binding_name):
                if top_package_name not in self.warned_about:
                    self.info(
                        """\
Unwanted import of '%(unwanted)s' that conflicts with '%(binding_name)s' encountered, preventing
its use. As a result an "ImportError" might be given at run time. Uninstall it for full compatible
behavior with the uncompiled code to debug it.""" % {
                            "unwanted": top_package_name,
                            "binding_name": self.binding_name,
                        })

                    self.warned_about.add(top_package_name)

                return (
                    False,
                    "Not included due to potentially conflicting Qt versions with selected Qt binding '%s'."
                    % self.binding_name,
                )
Ejemplo n.º 9
0
def copyDataFiles():
    """Copy the data files needed for standalone distribution.

    Notes:
        This is for data files only, not DLLs or even extension modules,
        those must be registered as entry points, and would not go through
        necessary handling if provided like this.
    """

    for included_datafile in getIncludedDataFiles():
        # TODO: directories should be resolved to files.
        if (not isinstance(included_datafile, (IncludedDataFile))
                or included_datafile.needsCopy()):
            if shallMakeModule():
                options_logger.sysexit("""\
Error, data files for modules must be done via wheels, or commercial plugins '--embed-*' options."""
                                       )
            elif not isStandaloneMode():
                options_logger.sysexit("""\
Error, data files cannot be included in accelerated mode unless using commercial plugins '--embed-*' options."""
                                       )

            _handleDataFile(included_datafile, )
Ejemplo n.º 10
0
 def isRelevant(cls):
     return isStandaloneMode()
Ejemplo n.º 11
0
def _handleDataFile(included_datafile):
    """Handle a data file."""
    tracer = included_datafile.tracer

    if not isinstance(included_datafile,
                      (IncludedDataFile, IncludedDataDirectory)):
        tracer.sysexit(
            "Error, can only accept 'IncludedData*' objects from plugins.")

    if not isStandaloneMode():
        tracer.sysexit(
            "Error, package data files are only included in standalone or onefile mode."
        )

    dist_dir = getStandaloneDirectoryPath()

    if included_datafile.kind == "empty_dirs":
        tracer.info("Included empty directories '%s' due to %s." % (
            ",".join(included_datafile.dest_path),
            included_datafile.reason,
        ))

        for sub_dir in included_datafile.dest_path:
            created_dir = os.path.join(dist_dir, sub_dir)

            makePath(created_dir)
            putTextFileContents(filename=os.path.join(created_dir,
                                                      ".keep_dir.txt"),
                                contents="")
    elif included_datafile.kind == "data_blob":
        dest_path = os.path.join(dist_dir, included_datafile.dest_path)
        makePath(os.path.dirname(dest_path))

        putTextFileContents(filename=dest_path,
                            contents=included_datafile.data)

        tracer.info("Included data file '%s' due to %s." % (
            included_datafile.dest_path,
            included_datafile.reason,
        ))
    elif included_datafile.kind == "data_file":
        dest_path = os.path.join(dist_dir, included_datafile.dest_path)

        tracer.info("Included data file '%s' due to %s." % (
            included_datafile.dest_path,
            included_datafile.reason,
        ))

        makePath(os.path.dirname(dest_path))
        copyFileWithPermissions(source_path=included_datafile.source_path,
                                dest_path=dest_path)
    elif included_datafile.kind == "data_dir":
        dest_path = os.path.join(dist_dir, included_datafile.dest_path)
        makePath(os.path.dirname(dest_path))

        copied = []

        for filename in getFileList(
                included_datafile.source_path,
                ignore_dirs=included_datafile.ignore_dirs,
                ignore_filenames=included_datafile.ignore_filenames,
                ignore_suffixes=included_datafile.ignore_suffixes,
                only_suffixes=included_datafile.only_suffixes,
                normalize=included_datafile.normalize,
        ):
            filename_relative = os.path.relpath(filename,
                                                included_datafile.source_path)

            filename_dest = os.path.join(dest_path, filename_relative)
            makePath(os.path.dirname(filename_dest))

            copyFileWithPermissions(source_path=filename,
                                    dest_path=filename_dest)

            copied.append(filename_relative)

        tracer.info("Included data dir %r with %d files due to: %s." % (
            included_datafile.dest_path,
            len(copied),
            included_datafile.reason,
        ))
    else:
        assert False, included_datafile