Skip to content

Commit 6607153

Browse files
committed
pybricks: modules: add conditional around MP_REGISTER_MODULE()
Add a conditional compilation check around MP_REGISTER_MODULE() that checks MICROPY_MODULE_BUILTIN_SUBPACKAGES. If this option is enabled, we don't need to register subpackages as they are already handled by the parent package.
1 parent 343793b commit 6607153

File tree

11 files changed

+32
-0
lines changed

11 files changed

+32
-0
lines changed

pybricks/ev3devices/pb_module_ev3devices.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ const mp_obj_module_t pb_module_ev3devices = {
2828
.globals = (mp_obj_dict_t *)&pb_module_ev3devices_globals,
2929
};
3030

31+
#if !MICROPY_MODULE_BUILTIN_SUBPACKAGES
3132
MP_REGISTER_MODULE(MP_QSTR_pybricks_dot_ev3devices, pb_module_ev3devices);
33+
#endif
3234

3335
#endif // PYBRICKS_PY_EV3DEVICES

pybricks/experimental/pb_module_experimental.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ const mp_obj_module_t pb_module_experimental = {
6969
.globals = (mp_obj_dict_t *)&pb_module_experimental_globals,
7070
};
7171

72+
#if !MICROPY_MODULE_BUILTIN_SUBPACKAGES
7273
MP_REGISTER_MODULE(MP_QSTR_pybricks_dot_experimental, pb_module_experimental);
74+
#endif
7375

7476
#endif // PYBRICKS_PY_EXPERIMENTAL

pybricks/hubs/pb_module_hubs.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ const mp_obj_module_t pb_module_hubs = {
2626
.globals = (mp_obj_dict_t *)&pb_module_hubs_globals,
2727
};
2828

29+
#if !MICROPY_MODULE_BUILTIN_SUBPACKAGES
2930
MP_REGISTER_MODULE(MP_QSTR_pybricks_dot_hubs, pb_module_hubs);
31+
#endif
3032

3133
#endif // PYBRICKS_PY_HUBS

pybricks/iodevices/pb_module_iodevices.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ const mp_obj_module_t pb_module_iodevices = {
3535
.globals = (mp_obj_dict_t *)&pb_module_iodevices_globals,
3636
};
3737

38+
#if !MICROPY_MODULE_BUILTIN_SUBPACKAGES
3839
MP_REGISTER_MODULE(MP_QSTR_pybricks_dot_iodevices, pb_module_iodevices);
40+
#endif
3941

4042
#endif // PYBRICKS_PY_IODEVICES

pybricks/media/pb_module_media.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ const mp_obj_module_t pb_module_media = {
2020
.globals = (mp_obj_dict_t *)&pb_module_media_globals,
2121
};
2222

23+
#if !MICROPY_MODULE_BUILTIN_SUBPACKAGES
2324
MP_REGISTER_MODULE(MP_QSTR_pybricks_dot_media, pb_module_media);
25+
#endif
2426

2527
#endif // PYBRICKS_PY_MEDIA

pybricks/nxtdevices/pb_module_nxtdevices.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ const mp_obj_module_t pb_module_nxtdevices = {
3030
.globals = (mp_obj_dict_t *)&pb_module_nxtdevices_globals,
3131
};
3232

33+
#if !MICROPY_MODULE_BUILTIN_SUBPACKAGES
3334
MP_REGISTER_MODULE(MP_QSTR_pybricks_dot_nxtdevices, pb_module_nxtdevices);
35+
#endif
3436

3537
#endif // PYBRICKS_PY_NXTDEVICES

pybricks/parameters/pb_module_parameters.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ const mp_obj_module_t pb_module_parameters = {
3030
.globals = (mp_obj_dict_t *)&pb_module_parameters_globals,
3131
};
3232

33+
#if !MICROPY_MODULE_BUILTIN_SUBPACKAGES
3334
MP_REGISTER_MODULE(MP_QSTR_pybricks_dot_parameters, pb_module_parameters);
35+
#endif
3436

3537
#endif // PYBRICKS_PY_PARAMETERS

