Skip to content

Commit 0dddb1a

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 0dddb1a

File tree

11 files changed

+54
-0
lines changed

11 files changed

+54
-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: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,38 @@ void pb_package_pybricks_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
4747
}
4848
#endif
4949

50+
#if PYBRICKS_PY_EXPERIMENTAL
51+
extern const mp_obj_module_t pb_module_experimental;
52+
#endif
53+
#if PYBRICKS_PY_HUBS
54+
extern const mp_obj_module_t pb_module_hubs;
55+
#endif
56+
#if PYBRICKS_PY_NXTDEVICES
57+
extern const mp_obj_module_t pb_module_nxtdevices;
58+
#endif
59+
#if PYBRICKS_PY_EV3DEVICES
60+
extern const mp_obj_module_t pb_module_ev3devices;
61+
#endif
62+
#if PYBRICKS_PY_PUPDEVICES
63+
extern const mp_obj_module_t pb_module_pupdevices;
64+
#endif
65+
#if PYBRICKS_PY_IODEVICES
66+
extern const mp_obj_module_t pb_module_iodevices;
67+
#endif
68+
#if PYBRICKS_PY_MEDIA
69+
extern const mp_obj_module_t pb_module_media;
70+
#endif
71+
#if PYBRICKS_PY_PARAMETERS
72+
extern const mp_obj_module_t pb_module_parameters;
73+
#endif
74+
#if PYBRICKS_PY_TOOLS
75+
extern const mp_obj_module_t pb_module_tools;
76+
#endif
77+
#if PYBRICKS_PY_ROBOTICS
78+
extern const mp_obj_module_t pb_module_robotics;
79+
#endif
80+
81+
5082
static const mp_rom_map_elem_t pybricks_globals_table[] = {
5183
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_pybricks) },
5284
{ MP_ROM_QSTR(MP_QSTR_version), MP_ROM_PTR(&pybricks_info_obj)},

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)