Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move logic to determine support revision from templates #1943

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/briefcase/commands/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
60 changes: 36 additions & 24 deletions src/briefcase/platforms/linux/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/briefcase/platforms/linux/appimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/briefcase/platforms/linux/flatpak.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
Loading