Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions buildconfig/stubs/pygame/system.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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.

Expand Down
2 changes: 2 additions & 0 deletions src_c/doc/system_doc.h
Original file line number Diff line number Diff line change
@@ -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."
16 changes: 16 additions & 0 deletions src_c/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions test/system_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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

Expand Down
Loading