pybricks/pupdevices/pb_module_pupdevices.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ const mp_obj_module_t pb_module_pupdevices = {
3535
.globals = (mp_obj_dict_t *)&pb_module_pupdevices_globals,
3636
};
3737

38+
#if !MICROPY_MODULE_BUILTIN_SUBPACKAGES
3839
MP_REGISTER_MODULE(MP_QSTR_pybricks_dot_pupdevices, pb_module_pupdevices);
40+
#endif
3941

4042
#endif // PYBRICKS_PY_PUPDEVICES

pybricks/pybricks.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,33 +52,43 @@ static const mp_rom_map_elem_t pybricks_globals_table[] = {
5252
{ MP_ROM_QSTR(MP_QSTR_version), MP_ROM_PTR(&pybricks_info_obj)},
5353
#if MICROPY_MODULE_BUILTIN_SUBPACKAGES
5454
#if PYBRICKS_PY_EXPERIMENTAL
55+
extern const mp_obj_module_t pb_module_experimental;
5556
{ MP_ROM_QSTR(MP_QSTR_experimental), MP_ROM_PTR(&pb_module_experimental) },
5657
#endif
5758
#if PYBRICKS_PY_HUBS
59+
extern const mp_obj_module_t pb_module_hubs;
5860
{ MP_ROM_QSTR(MP_QSTR_hubs), MP_ROM_PTR(&pb_module_hubs) },
5961
#endif
6062
#if PYBRICKS_PY_NXTDEVICES
63+
extern const mp_obj_module_t pb_module_nxtdevices;
6164
{ MP_ROM_QSTR(MP_QSTR_nxtdevices), MP_ROM_PTR(&pb_module_nxtdevices) },
6265
#endif
6366
#if PYBRICKS_PY_EV3DEVICES
67+
extern const mp_obj_module_t pb_module_ev3devices;
6468
{ MP_ROM_QSTR(MP_QSTR_ev3devices), MP_ROM_PTR(&pb_module_ev3devices) },
6569
#endif
6670
#if PYBRICKS_PY_PUPDEVICES
71+
extern const mp_obj_module_t pb_module_pupdevices;
6772
{ MP_ROM_QSTR(MP_QSTR_pupdevices), MP_ROM_PTR(&pb_module_pupdevices) },
6873
#endif
6974
#if PYBRICKS_PY_IODEVICES
75+
extern const mp_obj_module_t pb_module_iodevices;
7076
{ MP_ROM_QSTR(MP_QSTR_iodevices), MP_ROM_PTR(&pb_module_iodevices) },
7177
#endif
7278
#if PYBRICKS_PY_MEDIA
79+
extern const mp_obj_module_t pb_module_media;
7380
{ MP_ROM_QSTR(MP_QSTR_media), MP_ROM_PTR(&pb_module_media) },
7481
#endif
7582
#if PYBRICKS_PY_PARAMETERS
83+
extern const mp_obj_module_t pb_module_parameters;
7684
{ MP_ROM_QSTR(MP_QSTR_parameters), MP_ROM_PTR(&pb_module_parameters) },
7785
#endif
7886
#if PYBRICKS_PY_TOOLS
87+
extern const mp_obj_module_t pb_module_tools;
7988
{ MP_ROM_QSTR(MP_QSTR_tools), MP_ROM_PTR(&pb_module_tools) },
8089
#endif
8190
#if PYBRICKS_PY_ROBOTICS
91+
extern const mp_obj_module_t pb_module_robotics;
8292
{ MP_ROM_QSTR(MP_QSTR_robotics), MP_ROM_PTR(&pb_module_robotics) },
8393
#endif
8494
#endif

pybricks/robotics/pb_module_robotics.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ const mp_obj_module_t pb_module_robotics = {
2828
.globals = (mp_obj_dict_t *)&pb_module_robotics_globals,
2929
};
3030

31+
#if !MICROPY_MODULE_BUILTIN_SUBPACKAGES
3132
MP_REGISTER_MODULE(MP_QSTR_pybricks_dot_robotics, pb_module_robotics);
33+
#endif
3234

3335
#endif // PYBRICKS_PY_ROBOTICS

0 commit comments

Comments
 (0)