From 2571c13ac6fd4471da9edb250491bc1ed4262531 Mon Sep 17 00:00:00 2001 From: Starbuck5 <46412508+Starbuck5@users.noreply.github.com> Date: Mon, 20 May 2024 10:09:11 -0400 Subject: [PATCH 1/5] Add briefcase entrypoint --- buildconfig/stubs/mypy_allow_list.txt | 1 + pyproject.toml | 3 + setup.cfg | 2 + setup.py | 6 +- src_py/__briefcase/meson.build | 5 + src_py/__briefcase/pygame_ce.py | 154 ++++++++++++++++++++++++++ src_py/meson.build | 1 + 7 files changed, 170 insertions(+), 2 deletions(-) create mode 100644 src_py/__briefcase/meson.build create mode 100644 src_py/__briefcase/pygame_ce.py diff --git a/buildconfig/stubs/mypy_allow_list.txt b/buildconfig/stubs/mypy_allow_list.txt index 646e45cd1a..c6f3ffa15b 100644 --- a/buildconfig/stubs/mypy_allow_list.txt +++ b/buildconfig/stubs/mypy_allow_list.txt @@ -19,6 +19,7 @@ pygame\.tests.* # don't look for stubs for pyinstaller hook pygame\.__pyinstaller.* +pygame\.__briefcase.* # don't look for stubs for these private modules either pygame\.ftfont diff --git a/pyproject.toml b/pyproject.toml index 5b5b5815fe..cd817fab77 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -47,6 +47,9 @@ classifiers = [ [project.entry-points.pyinstaller40] hook-dirs = 'pygame.__pyinstaller:get_hook_dirs' +[project.entry-points."briefcase.bootstraps"] +pygame_ce = 'pygame.__briefcase.pygame_ce:PygameCEGuiBootstrap' + [build-system] requires = ["meson-python", "ninja", "cython"] build-backend = 'mesonpy' diff --git a/setup.cfg b/setup.cfg index b6e5f5b9fc..f7d0bed4e4 100644 --- a/setup.cfg +++ b/setup.cfg @@ -19,6 +19,8 @@ commands = [options.entry_points] pyinstaller40 = hook-dirs = pygame.__pyinstaller:get_hook_dirs +briefcase.boostraps = + pygame_ce = pygame.__briefcase.pygame_ce:PygameCEGuiBootstrap [isort] include_trailing_comma = True diff --git a/setup.py b/setup.py index b272e1f444..d31c19049f 100644 --- a/setup.py +++ b/setup.py @@ -857,13 +857,15 @@ def run(self): 'pygame.tests.test_utils', 'pygame.docs', 'pygame.examples', - 'pygame.__pyinstaller'], + 'pygame.__pyinstaller', + 'pygame.__briefcase'], "package_dir": {'pygame': 'src_py', 'pygame._sdl2': 'src_py/_sdl2', 'pygame.tests': 'test', 'pygame.docs': 'docs', 'pygame.examples': 'examples', - 'pygame.__pyinstaller': 'src_py/__pyinstaller'}, + 'pygame.__pyinstaller': 'src_py/__pyinstaller', + 'pygame.__briefcase': 'src_py/__briefcase'}, "headers": headers, "ext_modules": extensions, "data_files": data_files, diff --git a/src_py/__briefcase/meson.build b/src_py/__briefcase/meson.build new file mode 100644 index 0000000000..b92eba1bae --- /dev/null +++ b/src_py/__briefcase/meson.build @@ -0,0 +1,5 @@ +# pure python sources +python_sources = files( + 'pygame_ce.py', +) +py.install_sources(python_sources, subdir: pg / '__briefcase') diff --git a/src_py/__briefcase/pygame_ce.py b/src_py/__briefcase/pygame_ce.py new file mode 100644 index 0000000000..cd1f85663d --- /dev/null +++ b/src_py/__briefcase/pygame_ce.py @@ -0,0 +1,154 @@ +from briefcase.bootstraps.base import BaseGuiBootstrap + + +class PygameCEGuiBootstrap(BaseGuiBootstrap): + display_name_annotation = "does not support iOS/Android deployment" + + def app_source(self): + return """\ +import importlib.metadata +import os +import sys +from pathlib import Path + +import pygame + + +SCREEN_WIDTH, SCREEN_HEIGHT = 800, 600 +WHITE = (255, 255, 255) + + +def main(): + # Linux desktop environments use an app's .desktop file to integrate the app + # in to their application menus. The .desktop file of this app will include + # the StartupWMClass key, set to app's formal name. This helps associate the + # app's windows to its menu item. + # + # For association to work, any windows of the app must have WMCLASS property + # set to match the value set in app's desktop file. For PyGame, this is set + # using the SDL_VIDEO_X11_WMCLASS environment variable. + + # Find the name of the module that was used to start the app + app_module = sys.modules["__main__"].__package__ + # Retrieve the app's metadata + metadata = importlib.metadata.metadata(app_module) + + os.environ["SDL_VIDEO_X11_WMCLASS"] = metadata["Formal-Name"] + + pygame.init() + pygame.display.set_caption(metadata["Formal-Name"]) + screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT)) + + running = True + while running: + for event in pygame.event.get(): + if event.type == pygame.QUIT: + running = False + break + + screen.fill(WHITE) + pygame.display.flip() + + pygame.quit() +""" + + def pyproject_table_briefcase_app_extra_content(self): + return """ +requires = [ + "pygame-ce~=2.4.0", +] +test_requires = [ +{% if cookiecutter.test_framework == "pytest" %} + "pytest", +{% endif %} +] +""" + + def pyproject_table_macOS(self): + return """\ +universal_build = true +requires = [ + "std-nslog~=1.0.0", +] +""" + + def pyproject_table_linux(self): + return """\ +requires = [ +] +""" + + def pyproject_table_linux_system_debian(self): + return """\ +system_requires = [ +] + +system_runtime_requires = [ +] +""" + + def pyproject_table_linux_system_rhel(self): + return """\ +system_requires = [ +] + +system_runtime_requires = [ +] +""" + + def pyproject_table_linux_system_suse(self): + return """\ +system_requires = [ +] + +system_runtime_requires = [ +] +""" + + def pyproject_table_linux_system_arch(self): + return """\ +system_requires = [ +] + +system_runtime_requires = [ +] +""" + + def pyproject_table_linux_appimage(self): + return """\ +manylinux = "manylinux_2_28" + +system_requires = [ +] + +linuxdeploy_plugins = [ +] +""" + + def pyproject_table_linux_flatpak(self): + return """\ +flatpak_runtime = "org.freedesktop.Platform" +flatpak_runtime_version = "23.08" +flatpak_sdk = "org.freedesktop.Sdk" +""" + + def pyproject_table_windows(self): + return """\ +requires = [ +] +""" + + def pyproject_table_iOS(self): + return """\ +supported = false +""" + + def pyproject_table_android(self): + return """\ +supported = false +""" + + def pyproject_table_web(self): + return """\ +supported = false +""" diff --git a/src_py/meson.build b/src_py/meson.build index b59b95994d..52c159f70b 100644 --- a/src_py/meson.build +++ b/src_py/meson.build @@ -38,3 +38,4 @@ install_data(data_files, install_dir: pg_dir, install_tag: 'pg-tag') subdir('_sdl2') subdir('__pyinstaller') +subdir('__briefcase') From b97be4e966de47e94dbf9ac9fc6c59258c90ac5f Mon Sep 17 00:00:00 2001 From: Starbuck5 <46412508+Starbuck5@users.noreply.github.com> Date: Mon, 20 May 2024 10:35:29 -0400 Subject: [PATCH 2/5] Update briefcase template --- src_py/__briefcase/pygame_ce.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src_py/__briefcase/pygame_ce.py b/src_py/__briefcase/pygame_ce.py index cd1f85663d..795466b048 100644 --- a/src_py/__briefcase/pygame_ce.py +++ b/src_py/__briefcase/pygame_ce.py @@ -15,7 +15,7 @@ def app_source(self): SCREEN_WIDTH, SCREEN_HEIGHT = 800, 600 -WHITE = (255, 255, 255) +BGCOLOR = (255, 255, 255) def main(): @@ -25,8 +25,8 @@ def main(): # app's windows to its menu item. # # For association to work, any windows of the app must have WMCLASS property - # set to match the value set in app's desktop file. For PyGame, this is set - # using the SDL_VIDEO_X11_WMCLASS environment variable. + # set to match the value set in app's desktop file. For pygame_ce, this is + # set using the SDL_VIDEO_X11_WMCLASS environment variable. # Find the name of the module that was used to start the app app_module = sys.modules["__main__"].__package__ @@ -46,7 +46,7 @@ def main(): running = False break - screen.fill(WHITE) + screen.fill(BGCOLOR) pygame.display.flip() pygame.quit() @@ -55,7 +55,7 @@ def main(): def pyproject_table_briefcase_app_extra_content(self): return """ requires = [ - "pygame-ce~=2.4.0", + "pygame-ce", ] test_requires = [ {% if cookiecutter.test_framework == "pytest" %} From fd0df12636d88cd1762f2d8417e0016eb9a70895 Mon Sep 17 00:00:00 2001 From: Starbuck5 <46412508+Starbuck5@users.noreply.github.com> Date: Mon, 20 May 2024 11:03:44 -0400 Subject: [PATCH 3/5] Fix stubcheck --- src_py/__briefcase/__init__.py | 0 src_py/__briefcase/meson.build | 1 + 2 files changed, 1 insertion(+) create mode 100644 src_py/__briefcase/__init__.py diff --git a/src_py/__briefcase/__init__.py b/src_py/__briefcase/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src_py/__briefcase/meson.build b/src_py/__briefcase/meson.build index b92eba1bae..a019a1a772 100644 --- a/src_py/__briefcase/meson.build +++ b/src_py/__briefcase/meson.build @@ -1,5 +1,6 @@ # pure python sources python_sources = files( + '__init__.py', 'pygame_ce.py', ) py.install_sources(python_sources, subdir: pg / '__briefcase') From a75a10930064aaffe61abb0cf5e10098570b744e Mon Sep 17 00:00:00 2001 From: Starbuck5 <46412508+Starbuck5@users.noreply.github.com> Date: Tue, 21 May 2024 16:24:19 -0400 Subject: [PATCH 4/5] Remove test_requires --- src_py/__briefcase/pygame_ce.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src_py/__briefcase/pygame_ce.py b/src_py/__briefcase/pygame_ce.py index 795466b048..6db18b411b 100644 --- a/src_py/__briefcase/pygame_ce.py +++ b/src_py/__briefcase/pygame_ce.py @@ -57,11 +57,6 @@ def pyproject_table_briefcase_app_extra_content(self): requires = [ "pygame-ce", ] -test_requires = [ -{% if cookiecutter.test_framework == "pytest" %} - "pytest", -{% endif %} -] """ def pyproject_table_macOS(self): From e18c33ffb335f5d2754b40a7e61fd06287348284 Mon Sep 17 00:00:00 2001 From: Charlie Hayden <46412508+Starbuck5@users.noreply.github.com> Date: Sun, 26 May 2024 13:25:48 -0700 Subject: [PATCH 5/5] Remove unused import Co-authored-by: Dan Lawrence --- src_py/__briefcase/pygame_ce.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src_py/__briefcase/pygame_ce.py b/src_py/__briefcase/pygame_ce.py index 6db18b411b..ddd26ddb4a 100644 --- a/src_py/__briefcase/pygame_ce.py +++ b/src_py/__briefcase/pygame_ce.py @@ -9,7 +9,6 @@ def app_source(self): import importlib.metadata import os import sys -from pathlib import Path import pygame