• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mozilla / mozregression / 14311112460

07 Apr 2025 01:55PM CUT coverage: 89.377%. First build
14311112460

Pull #1967

github

web-flow
Merge 62426c9fd into 807564865
Pull Request #1967: build(deps): bump taskcluster from 75.0.0 to 83.5.0

2524 of 2824 relevant lines covered (89.38%)

13.53 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/mozregression/pyinstaller.py
1
"""PyInstaller helper module to enable packaging tcl/tk with app bundles."""
2

3
# This Source Code Form is subject to the terms of the Mozilla Public
4
# License, v. 2.0. If a copy of the MPL was not distributed with this
5
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
6

7
import _tkinter
×
8
import shutil
×
9
import subprocess
×
10
from pathlib import Path
×
11

12
import PyInstaller.log as logging
×
13
from PyInstaller.building.datastruct import Tree
×
14
from PyInstaller.building.osx import BUNDLE
×
15
from PyInstaller.compat import is_darwin
×
16
from PyInstaller.utils.hooks.tcl_tk import (
×
17
    _collect_tcl_modules,
18
    _find_tcl_tk,
19
    find_tcl_tk_shared_libs,
20
)
21

22
logger = logging.getLogger(__name__)
×
23

24

25
class BUNDLE_WITH_TK(BUNDLE):
×
26
    """A BUNDLE class that incorporates tcl/tk libraries."""
27

28
    def __init__(self, *args, **kwargs):
×
29
        if not is_darwin:
×
30
            # This class can only be used on macOS.
31
            return
×
32
        super().__init__(*args, **kwargs)
×
33

34
    def assemble(self):
×
35
        """Run BUNDLE.assemble, and then run post assembly methods."""
36
        super().assemble()
×
37
        self.post_assemble()
×
38
        self.resign_binary()
×
39

40
    def post_assemble(self):
×
41
        """Collect tcl/tk library/module files and add them to the bundle."""
42

43
        # These files will not be needed (originally excluded by PyInstaller).
44
        excluded_files = ["demos", "*.lib", "*Config.sh"]
×
45

46
        # Discover location of tcl/tk dynamic library files (i.e., dylib).
47
        _tkinter_file = _tkinter.__file__
×
48
        tcl_lib, tk_lib = find_tcl_tk_shared_libs(_tkinter_file)
×
49

50
        # Determine full path/location of tcl/tk libraries.
51
        tcl_root, tk_root = _find_tcl_tk(_tkinter_file)
×
52

53
        # Determine original prefixes to put all the library files in.
54
        tcl_prefix, tk_prefix = Path(tcl_root).name, Path(tk_root).name
×
55

56
        # Create Tree objects with all the files that need to be included in the bundle.
57
        # Tree objects are a way of creating a table of contents describing everything in
58
        # the provided root directory.
59
        tcltree = Tree(tcl_root, prefix=tcl_prefix, excludes=excluded_files)
×
60
        tktree = Tree(tk_root, prefix=tk_prefix, excludes=excluded_files)
×
61
        tclmodulestree = _collect_tcl_modules(tcl_root)
×
62
        tcl_tk_files = tcltree + tktree + tclmodulestree
×
63

64
        # Use Tree object to list out files that will be copied (adapted from
65
        # PyInstaller.building.osx).
66
        files = [(dest, source) for dest, source, _type in tcl_tk_files]
×
67

68
        # Append dynamic library files.
69
        files.append((tcl_lib[0], tcl_lib[1]))
×
70
        files.append((tk_lib[0], tk_lib[1]))
×
71

72
        # Create "lib" directory in the .app bundle.
73
        lib_dir = Path(self.name) / "Contents" / "lib"
×
74
        lib_dir.mkdir()
×
75

76
        # Iterate over all files and copy them into "lib" directory.
77
        for dest, source in files:
×
78
            dest_full_path = lib_dir / dest
×
79
            dest_full_path.parent.mkdir(parents=True, exist_ok=True)
×
80
            if dest_full_path.is_dir():
×
81
                shutil.copytree(source, dest_full_path)
×
82
            else:
83
                shutil.copy(source, dest_full_path)
×
84

85
    def resign_binary(self):
×
86
        """Force resigning of the .app bundle."""
87
        command = [
×
88
            "codesign",
89
            "-s",
90
            "-",
91
            "--force",
92
            "--all-architectures",
93
            "--timestamp",
94
            "--deep",
95
            "--force",
96
        ]
97
        if self.entitlements_file:
×
98
            command.append("--entitlements")
×
99
            command.append(self.entitlements_file)
×
100

101
        command.append(self.name)
×
102
        subprocess.check_output(command)
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc