Skip to content

Commit 90e4a58

Browse files
authored
Merge pull request #524 from JaskRendix/toml
Migrate to pyproject.toml, remove setup.py, update package initialization, rename build script
2 parents e41fe25 + 312e234 commit 90e4a58

File tree

6 files changed

+120
-204
lines changed

6 files changed

+120
-204
lines changed

.replit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
onBoot = "python setup.py install; clear"
1+
onBoot = "pip install -e .; clear"
22
language = "python3"
33
run = "python pygame_menu/examples/simple.py"

build.py renamed to build_package.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import sys
1212
from pathlib import Path
1313

14-
assert len(sys.argv) == 2, "Argument is required, usage: build.py pip/twine"
14+
assert len(sys.argv) == 2, "Argument is required, usage: build_package.py pip/twine"
1515
mode: str = sys.argv[1].strip()
1616

1717
root = Path(__file__).resolve().parent
@@ -20,16 +20,12 @@
2020

2121
if mode == "pip":
2222
if dist.is_dir():
23-
for k in dist.iterdir():
24-
if "pygame_menu-" in k.name or "pygame-menu-" in k.name:
25-
k.unlink()
23+
shutil.rmtree(dist)
2624

2725
if build.is_dir():
28-
for k in build.iterdir():
29-
if "bdist." in k.name or k.name == "lib":
30-
shutil.rmtree(k)
26+
shutil.rmtree(build)
3127

32-
subprocess.run(["python", "setup.py", "sdist", "bdist_wheel"], check=True)
28+
subprocess.run(["python", "-m", "build"], check=True)
3329

3430
elif mode == "twine":
3531
if dist.is_dir():
@@ -39,7 +35,9 @@
3935
check=True,
4036
)
4137
else:
42-
raise FileNotFoundError("No distribution found, execute build.py pip first")
38+
raise FileNotFoundError(
39+
"No distribution found, execute build_package.py pip first"
40+
)
4341

4442
else:
4543
raise ValueError(f"Unknown mode {mode}")

codecov.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
ignore:
2-
- "build.py"
2+
- "build_package.py"
33
- "docs/*.py"
44
- "pygame_menu/__pyinstaller/*py"
55
- "pygame_menu/examples/*.py"
66
- "pygame_menu/examples/other/*.py"
7-
- "setup.py"
87
- "test/*.py"

pygame_menu/__init__.py

