aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside-tools/deploy/nuitka_helper.py
blob: fc0916276440c2d6a175076a723b47aa49a6ca10 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

import os
import sys
from pathlib import Path
from . import run_command


class Nuitka:
    """
    Wrapper class around the nuitka executable, enabling its usage through python code
    """

    def __init__(self, nuitka):
        self.nuitka = nuitka

    def create_executable(
        self, source_file: Path, extra_args: str, qml_files: list[Path], dry_run: bool
    ):
        extra_args = extra_args.split()
        qml_args = []
        if qml_files:
            # this includes "all" the plugins
            # FIXME: adding the "qml" plugin is equivalent to "all" because of dependencies
            # Ideally it should only add the specific qml plugins. eg: quick window, quick controls
            qml_args.append("--include-qt-plugins=all")
            qml_args.extend(
                [f"--include-data-files={qml_file}=./{qml_file.name}" for qml_file in qml_files]
            )

        output_dir = source_file.parent / "deployment"
        if not dry_run:
            output_dir.mkdir(parents=True, exist_ok=True)
            print("[DEPLOY] Running Nuitka")
        command = self.nuitka + [
            os.fspath(source_file),
            "--follow-imports",
            "--onefile",
            "--enable-plugin=pyside6",
            f"--output-dir={output_dir}",
        ]
        command.extend(extra_args + qml_args)

        if sys.platform == "linux":
            linux_icon = str(Path(__file__).parent / "pyside_icon.jpg")
            command.append(f"--linux-onefile-icon={linux_icon}")

        run_command(command=command, dry_run=dry_run)