@@ -118,6 +118,8 @@ by simply importing them:
118
118
page = FurnitureProductPage(response)
119
119
item = page.to_item()
120
120
121
+ .. _`pop-recommended-requirements` :
122
+
121
123
Recommended Requirements
122
124
~~~~~~~~~~~~~~~~~~~~~~~~
123
125
@@ -143,13 +145,15 @@ inside of ``ecommerce-page-objects/ecommerce_page_objects/__init__.py``:
143
145
144
146
.. code-block :: python
145
147
146
- from web_poet import default_registry, consume_modules
148
+ from web_poet import default_registry
147
149
148
- # This allows all of the OverrideRules declared inside the package
149
- # using @handle_urls to be properly discovered and loaded.
150
- consume_modules(__package__ )
150
+ REGISTRY = default_registry.export(__package__ )
151
151
152
- REGISTRY = default_registry
152
+ The :meth: `~.PageObjectRegistry.export ` method returns a new instance of
153
+ :class: `~.PageObjectRegistry ` which contains only the :class: `~.OverrideRule `
154
+ from the given package. This means that if there are other **POPs ** using the
155
+ recommended ``default_registry ``, any :class: `~.OverrideRule ` that are not part
156
+ of the packages are not included.
153
157
154
158
This allows any developer using a **POP ** to easily access all of the
155
159
:class: `~.OverrideRule ` using the convention of accessing it via the
@@ -173,8 +177,35 @@ This allows any developer using a **POP** to easily access all of the
173
177
174
178
However, it is **recommended ** to use the instances of
175
179
:class: `~.PageObjectRegistry ` to leverage the validation logic for its
176
- contents.
180
+ contents, as well as its other functionalities.
181
+
182
+ Lastly, when trying to repackage multiple **POPs ** into a single unifying **POP **
183
+ which contains all of the :class: `~.OverrideRule `, it can easily be packaged
184
+ as:
185
+
186
+ .. code-block :: python
187
+
188
+ from web_poet import PageObjectRegistry
189
+
190
+ import base_A_package
191
+ import base_B_package
192
+
193
+ # If on Python 3.9+
194
+ combined_rules = base_A_package.REGISTRY | base_B_package.REGISTRY
195
+
196
+ # If on lower Python versions
197
+ combined_rules = {** base_A_package.REGISTRY , ** base_B_package.REGISTRY }
198
+
199
+ REGISTRY = PageObjectRegistry(combined_rules)
200
+
201
+ Note that you can also opt to use only a subset of the :class: `~.OverrideRule `
202
+ by selecting the specific ones in ``combined_rules `` before creating a new
203
+ :class: `~.PageObjectRegistry ` instance. An **inclusion ** rule is preferred than
204
+ an **exclusion ** rule (see **Tip #4 ** in the :ref: `conventions-and-best-practices `).
205
+ You can use :meth: `~.PageObjectRegistry.search_overrides ` when selecting the
206
+ rules.
177
207
208
+ .. _`conventions-and-best-practices` :
178
209
179
210
Conventions and Best Practices
180
211
------------------------------
0 commit comments