From 8afe7d1cdcf889db3fa058a11ff76defc9937352 Mon Sep 17 00:00:00 2001 From: Tobias Gruetzmacher Date: Thu, 13 Jun 2024 23:10:41 +0200 Subject: [PATCH 1/2] Modernize importlib.metadata usage in PyInstaller spec --- scripts/dosage.spec | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/scripts/dosage.spec b/scripts/dosage.spec index eb9883c25..68d00026a 100644 --- a/scripts/dosage.spec +++ b/scripts/dosage.spec @@ -1,28 +1,30 @@ # SPDX-License-Identifier: MIT -# Copyright (C) 2017-2020 Tobias Gruetzmacher +# SPDX-FileCopyrightText: © 2017 Tobias Gruetzmacher + +import re +from importlib import metadata # Idea from # https://github.com/pyinstaller/pyinstaller/wiki/Recipe-Setuptools-Entry-Point, # but with importlib -def Entrypoint(group, name, **kwargs): - import re - try: - from importlib.metadata import entry_points - except ImportError: - from importlib_metadata import entry_points - +def entrypoint(group, name, **kwargs): # get the entry point - eps = entry_points()[group] - ep = next(ep for ep in eps if ep.name == name) - module, attr = re.split(r'\s*:\s*', ep.value, 1) + eps = metadata.entry_points() + if 'select' in dir(eps): + # modern + ep = eps.select(group=group)[name] + else: + # legacy (pre-3.10) + ep = next(ep for ep in eps[group] if ep.name == name) + module, attr = re.split(r'\s*:\s*', ep.value, maxsplit=1) # script name must not be a valid module name to avoid name clashes on import script_path = os.path.join(workpath, name + '-script.py') print("creating script for entry point", group, name) - with open(script_path, 'w') as fh: + with open(script_path, mode='w', encoding='utf-8') as fh: print("import sys", file=fh) print("import", module, file=fh) - print("sys.exit(%s.%s())" % (module, attr), file=fh) + print(f"sys.exit({module}.{attr}())", file=fh) return Analysis( [script_path] + kwargs.get('scripts', []), @@ -30,7 +32,7 @@ def Entrypoint(group, name, **kwargs): ) -a = Entrypoint('console_scripts', 'dosage') +a = entrypoint('console_scripts', 'dosage') a.binaries = [x for x in a.binaries if not x[1].lower().startswith(r'c:\windows')] From 6024b2a01b5746b0eabb227d7a4c14ccb9e8ee13 Mon Sep 17 00:00:00 2001 From: Tobias Gruetzmacher Date: Thu, 13 Jun 2024 23:18:36 +0200 Subject: [PATCH 2/2] Build modern Windows EXE with Python 3.12 --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 880f9fa62..1d60b1969 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -74,7 +74,7 @@ pys.each { py -> parallel(tasks) parallel modern: { stage('Modern Windows binary') { - windowsBuild('3.11', 'dosage.exe') + windowsBuild('3.12', 'dosage.exe') } }, legacy: {