@@ -161,6 +161,31 @@ to see the other functionalities.
161
161
using only the ``default_registry ``. There's no need to declare multiple
162
162
:class: `~.PageObjectRegistry ` instances and use multiple annotations.
163
163
164
+ .. warning ::
165
+
166
+ :meth: `~.PageObjectRegistry.get_overrides ` relies on the fact that all essential
167
+ packages/modules which contains the :meth: `~.PageObjectRegistry.handle_urls `
168
+ annotations are properly loaded.
169
+
170
+ Thus, for cases like importing Page Objects from another external package, you'd
171
+ need to properly load all :meth: `~.PageObjectRegistry.handle_urls ` annotations
172
+ from the external module. This ensures that the external Page Objects' have
173
+ their annotations properly loaded.
174
+
175
+ This can be done via the function named :func: `~.web_poet.overrides.consume_modules `.
176
+ Here's an example:
177
+
178
+ .. code-block :: python
179
+
180
+ from web_poet import default_registry, consume_modules
181
+
182
+ consume_modules(" external_package_A.po" , " another_ext_package.lib" )
183
+ rules = default_registry.get_overrides()
184
+
185
+ **NOTE **: :func: `~.web_poet.overrides.consume_modules ` must be called before
186
+ :meth: `~.PageObjectRegistry.get_overrides ` for the imports to properly load.
187
+
188
+
164
189
A handy CLI tool is also available at your disposal to quickly see the available
165
190
Override rules in a given module in your project. For example, invoking something
166
191
like ``web_poet my_project.page_objects `` would produce the following:
@@ -226,7 +251,7 @@ Then we could easily retrieve all Page Objects per subpackage or module like thi
226
251
227
252
.. code-block :: python
228
253
229
- from web_poet import default_registry
254
+ from web_poet import default_registry, consume_modules
230
255
231
256
# We can do it per website.
232
257
rules = default_registry.get_overrides_from(" my_page_obj_project.cool_gadget_site" )
@@ -236,11 +261,16 @@ Then we could easily retrieve all Page Objects per subpackage or module like thi
236
261
rules = default_registry.get_overrides_from(" my_page_obj_project.cool_gadget_site.us" )
237
262
rules = default_registry.get_overrides_from(" my_page_obj_project.cool_gadget_site.fr" )
238
263
239
- # or even drill down further to the specific module.
264
+ # Or even drill down further to the specific module.
240
265
rules = default_registry.get_overrides_from(" my_page_obj_project.cool_gadget_site.us.products" )
241
266
rules = default_registry.get_overrides_from(" my_page_obj_project.cool_gadget_site.us.product_listings" )
242
267
243
- # Or simply all of Override rules ever declared.
268
+ # Or simply all of the Override rules ever declared.
269
+ rules = default_registry.get_overrides()
270
+
271
+ # Lastly, you'd need to properly load external packages/modules for the
272
+ # @handle_urls annotation to be correctly read.
273
+ consume_modules(" external_package_A.po" , " another_ext_package.lib" )
244
274
rules = default_registry.get_overrides()
245
275
246
276
Multiple Registry Approach
0 commit comments