Skip to content

Commit b126e50

Browse files
Starbuck5MyreMylar
andauthored
Add a briefcase template to pygame-ce (#2862)
* Add briefcase entrypoint * Update briefcase template * Fix stubcheck * Remove test_requires * Remove unused import Co-authored-by: Dan Lawrence <danintheshed@gmail.com> --------- Co-authored-by: Dan Lawrence <danintheshed@gmail.com>
1 parent ca6bbc8 commit b126e50

File tree

8 files changed

+165
-2
lines changed

8 files changed

+165
-2
lines changed

buildconfig/stubs/mypy_allow_list.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pygame\.tests.*
1919

2020
# don't look for stubs for pyinstaller hook
2121
pygame\.__pyinstaller.*
22+
pygame\.__briefcase.*
2223

2324
# don't look for stubs for these private modules either
2425
pygame\.ftfont

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ classifiers = [
4747
[project.entry-points.pyinstaller40]
4848
hook-dirs = 'pygame.__pyinstaller:get_hook_dirs'
4949

50+
[project.entry-points."briefcase.bootstraps"]
51+
pygame_ce = 'pygame.__briefcase.pygame_ce:PygameCEGuiBootstrap'
52+
5053
[build-system]
5154
requires = ["meson-python", "ninja", "cython", "sphinx<=7.2.6"]
5255
build-backend = 'mesonpy'

setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ commands =
1919
[options.entry_points]
2020
pyinstaller40 =
2121
hook-dirs = pygame.__pyinstaller:get_hook_dirs
22+
briefcase.boostraps =
23+
pygame_ce = pygame.__briefcase.pygame_ce:PygameCEGuiBootstrap
2224

2325
[isort]
2426
include_trailing_comma = True

setup.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -851,13 +851,15 @@ def run(self):
851851
'pygame.tests.test_utils',
852852
'pygame.docs',
853853
'pygame.examples',
854-
'pygame.__pyinstaller'],
854+
'pygame.__pyinstaller',
855+
'pygame.__briefcase'],
855856
"package_dir": {'pygame': 'src_py',
856857
'pygame._sdl2': 'src_py/_sdl2',
857858
'pygame.tests': 'test',
858859
'pygame.docs': 'docs',
859860
'pygame.examples': 'examples',
860-
'pygame.__pyinstaller': 'src_py/__pyinstaller'},
861+
'pygame.__pyinstaller': 'src_py/__pyinstaller',
862+
'pygame.__briefcase': 'src_py/__briefcase'},
861863
"headers": headers,
862864
"ext_modules": extensions,
863865
"data_files": data_files,

src_py/__briefcase/__init__.py

Whitespace-only changes.

src_py/__briefcase/meson.build

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# pure python sources
2+
python_sources = files(
3+
'__init__.py',
4+
'pygame_ce.py',
5+
)
6+
py.install_sources(python_sources, subdir: pg / '__briefcase')

src_py/__briefcase/pygame_ce.py

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
from briefcase.bootstraps.base import BaseGuiBootstrap
2+
3+
4+
class PygameCEGuiBootstrap(BaseGuiBootstrap):
5+
display_name_annotation = "does not support iOS/Android deployment"
6+
7+
def app_source(self):
8+
return """\
9+
import importlib.metadata
10+
import os
11+
import sys
12+
13+
import pygame
14+
15+
16+
SCREEN_WIDTH, SCREEN_HEIGHT = 800, 600
17+
BGCOLOR = (255, 255, 255)
18+
19+
20+
def main():
21+
# Linux desktop environments use an app's .desktop file to integrate the app
22+
# in to their application menus. The .desktop file of this app will include
23+
# the StartupWMClass key, set to app's formal name. This helps associate the
24+
# app's windows to its menu item.
25+
#
26+
# For association to work, any windows of the app must have WMCLASS property
27+
# set to match the value set in app's desktop file. For pygame_ce, this is
28+
# set using the SDL_VIDEO_X11_WMCLASS environment variable.
29+
30+
# Find the name of the module that was used to start the app
31+
app_module = sys.modules["__main__"].__package__
32+
# Retrieve the app's metadata
33+
metadata = importlib.metadata.metadata(app_module)
34+
35+
os.environ["SDL_VIDEO_X11_WMCLASS"] = metadata["Formal-Name"]
36+
37+
pygame.init()
38+
pygame.display.set_caption(metadata["Formal-Name"])
39+
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
40+
41+
running = True
42+
while running:
43+
for event in pygame.event.get():
44+
if event.type == pygame.QUIT:
45+
running = False
46+
break
47+
48+
screen.fill(BGCOLOR)
49+
pygame.display.flip()
50+
51+
pygame.quit()
52+
"""
53+
54+
def pyproject_table_briefcase_app_extra_content(self):
55+
return """
56+
requires = [
57+
"pygame-ce",
58+
]
59+
"""
60+
61+
def pyproject_table_macOS(self):
62+
return """\
63+
universal_build = true
64+
requires = [
65+
"std-nslog~=1.0.0",
66+
]
67+
"""
68+
69+
def pyproject_table_linux(self):
70+
return """\
71+
requires = [
72+
]
73+
"""
74+
75+
def pyproject_table_linux_system_debian(self):
76+
return """\
77+
system_requires = [
78+
]
79+
80+
system_runtime_requires = [
81+
]
82+
"""
83+
84+
def pyproject_table_linux_system_rhel(self):
85+
return """\
86+
system_requires = [
87+
]
88+
89+
system_runtime_requires = [
90+
]
91+
"""
92+
93+
def pyproject_table_linux_system_suse(self):
94+
return """\
95+
system_requires = [
96+
]
97+
98+
system_runtime_requires = [
99+
]
100+
"""
101+
102+
def pyproject_table_linux_system_arch(self):
103+
return """\
104+
system_requires = [
105+
]
106+
107+
system_runtime_requires = [
108+
]
109+
"""
110+
111+
def pyproject_table_linux_appimage(self):
112+
return """\
113+
manylinux = "manylinux_2_28"
114+
115+
system_requires = [
116+
]
117+
118+
linuxdeploy_plugins = [
119+
]
120+
"""
121+
122+
def pyproject_table_linux_flatpak(self):
123+
return """\
124+
flatpak_runtime = "org.freedesktop.Platform"
125+
flatpak_runtime_version = "23.08"
126+
flatpak_sdk = "org.freedesktop.Sdk"
127+
"""
128+
129+
def pyproject_table_windows(self):
130+
return """\
131+
requires = [
132+
]
133+
"""
134+
135+
def pyproject_table_iOS(self):
136+
return """\
137+
supported = false
138+
"""
139+
140+
def pyproject_table_android(self):
141+
return """\
142+
supported = false
143+
"""
144+
145+
def pyproject_table_web(self):
146+
return """\
147+
supported = false
148+
"""

src_py/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,4 @@ install_data(data_files, install_dir: pg_dir, install_tag: 'pg-tag')
3939

4040
subdir('_sdl2')
4141
subdir('__pyinstaller')
42+
subdir('__briefcase')

0 commit comments

Comments
 (0)