Skip to content

Commit 8ed529e

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 8ed529e

File tree

11 files changed

+55
-0
lines changed

11 files changed

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

50+
#if MICROPY_MODULE_BUILTIN_SUBPACKAGES
51+
#if PYBRICKS_PY_EXPERIMENTAL
52+
extern const mp_obj_module_t pb_module_experimental;
53+
#endif
54+
#if PYBRICKS_PY_HUBS
55+
extern const mp_obj_module_t pb_module_hubs;
56+
#endif
57+
#if PYBRICKS_PY_NXTDEVICES
58+
extern const mp_obj_module_t pb_module_nxtdevices;
59+
#endif
60+
#if PYBRICKS_PY_EV3DEVICES
61+
extern const mp_obj_module_t pb_module_ev3devices;
62+
#endif
63+
#if PYBRICKS_PY_PUPDEVICES
64+
extern const mp_obj_module_t pb_module_pupdevices;
65+
#endif
66+
#if PYBRICKS_PY_IODEVICES
67+
extern const mp_obj_module_t pb_module_iodevices;
68+
#endif
69+
#if PYBRICKS_PY_MEDIA
70+
extern const mp_obj_module_t pb_module_media;
71+
#endif
72+
#if PYBRICKS_PY_PARAMETERS
73+
extern const mp_obj_module_t pb_module_parameters;
74+
#endif
75+
#if PYBRICKS_PY_TOOLS
76+
extern const mp_obj_module_t pb_module_tools;
77+
#endif
78+
#if PYBRICKS_PY_ROBOTICS
79+
extern const mp_obj_module_t pb_module_robotics;
80+
#endif
81+
#endif
82+
5083
static const mp_rom_map_elem_t pybricks_globals_table[] = {
5184
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_pybricks) },
5285
{ 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)