Skip to content

Commit de45628

Browse files
authored
Merge pull request #2820 from pygame-community/ankith26-unify-version
Track version only in pyproject.toml
2 parents 8d59876 + ca42fdd commit de45628

File tree

6 files changed

+70
-40
lines changed

6 files changed

+70
-40
lines changed

buildconfig/get_version.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,29 @@
2929

3030
version = ast.literal_eval(finds[0].strip())
3131

32-
print(version)
32+
33+
_splits = version.split(".")
34+
35+
# handle optional dev tag
36+
if len(_splits) == 3:
37+
_splits.append('""')
38+
elif len(_splits) == 4:
39+
_splits[3] = f'".{_splits[3]}"'
40+
else:
41+
raise ValueError("Invalid version!")
42+
43+
version_short = ".".join(_splits[:3])
44+
version_macros = tuple(
45+
zip(
46+
("PG_MAJOR_VERSION", "PG_MINOR_VERSION", "PG_PATCH_VERSION", "PG_VERSION_TAG"),
47+
_splits,
48+
)
49+
)
50+
51+
52+
if __name__ == "__main__":
53+
print(
54+
"\n".join(f"-D{key}={value}" for key, value in version_macros)
55+
if "--macros" in sys.argv
56+
else version
57+
)

docs/reST/conf.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
# documentation root, use os.path.abspath to make it absolute, like shown here.
1818
sys.path.append(os.path.abspath('.'))
1919

20+
import buildconfig.get_version as pg_ver
21+
2022
# -- General configuration -----------------------------------------------------
2123

2224
# Add any Sphinx extension module names here, as strings. They can be extensions
@@ -46,10 +48,10 @@
4648
# |version| and |release|, also used in various other places throughout the
4749
# built documents.
4850
#
49-
# The short X.Y version.
50-
version = '2.5.0'
51+
# The short X.Y.Z version.
52+
version = pg_ver.version_short
5153
# The full version, including alpha/beta/rc tags.
52-
release = '2.5.0.dev3'
54+
release = pg_ver.version
5355

5456
# Format strings for the version directives
5557
versionadded_format = 'New in pygame-ce %s'

meson.build

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ project(
1111
],
1212
)
1313

14+
defines = run_command(
15+
[find_program('python3', 'python'), 'buildconfig/get_version.py', '--macros'],
16+
check: true,
17+
).stdout().strip().split()
18+
foreach define : defines
19+
add_global_arguments(define, language: 'c')
20+
endforeach
21+
1422
pg = 'pygame' # python base package name
1523

1624
if host_machine.system() == 'windows'

setup.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@
99
import platform
1010
import sysconfig
1111

12+
import buildconfig.get_version as pg_ver
13+
1214
with open('README.rst', encoding='utf-8') as readme:
1315
LONG_DESCRIPTION = readme.read()
1416

1517
EXTRAS = {}
1618

1719
METADATA = {
1820
"name": "pygame-ce",
19-
"version": "2.5.0.dev3",
21+
"version": pg_ver.version,
2022
"license": "LGPL",
2123
"url": "https://pyga.me",
2224
"author": "A community project.",
@@ -406,6 +408,9 @@ def run_install_headers(self):
406408
raise
407409

408410
for e in extensions:
411+
# define version macros
412+
e.define_macros.extend(pg_ver.version_macros)
413+
409414
# Only define the ARM_NEON defines if they have been enabled at build time.
410415
if enable_arm_neon:
411416
e.define_macros.append(('PG_ENABLE_ARM_NEON', '1'))

src_c/include/_pygame.h

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,22 @@
5555
#include <Python.h>
5656

5757
/* version macros (defined since version 1.9.5) */
58-
#define PG_MAJOR_VERSION 2
59-
#define PG_MINOR_VERSION 5
60-
#define PG_PATCH_VERSION 0
61-
/* The below is of the form ".devX" for dev releases, and "" (empty) for full
62-
* releases */
63-
#define PG_VERSION_TAG ".dev3"
58+
#ifndef PG_MAJOR_VERSION
59+
#error PG_MAJOR_VERSION must be defined
60+
#endif
61+
62+
#ifndef PG_MINOR_VERSION
63+
#error PG_MINOR_VERSION must be defined
64+
#endif
65+
66+
#ifndef PG_PATCH_VERSION
67+
#error PG_PATCH_VERSION must be defined
68+
#endif
69+
70+
#ifndef PG_VERSION_TAG
71+
#error PG_VERSION_TAG must be defined
72+
#endif
73+
6474
#define PG_VERSIONNUM(MAJOR, MINOR, PATCH) \
6575
(1000 * (MAJOR) + 100 * (MINOR) + (PATCH))
6676
#define PG_VERSION_ATLEAST(MAJOR, MINOR, PATCH) \

test/version_test.py

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,18 @@
99

1010

1111
class VersionTest(unittest.TestCase):
12-
@unittest.skipIf(
13-
not os.path.isfile(pg_header), "Skipping because we cannot find _pygame.h"
14-
)
15-
def test_pg_version_consistency(self):
16-
pgh_major = -1
17-
pgh_minor = -1
18-
pgh_patch = -1
19-
import re
20-
21-
major_exp_search = re.compile(r"define\s+PG_MAJOR_VERSION\s+([0-9]+)").search
22-
minor_exp_search = re.compile(r"define\s+PG_MINOR_VERSION\s+([0-9]+)").search
23-
patch_exp_search = re.compile(r"define\s+PG_PATCH_VERSION\s+([0-9]+)").search
24-
with open(pg_header) as f:
25-
for line in f:
26-
if pgh_major == -1:
27-
m = major_exp_search(line)
28-
if m:
29-
pgh_major = int(m.group(1))
30-
if pgh_minor == -1:
31-
m = minor_exp_search(line)
32-
if m:
33-
pgh_minor = int(m.group(1))
34-
if pgh_patch == -1:
35-
m = patch_exp_search(line)
36-
if m:
37-
pgh_patch = int(m.group(1))
38-
self.assertEqual(pgh_major, pygame.version.vernum[0])
39-
self.assertEqual(pgh_minor, pygame.version.vernum[1])
40-
self.assertEqual(pgh_patch, pygame.version.vernum[2])
12+
def test_vernum_obj(self):
13+
major, minor, patch = map(int, pygame.version.ver.split(".")[:3])
14+
self.assertEqual(pygame.version.vernum.major, major)
15+
self.assertEqual(pygame.version.vernum[0], major)
16+
self.assertEqual(pygame.version.vernum.minor, minor)
17+
self.assertEqual(pygame.version.vernum[1], minor)
18+
self.assertEqual(pygame.version.vernum.patch, patch)
19+
self.assertEqual(pygame.version.vernum[2], patch)
4120

4221
def test_sdl_version(self):
4322
self.assertEqual(len(pygame.version.SDL), 3)
23+
self.assertEqual(tuple(pygame.version.SDL), pygame.get_sdl_version())
4424

4525
def test_installed_version_and_dunder(self):
4626
self.assertEqual(pygame.__version__, pygame.version.ver)

0 commit comments

Comments
 (0)