From ea446be6a4daecd11ac9cba34406e9676ef760bf Mon Sep 17 00:00:00 2001 From: Russell Martin Date: Wed, 7 Aug 2024 16:06:38 -0400 Subject: [PATCH] Move logic to determine support revision from templates --- src/briefcase/commands/create.py | 6 +++ src/briefcase/platforms/linux/__init__.py | 60 ++++++++++++++--------- src/briefcase/platforms/linux/appimage.py | 3 +- src/briefcase/platforms/linux/flatpak.py | 4 +- 4 files changed, 46 insertions(+), 27 deletions(-) diff --git a/src/briefcase/commands/create.py b/src/briefcase/commands/create.py index 5324bc3641..4b16e97395 100644 --- a/src/briefcase/commands/create.py +++ b/src/briefcase/commands/create.py @@ -104,6 +104,10 @@ def support_package_url(self, support_revision: str) -> str: f"{self.support_package_filename(support_revision)}" ) + def default_support_revision(self) -> str: + """The default revision for the default support package for a format.""" + return "" + def stub_binary_filename(self, support_revision: str, is_console_app: bool) -> str: """The filename for the stub binary.""" stub_type = "Console" if is_console_app else "GUI" @@ -229,6 +233,8 @@ def generate_app_template(self, app: AppConfig): # Properties of the generating environment # The full Python version string, including minor and dev/a/b/c suffixes (e.g., 3.11.0rc2) "python_version": platform.python_version(), + # Support package revision for default support package + "support_revision": self.default_support_revision(), # The host architecture "host_arch": self.tools.host_arch, # Transformations of explicit properties into useful forms diff --git a/src/briefcase/platforms/linux/__init__.py b/src/briefcase/platforms/linux/__init__.py index f1265ead16..da159cf3e9 100644 --- a/src/briefcase/platforms/linux/__init__.py +++ b/src/briefcase/platforms/linux/__init__.py @@ -57,30 +57,6 @@ def parse_freedesktop_os_release(content): class LinuxMixin: platform = "linux" - def support_package_url(self, support_revision): - """The URL of the support package to use for apps of this type. - - Linux builds that use a support package (AppImage, Flatpak) use indygreg's - Standalone Python to provide system packages. See - `https://github.com/indygreg/python-build-standalone` for details. - - System packages don't use a support package; this is defined by - the template, so this method won't be invoked - """ - python_download_arch = self.tools.host_arch - # use a 32bit Python if using 32bit Python on 64bit hardware - if self.tools.is_32bit_python and self.tools.host_arch == "aarch64": - python_download_arch = "armv7" - elif self.tools.is_32bit_python and self.tools.host_arch == "x86_64": - python_download_arch = "i686" - - version, datestamp = support_revision.split("+") - return ( - "https://github.com/indygreg/python-build-standalone/releases/download/" - f"{datestamp}/" - f"cpython-{support_revision}-{python_download_arch}-unknown-linux-gnu-install_only_stripped.tar.gz" - ) - def vendor_details(self, freedesktop_info): """Normalize the identity of the target Linux vendor, version, and base. @@ -123,6 +99,42 @@ def vendor_details(self, freedesktop_info): return vendor, codename, vendor_base +class StandalonePythonSupportMixin: + """Linux builds that use a support package (AppImage, Flatpak) use indygreg's + Standalone Python to provide system packages. + + See `https://github.com/indygreg/python-build-standalone` for details. + + System packages don't use a support package and instead use the system Python. + """ + + def default_support_revision(self) -> str: + """The default support revision for Standalone Python.""" + return { + "3.8": "3.8.19+20240726", + "3.9": "3.9.19+20240726", + "3.10": "3.10.14+20240726", + "3.11": "3.11.9+20240726", + "3.12": "3.12.4+20240726", + }[self.python_version_tag] + + def support_package_url(self, support_revision: str): + """The URL of the Standalone Python package.""" + python_download_arch = self.tools.host_arch + # use a 32bit Python if using 32bit Python on 64bit hardware + if self.tools.is_32bit_python and self.tools.host_arch == "aarch64": + python_download_arch = "armv7" + elif self.tools.is_32bit_python and self.tools.host_arch == "x86_64": + python_download_arch = "i686" + + version, datestamp = support_revision.split("+") + return ( + "https://github.com/indygreg/python-build-standalone/releases/download/" + f"{datestamp}/" + f"cpython-{support_revision}-{python_download_arch}-unknown-linux-gnu-install_only_stripped.tar.gz" + ) + + class LocalRequirementsMixin: # pragma: no-cover-if-is-windows # A mixin that captures the process of compiling requirements that are specified # as local file references into sdists, and then installing those requirements diff --git a/src/briefcase/platforms/linux/appimage.py b/src/briefcase/platforms/linux/appimage.py index 73743aa1da..fe546404d4 100644 --- a/src/briefcase/platforms/linux/appimage.py +++ b/src/briefcase/platforms/linux/appimage.py @@ -24,10 +24,11 @@ DockerOpenCommand, LinuxMixin, LocalRequirementsMixin, + StandalonePythonSupportMixin, ) -class LinuxAppImagePassiveMixin(LinuxMixin): +class LinuxAppImagePassiveMixin(StandalonePythonSupportMixin, LinuxMixin): # The Passive mixin honors the docker options, but doesn't try to verify # docker exists. It is used by commands that are "passive" from the # perspective of the build system, like open and run. diff --git a/src/briefcase/platforms/linux/flatpak.py b/src/briefcase/platforms/linux/flatpak.py index 563248b0ac..e454293c15 100644 --- a/src/briefcase/platforms/linux/flatpak.py +++ b/src/briefcase/platforms/linux/flatpak.py @@ -12,10 +12,10 @@ from briefcase.config import AppConfig from briefcase.exceptions import BriefcaseConfigError from briefcase.integrations.flatpak import Flatpak -from briefcase.platforms.linux import LinuxMixin +from briefcase.platforms.linux import LinuxMixin, StandalonePythonSupportMixin -class LinuxFlatpakMixin(LinuxMixin): +class LinuxFlatpakMixin(StandalonePythonSupportMixin, LinuxMixin): output_format = "flatpak" supported_host_os = {"Linux"} supported_host_os_reason = "Flatpaks can only be built on Linux."