Skip to content

Commit 1c37e81

Browse files
committed
scripts: add type annotations to macdeployqtplus
1 parent 5c2885f commit 1c37e81

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

contrib/macdeploy/macdeployqtplus

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import subprocess, sys, re, os, shutil, stat, os.path, time
2020
from string import Template
2121
from argparse import ArgumentParser
22+
from typing import List, Optional
2223

2324
# This is ported from the original macdeployqt with modifications
2425

@@ -85,7 +86,7 @@ class FrameworkInfo(object):
8586
bundleBinaryDirectory = "Contents/MacOS"
8687

8788
@classmethod
88-
def fromOtoolLibraryLine(cls, line):
89+
def fromOtoolLibraryLine(cls, line: str) -> Optional['FrameworkInfo']:
8990
# Note: line must be trimmed
9091
if line == "":
9192
return None
@@ -152,7 +153,7 @@ class FrameworkInfo(object):
152153
return info
153154

154155
class ApplicationBundleInfo(object):
155-
def __init__(self, path):
156+
def __init__(self, path: str):
156157
self.path = path
157158
appName = "Bitcoin-Qt"
158159
self.binaryPath = os.path.join(path, "Contents", "MacOS", appName)
@@ -167,7 +168,7 @@ class DeploymentInfo(object):
167168
self.pluginPath = None
168169
self.deployedFrameworks = []
169170

170-
def detectQtPath(self, frameworkDirectory):
171+
def detectQtPath(self, frameworkDirectory: str):
171172
parentDir = os.path.dirname(frameworkDirectory)
172173
if os.path.exists(os.path.join(parentDir, "translations")):
173174
# Classic layout, e.g. "/usr/local/Trolltech/Qt-4.x.x"
@@ -180,7 +181,7 @@ class DeploymentInfo(object):
180181
if os.path.exists(pluginPath):
181182
self.pluginPath = pluginPath
182183

183-
def usesFramework(self, name):
184+
def usesFramework(self, name: str) -> bool:
184185
nameDot = "%s." % name
185186
libNameDot = "lib%s." % name
186187
for framework in self.deployedFrameworks:
@@ -192,7 +193,7 @@ class DeploymentInfo(object):
192193
return True
193194
return False
194195

195-
def getFrameworks(binaryPath, verbose):
196+
def getFrameworks(binaryPath: str, verbose: int) -> List[FrameworkInfo]:
196197
if verbose >= 3:
197198
print("Inspecting with otool: " + binaryPath)
198199
otoolbin=os.getenv("OTOOL", "otool")
@@ -221,33 +222,33 @@ def getFrameworks(binaryPath, verbose):
221222

222223
return libraries
223224

224-
def runInstallNameTool(action, *args):
225+
def runInstallNameTool(action: str, *args):
225226
installnametoolbin=os.getenv("INSTALLNAMETOOL", "install_name_tool")
226227
subprocess.check_call([installnametoolbin, "-"+action] + list(args))
227228

228-
def changeInstallName(oldName, newName, binaryPath, verbose):
229+
def changeInstallName(oldName: str, newName: str, binaryPath: str, verbose: int):
229230
if verbose >= 3:
230231
print("Using install_name_tool:")
231232
print(" in", binaryPath)
232233
print(" change reference", oldName)
233234
print(" to", newName)
234235
runInstallNameTool("change", oldName, newName, binaryPath)
235236

236-
def changeIdentification(id, binaryPath, verbose):
237+
def changeIdentification(id: str, binaryPath: str, verbose: int):
237238
if verbose >= 3:
238239
print("Using install_name_tool:")
239240
print(" change identification in", binaryPath)
240241
print(" to", id)
241242
runInstallNameTool("id", id, binaryPath)
242243

243-
def runStrip(binaryPath, verbose):
244+
def runStrip(binaryPath: str, verbose: int):
244245
stripbin=os.getenv("STRIP", "strip")
245246
if verbose >= 3:
246247
print("Using strip:")
247248
print(" stripped", binaryPath)
248249
subprocess.check_call([stripbin, "-x", binaryPath])
249250

250-
def copyFramework(framework, path, verbose):
251+
def copyFramework(framework: FrameworkInfo, path: str, verbose: int) -> Optional[str]:
251252
if framework.sourceFilePath.startswith("Qt"):
252253
#standard place for Nokia Qt installer's frameworks
253254
fromPath = "/Library/Frameworks/" + framework.sourceFilePath
@@ -309,7 +310,7 @@ def copyFramework(framework, path, verbose):
309310

310311
return toPath
311312

312-
def deployFrameworks(frameworks, bundlePath, binaryPath, strip, verbose, deploymentInfo=None):
313+
def deployFrameworks(frameworks: List[FrameworkInfo], bundlePath: str, binaryPath: str, strip: bool, verbose: int, deploymentInfo: Optional[DeploymentInfo] = None) -> DeploymentInfo:
313314
if deploymentInfo is None:
314315
deploymentInfo = DeploymentInfo()
315316

@@ -355,15 +356,15 @@ def deployFrameworks(frameworks, bundlePath, binaryPath, strip, verbose, deploym
355356

356357
return deploymentInfo
357358

358-
def deployFrameworksForAppBundle(applicationBundle, strip, verbose):
359+
def deployFrameworksForAppBundle(applicationBundle: ApplicationBundleInfo, strip: bool, verbose: int) -> DeploymentInfo:
359360
frameworks = getFrameworks(applicationBundle.binaryPath, verbose)
360361
if len(frameworks) == 0 and verbose >= 1:
361362
print("Warning: Could not find any external frameworks to deploy in %s." % (applicationBundle.path))
362363
return DeploymentInfo()
363364
else:
364365
return deployFrameworks(frameworks, applicationBundle.path, applicationBundle.binaryPath, strip, verbose)
365366

366-
def deployPlugins(appBundleInfo, deploymentInfo, strip, verbose):
367+
def deployPlugins(appBundleInfo: ApplicationBundleInfo, deploymentInfo: DeploymentInfo, strip: bool, verbose: int):
367368
# Lookup available plugins, exclude unneeded
368369
plugins = []
369370
if deploymentInfo.pluginPath is None:
@@ -707,7 +708,7 @@ elif config.sign:
707708

708709
if config.dmg is not None:
709710

710-
def runHDIUtil(verb, image_basename, **kwargs):
711+
def runHDIUtil(verb: str, image_basename: str, **kwargs) -> int:
711712
hdiutil_args = ["hdiutil", verb, image_basename + ".dmg"]
712713
if "capture_stdout" in kwargs:
713714
del kwargs["capture_stdout"]

0 commit comments

Comments
 (0)