Lines changed: 61 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -6,89 +6,42 @@
66
A menu for pygame. Simple, and easy to use.
77
"""
88

9-
from __future__ import annotations
10-
11-
__all__ = [
12-
# Common classes
13-
"BaseImage",
14-
"Menu",
15-
"Sound",
16-
"Theme",
17-
]
18-
19-
# Check if pygame exists, if not maybe the module is being used by setup.py
20-
__pygame_version__ = None
21-
try:
22-
from pygame import version as __pygame_version__
23-
24-
__pygame_version__ = __pygame_version__.vernum
25-
except (ModuleNotFoundError, ImportError):
26-
pass
27-
28-
# Import modules that require pygame
29-
if __pygame_version__ is not None:
30-
"""
31-
BaseImage: Provides basic image loading and manipulation with pygame
32-
"""
33-
import pygame_menu.baseimage
34-
from pygame_menu.baseimage import BaseImage
35-
36-
"""
37-
Controls: Default controls of menu object and key definition
38-
"""
39-
import pygame_menu.controls
40-
41-
"""
42-
Events: Menu events definition and locals
43-
"""
44-
import pygame_menu.events
45-
46-
"""
47-
Fonts: Menu fonts
48-
"""
49-
import pygame_menu.font
50-
51-
"""
52-
Locals: Local constants
53-
"""
54-
import pygame_menu.locals
55-
56-
"""
57-
Menu: Menu class
58-
"""
59-
from pygame_menu.menu import Menu
60-
61-
"""
62-
ScrollArea: Scrollarea class
63-
"""
64-
import pygame_menu._scrollarea
65-
66-
"""
67-
Sound: Sound class
68-
"""
69-
import pygame_menu.sound
70-
from pygame_menu.sound import Sound
9+
import logging
10+
import os
11+
from datetime import datetime
12+
from importlib.metadata import PackageNotFoundError, metadata
7113

72-
"""
73-
Themes: Menu themes
74-
"""
75-
import pygame_menu.themes
76-
from pygame_menu.themes import Theme
14+
logger = logging.getLogger(__name__)
7715

78-
"""
79-
Widgets: Menu widgets
80-
"""
81-
import pygame_menu.widgets
16+
__all__ = ["BaseImage", "Menu", "Sound", "Theme"]
8217

83-
"""
84-
Version: Library version
85-
"""
86-
import pygame_menu.version
18+
# Metadata
19+
try:
20+
_meta = metadata("pygame-menu")
21+
__version__ = _meta.get("Version")
22+
__author__ = _meta.get("Author")
23+
__email__ = _meta.get("Author-email")
24+
__description__ = _meta.get("Summary")
25+
__license__ = _meta.get("License")
26+
__url__ = _meta.get("Home-page")
27+
__module_name__ = _meta.get("Name")
28+
except PackageNotFoundError:
29+
# Local fallback
30+
__version__ = "4.4.3"
31+
__author__ = "Pablo Pizarro R."
32+
__email__ = "[email protected]"
33+
__description__ = "A menu for pygame. Simple, and easy to use"
34+
__license__ = "MIT"
35+
__url__ = "https://pygame-menu.readthedocs.io"
36+
__module_name__ = "pygame-menu"
37+
38+
# Extra metadata not provided by importlib
39+
__url_documentation__ = "https://pygame-menu.readthedocs.io"
40+
__url_source_code__ = "https://github.com/ppizarror/pygame-menu"
41+
__url_bug_tracker__ = "https://github.com/ppizarror/pygame-menu/issues"
42+
__keywords__ = "pygame menu menus gui widget input button pygame-menu image sound ui"
43+
__copyright__ = f"Copyright 2017-{datetime.now().year} Pablo Pizarro R."
8744

88-
"""
89-
Metadata: Information about the project
90-
"""
91-
__author__ = "Pablo Pizarro R."
9245
__contributors__ = [
9346
# Author
9447
"ppizarror",
@@ -116,31 +69,40 @@
11669
"werdeil",
11770
"zPaw",
11871
]
119-
__copyright__ = "Copyright 2017 Pablo Pizarro R. @ppizarror"
120-
__description__ = "A menu for pygame. Simple, and easy to use"
121-
__email__ = "[email protected]"
122-
__keywords__ = "pygame menu menus gui widget input button pygame-menu image sound ui"
123-
__license__ = "MIT"
124-
__module_name__ = "pygame-menu"
125-
__url__ = "https://pygame-menu.readthedocs.io"
126-
__url_bug_tracker__ = "https://github.com/ppizarror/pygame-menu/issues"
127-
__url_documentation__ = "https://pygame-menu.readthedocs.io"
128-
__url_source_code__ = "https://github.com/ppizarror/pygame-menu"
129-
__version__ = pygame_menu.version.ver
13072

131-
"""
132-
Print pygame-menu version.
133-
"""
134-
import logging
135-
import os
73+
# Pygame check
74+
__pygame_version__ = None
75+
try:
76+
from pygame import version as __pv
13677

137-
logger = logging.getLogger(__name__)
78+
__pygame_version__ = __pv.vernum
79+
except (ModuleNotFoundError, ImportError):
80+
# Pygame is not installed; skip pygame-dependent imports
81+
pass
13882

83+
# Conditional imports
84+
if __pygame_version__ is not None:
85+
from pygame_menu import (
86+
_scrollarea,
87+
baseimage,
88+
controls,
89+
events,
90+
font,
91+
locals,
92+
menu,
93+
sound,
94+
themes,
95+
widgets,
96+
)
97+
98+
BaseImage = baseimage.BaseImage
99+
Menu = menu.Menu
100+
Sound = sound.Sound
101+
Theme = themes.Theme
102+
103+
# Version print
139104
if (
140105
"PYGAME_MENU_HIDE_VERSION" not in os.environ
141106
and "PYGAME_HIDE_SUPPORT_PROMPT" not in os.environ
142107
):
143108
logger.info(f"{__module_name__} {__version__}")
144-
145-
# Cleanup namespace
146-
del os

pyproject.toml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,53 @@
1+
[build-system]
2+
requires = ["setuptools>=61.0", "wheel"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "pygame-menu"
7+
dynamic = ["version"]
8+
description = "A menu for pygame. Simple, and easy to use"
9+
readme = "README.rst"
10+
requires-python = ">=3.9, <4"
11+
license = {text = "MIT"}
12+
authors = [{name = "Pablo Pizarro R.", email = "[email protected]"}]
13+
keywords = ["pygame", "menu", "menus", "gui", "widget", "input", "button", "image", "sound", "ui"]
14+
classifiers = [
15+
"License :: OSI Approved :: MIT License",
16+
"Natural Language :: English",
17+
"Operating System :: OS Independent",
18+
"Programming Language :: Python :: 3.9",
19+
"Programming Language :: Python :: 3.10",
20+
"Programming Language :: Python :: 3.11",
21+
"Programming Language :: Python :: 3.12",
22+
"Programming Language :: Python :: 3.13",
23+
"Topic :: Games/Entertainment",
24+
"Topic :: Multimedia",
25+
"Topic :: Software Development :: Libraries :: pygame",
26+
]
27+
dependencies = ["pygame>=2.0.0"]
28+
29+
[project.urls]
30+
"Bug Tracker" = "https://github.com/ppizarror/pygame-menu/issues"
31+
"Documentation" = "https://pygame-menu.readthedocs.io"
32+
"Source Code" = "https://github.com/ppizarror/pygame-menu"
33+
34+
[project.optional-dependencies]
35+
docs = ["sphinx<7", "sphinx-autodoc-typehints>=1.2.0", "sphinx-rtd-theme"]
36+
test = ["nose2[coverage_plugin]", "pytest", "pytest-cov"]
37+
38+
[project.entry-points."pyinstaller40"]
39+
hook-dirs = "pygame_menu.__pyinstaller:get_hook_dirs"
40+
41+
[tool.setuptools]
42+
include-package-data = true
43+
44+
[tool.setuptools.dynamic]
45+
version = {attr = "pygame_menu.version.ver"}
46+
47+
[tool.setuptools.packages.find]
48+
where = ["."]
49+
exclude = ["test*"]
50+
151
[tool.ruff]
252
target-version = "py39"
353
line-length = 88

setup.py

Lines changed: 0 additions & 93 deletions
This file was deleted.

0 commit comments

Comments
 (0)