diff --git a/buildconfig/stubs/pygame/system.pyi b/buildconfig/stubs/pygame/system.pyi index 36e909af74..1883b9470d 100644 --- a/buildconfig/stubs/pygame/system.pyi +++ b/buildconfig/stubs/pygame/system.pyi @@ -27,6 +27,17 @@ class _Locale(TypedDict): language: str country: str | None +def get_cpu_cores() -> int: + """Get the number of CPU cores available in the system. + + Returns the number of CPU cores available in the system. + + .. note:: On CPUs that include technologies such as hyperthreading, the number + of logical cores may be more than the number of physical cores. + + .. versionadded:: 2.5.7 + """ + def get_cpu_instruction_sets() -> _InstructionSets: """Get the information of CPU instruction sets. @@ -75,6 +86,25 @@ def get_total_ram() -> int: .. versionadded:: 2.3.1 """ +def get_platform() -> str: + """Get the name of the running system platform. + + Returns a string with the name of the running system platform. + + Examples of supported platforms include: + ``Windows``, ``Linux``, ``Mac OS X``, ``iOS``, ``Android``. + + .. note:: + If the correct platform name is not available, + returns a string beginning with the text "Unknown". + + .. note:: + The ``platform`` library has similar functionality for this use case, + but has more detailed platform information. + + .. versionadded:: 2.5.7 + """ + def get_pref_path(org: str, app: str) -> str: """Get a writeable folder for your app. diff --git a/src_c/doc/system_doc.h b/src_c/doc/system_doc.h index d0b939a170..94cbbc0dfa 100644 --- a/src_c/doc/system_doc.h +++ b/src_c/doc/system_doc.h @@ -1,7 +1,9 @@ /* Auto generated file: with make_docs.py . Docs go in docs/reST/ref/ . */ #define DOC_SYSTEM "Pygame module to provide additional context about the system." +#define DOC_SYSTEM_GETCPUCORES "get_cpu_cores() -> int\nGet the number of CPU cores available in the system." #define DOC_SYSTEM_GETCPUINSTRUCTIONSETS "get_cpu_instruction_sets() -> _InstructionSets\nGet the information of CPU instruction sets." #define DOC_SYSTEM_GETTOTALRAM "get_total_ram() -> int\nGet the amount of RAM configured in the system." +#define DOC_SYSTEM_GETPLATFORM "get_platform() -> str\nGet the name of the running system platform." #define DOC_SYSTEM_GETPREFPATH "get_pref_path(org, app) -> str\nGet a writeable folder for your app." #define DOC_SYSTEM_GETPREFLOCALES "get_pref_locales() -> list[_Locale]\nGet preferred locales set on the system." #define DOC_SYSTEM_GETPOWERSTATE "get_power_state() -> PowerState | None\nGet the current power supply state." diff --git a/src_c/system.c b/src_c/system.c index 2c9e2b4e5f..3bcf339f07 100644 --- a/src_c/system.c +++ b/src_c/system.c @@ -4,6 +4,12 @@ #include "doc/system_doc.h" +static PyObject * +pg_system_get_cpu_cores(PyObject *self, PyObject *_null) +{ + return PyLong_FromLong(SDL_GetCPUCount()); +} + static PyObject * pg_system_get_cpu_instruction_sets(PyObject *self, PyObject *_null) { @@ -63,6 +69,12 @@ pg_system_get_total_ram(PyObject *self, PyObject *_null) return PyLong_FromLong(SDL_GetSystemRAM()); } +static PyObject * +pg_system_get_platform(PyObject *self, PyObject *_null) +{ + return PyUnicode_FromString(SDL_GetPlatform()); +} + static PyObject * pg_system_get_pref_path(PyObject *self, PyObject *args, PyObject *kwargs) { @@ -252,10 +264,14 @@ pg_system_get_power_state(PyObject *self, PyObject *_null) } static PyMethodDef _system_methods[] = { + {"get_cpu_cores", pg_system_get_cpu_cores, METH_NOARGS, + DOC_SYSTEM_GETCPUCORES}, {"get_cpu_instruction_sets", pg_system_get_cpu_instruction_sets, METH_NOARGS, DOC_SYSTEM_GETCPUINSTRUCTIONSETS}, {"get_total_ram", pg_system_get_total_ram, METH_NOARGS, DOC_SYSTEM_GETTOTALRAM}, + {"get_platform", pg_system_get_platform, METH_NOARGS, + DOC_SYSTEM_GETPLATFORM}, {"get_pref_path", (PyCFunction)pg_system_get_pref_path, METH_VARARGS | METH_KEYWORDS, DOC_SYSTEM_GETPREFPATH}, {"get_pref_locales", pg_system_get_pref_locales, METH_NOARGS, diff --git a/test/system_test.py b/test/system_test.py index e03921c72a..82fe2c37ce 100644 --- a/test/system_test.py +++ b/test/system_test.py @@ -5,6 +5,11 @@ class SystemModuleTest(unittest.TestCase): + def test_get_cpu_cores(self): + cpu = pygame.system.get_cpu_cores() + + self.assertIsInstance(cpu, int) + def test_get_cpu_instruction_sets(self): instruction_sets = pygame.system.get_cpu_instruction_sets() @@ -17,6 +22,11 @@ def test_get_total_ram(self): self.assertIsInstance(ram, int) + def test_get_platform(self): + platform = pygame.system.get_platform() + + self.assertIsInstance(platform, str) + def test_get_pref_path(self): get_pref_path = pygame.system.get_pref_path