@@ -148,18 +148,18 @@ to see the other functionalities.
148
148
rules = default_registry.get_overrides()
149
149
150
150
# Or, we could also filter out the rules by the module they were defined in
151
- rules = default_registry.get_overrides_from( " my_project.page_objects" )
151
+ rules = default_registry.get_overrides( filters = " my_project.page_objects" )
152
152
153
153
print (len (rules)) # 3
154
154
print (rules[0 ]) # OverrideRule(for_patterns=Patterns(include=['example.com'], exclude=[], priority=500), use=<class 'my_project.page_objects.ExampleProductPage'>, instead_of=<class 'my_project.page_objects.GenericProductPage'>, meta={})
155
155
156
156
.. note ::
157
157
158
158
Notice in the code sample above where we could filter out the Override rules
159
- per module via :meth: ` ~.PageObjectRegistry.get_overrides_from ` . This
160
- could also offer another alternative way to organize your Page Object rules
161
- using only the `` default_registry ``. There's no need to declare multiple
162
- :class: ` ~.PageObjectRegistry ` instances and use multiple annotations.
159
+ per module via the `` filters `` param . This could also offer another alternative
160
+ way to organize your Page Object rules using only the `` default_registry ``.
161
+ There's no need to declare multiple :class: ` ~.PageObjectRegistry ` instances
162
+ and use multiple annotations.
163
163
164
164
.. warning ::
165
165
@@ -182,8 +182,12 @@ to see the other functionalities.
182
182
consume_modules(" external_package_A.po" , " another_ext_package.lib" )
183
183
rules = default_registry.get_overrides()
184
184
185
- **NOTE **: :func: `~.web_poet.overrides.consume_modules ` must be called before
186
- :meth: `~.PageObjectRegistry.get_overrides ` for the imports to properly load.
185
+ # Fortunately, `get_overrides()` provides a shortcut for the lines above:
186
+ rules = default_registry.get_overrides(consume = [" external_package_A.po" , " another_ext_package.lib" ])
187
+
188
+ **NOTE **: :func: `~.web_poet.overrides.consume_modules ` or the ``consume `` param
189
+ of :meth: `~.PageObjectRegistry.get_overrides ` for the imports to properly load.
190
+ Most especially if you intend to use Page Objects from externally imported packages.
187
191
188
192
189
193
A handy CLI tool is also available at your disposal to quickly see the available
@@ -254,16 +258,16 @@ Then we could easily retrieve all Page Objects per subpackage or module like thi
254
258
from web_poet import default_registry, consume_modules
255
259
256
260
# We can do it per website.
257
- rules_gadget = default_registry.get_overrides_from( " my_page_obj_project.cool_gadget_site" )
258
- rules_furniture = default_registry.get_overrides_from( " my_page_obj_project.furniture_site" )
261
+ rules_gadget = default_registry.get_overrides( filters = " my_page_obj_project.cool_gadget_site" )
262
+ rules_furniture = default_registry.get_overrides( filters = " my_page_obj_project.furniture_site" )
259
263
260
264
# It can also drill down to the country domains on a given site.
261
- rules_gadget_us = default_registry.get_overrides_from( " my_page_obj_project.cool_gadget_site.us" )
262
- rules_gadget_fr = default_registry.get_overrides_from( " my_page_obj_project.cool_gadget_site.fr" )
265
+ rules_gadget_us = default_registry.get_overrides( filters = " my_page_obj_project.cool_gadget_site.us" )
266
+ rules_gadget_fr = default_registry.get_overrides( filters = " my_page_obj_project.cool_gadget_site.fr" )
263
267
264
268
# Or even drill down further to the specific module.
265
- rules_gadget_us_products = default_registry.get_overrides_from( " my_page_obj_project.cool_gadget_site.us.products" )
266
- rules_gadget_us_listings = default_registry.get_overrides_from( " my_page_obj_project.cool_gadget_site.us.product_listings" )
269
+ rules_gadget_us_products = default_registry.get_overrides( filters = " my_page_obj_project.cool_gadget_site.us.products" )
270
+ rules_gadget_us_listings = default_registry.get_overrides( filters = " my_page_obj_project.cool_gadget_site.us.product_listings" )
267
271
268
272
# Or simply all of the Override rules ever declared.
269
273
rules = default_registry.get_overrides()
@@ -273,11 +277,16 @@ Then we could easily retrieve all Page Objects per subpackage or module like thi
273
277
consume_modules(" external_package_A.po" , " another_ext_package.lib" )
274
278
rules = default_registry.get_overrides()
275
279
280
+ # Remember, a shortcut for consuming imports would be:
281
+ rules = default_registry.get_overrides(consume = [" external_package_A.po" , " another_ext_package.lib" ])
282
+
283
+
276
284
.. warning ::
277
285
278
286
Remember to consider calling :func: `~.web_poet.overrides.consume_modules `
279
- when using :meth: `~.PageObjectRegistry.get_overrides ` in case you have some
280
- external package containing Page Objects of interest.
287
+ or the ``consume `` param of :meth: `~.PageObjectRegistry.get_overrides ` for the
288
+ imports to properly load. Most especially if you intend to use Page Objects
289
+ from externally imported packages.
281
290
282
291
This enables the :meth: `~.PageObjectRegistry.handle_urls ` that annotates
283
292
the external Page Objects to be properly loadeded.
@@ -301,9 +310,9 @@ hierarchy** like this:
301
310
├── furniture_shop_products.py
302
311
└── furniture_shop_product_listings.py
303
312
304
- As such, calling ``default_registry.get_overrides_from () `` would not work
305
- on projects with a **flat hierarchy **. Thus, we can organize them using our own
306
- instances of the :class: `~.PageObjectRegistry ` instead:
313
+ As such, calling ``default_registry.get_overrides () `` with a `` from `` parameter
314
+ would not effectively work on projects with a **flat hierarchy **. Thus, we can
315
+ organize them using our own instances of the :class: `~.PageObjectRegistry ` instead:
307
316
308
317
.. code-block :: python
309
318
@@ -385,10 +394,12 @@ retrieve such rules would be:
385
394
386
395
from web_poet import default_registry
387
396
388
- product_listing_rules = default_registry.get_overrrides_from(
389
- " my_page_obj_project.cool_gadget_site.us.product_listings" ,
390
- " my_page_obj_project.cool_gadget_site.fr.product_listings" ,
391
- " my_page_obj_project.furniture_shop.product_listings"
397
+ product_listing_rules = default_registry.get_overrrides(
398
+ filters = [
399
+ " my_page_obj_project.cool_gadget_site.us.product_listings" ,
400
+ " my_page_obj_project.cool_gadget_site.fr.product_listings" ,
401
+ " my_page_obj_project.furniture_shop.product_listings" ,
402
+ ]
392
403
)
393
404
394
405
On the other hand, we can also create another :class: `~.PageObjectRegistry ` instance
@@ -431,7 +442,7 @@ Retrieving all of the Product Listing Override rules would simply be:
431
442
rules = product_listings_registry.get_overrides()
432
443
433
444
# We can also filter it down further on a per site basis if needed.
434
- rules = product_listings_registry.get_overrides_from( " my_page_obj_project.cool_gadget_site" )
445
+ rules = product_listings_registry.get_overrides( filters = " my_page_obj_project.cool_gadget_site" )
435
446
436
447
Using Overrides from External Packages
437
448
--------------------------------------
@@ -461,6 +472,9 @@ packages** in your project, you can do it like:
461
472
import gadget_sites_page_objects
462
473
from web_poet import PageObjectRegistry, consume_modules, default_registry
463
474
475
+ # We're using `consume_modules()` here instead of the `consume` param of
476
+ # `PageObjectRegistry.get_overrides()` since we need to access the `data`
477
+ # attribute of the registry even before calling `PageObjectRegistry.get_overrides()`
464
478
consume_modules(" ecommerce_page_objects" , " gadget_sites_page_objects" )
465
479
466
480
combined_registry = PageObjectRegistry()
0 commit comments