Skip to content
Snippets Groups Projects
Commit 5f601d98 authored by Philipp Hörist's avatar Philipp Hörist
Browse files

chore: WinLauncher: Add type annotations

parent 7ce4fcf1
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright 2016 Christoph Reiter
#
# This program is free software; you can redistribute it and/or modify
......@@ -9,7 +9,7 @@
"""Creates simple Python .exe launchers for gui and cli apps
./create-launcher.py "3.8.0" <target-dir>
./create-launcher.py "1.4.0" <target-dir>
"""
import os
......@@ -19,10 +19,9 @@
import tempfile
import shutil
import struct
from distutils.spawn import find_executable
def build_resource(rc_path, out_path):
def build_resource(rc_path: str, out_path: str) -> None:
"""Raises subprocess.CalledProcessError"""
def is_64bit():
......@@ -34,7 +33,7 @@ def is_64bit():
"-o", out_path])
def get_build_args():
def get_build_args() -> list[str]:
python_name = os.path.splitext(os.path.basename(sys.executable))[0]
python_config = os.path.join(
os.path.dirname(sys.executable), python_name + "-config")
......@@ -49,7 +48,11 @@ def get_build_args():
return shlex.split(cflags) + shlex.split(libs)
def build_exe(source_path, resource_path, is_gui, out_path):
def build_exe(source_path: str,
resource_path: str,
is_gui: bool,
out_path: str) -> None:
args = ["gcc", "-s"]
if is_gui:
args.append("-mwindows")
......@@ -58,7 +61,7 @@ def build_exe(source_path, resource_path, is_gui, out_path):
subprocess.check_call(args)
def get_launcher_code(debug):
def get_launcher_code(debug: bool) -> str:
template = """\
#include "Python.h"
#define WIN32_LEAN_AND_MEAN
......@@ -104,8 +107,13 @@ def get_launcher_code(debug):
return template
def get_resouce_code(filename, file_version, file_desc, icon_path,
product_name, product_version, company_name):
def get_resouce_code(filename: str,
file_version: str,
file_desc: str,
icon_path: str,
product_name: str,
product_version: str,
company_name: str) -> str:
template = """\
1 ICON "%(icon_path)s"
......@@ -135,7 +143,7 @@ def get_resouce_code(filename, file_version, file_desc, icon_path,
END
"""
def to_ver_list(v):
def to_ver_list(v: str) -> str:
v = v.split("-")[0]
return ",".join(map(str, (list(map(int, v.split("."))) + [0] * 4)[:4]))
......@@ -152,8 +160,14 @@ def to_ver_list(v):
}
def build_launcher(out_path, icon_path, file_desc, product_name, product_version,
company_name, is_gui, debug=False):
def build_launcher(out_path: str,
icon_path: str,
file_desc: str,
product_name: str,
product_version: str,
company_name: str,
is_gui: bool,
debug: bool = False) -> None:
src_ico = os.path.abspath(icon_path)
target = os.path.abspath(out_path)
......@@ -179,7 +193,7 @@ def build_launcher(out_path, icon_path, file_desc, product_name, product_version
shutil.rmtree(temp)
def main():
def main() -> None:
argv = sys.argv
version = argv[1]
......@@ -203,5 +217,6 @@ def main():
# os.path.join(misc, "gajim.ico"), "History Manager", "History Manager",
# version, company_name, 'history_manager.py', True)
if __name__ == "__main__":
main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment