Skip to content

Commit b7976b0

Browse files
committed
[REF] util.views: moved views/html convert helpers from BS5 script
Move xpath keywords / where clause functions from base/16.0 pre-90-convert-bootstrap5.py script into util.views and add shortcut methods for them in converter class. Also refactored to make them usable with arbitrary converters. Revise converter API, especially simplified classmethods / remove oneshot aliases (it's easier to just instantiate the converter first). Refactor parse/unparse string arch code into separate helper functions, and add a `ArchEditor` context manager to parse-edit-unparse an arch within a context (similar to edit_views). Make sure EtreeConverter is pickle-able for multiprocessing: concurrent.futures ProcessPoolExecutor uses multiprocessing to spawn its subprocess workers. That requires memory data from the main process to be transferred by serializing and deserializing, using the pickle library. To make this work: - the converter function must not be an anonymous "factory" function,   e.g. one generated as a nested function, so unaccessible from the   outer scope. - instance values in the serialized objects must also be pickleable. Therefore the following changes have been done: - the converter function is now a method of the converter class - to keep @lru_cache decorator on the method, the entire class is   made hashable, this is done by computing a hash of the provided   arguments to `__init__`, making some attributes "private", and   adding read-only properties to access them. - to make the instances pickable, the compiled coversions are first   removed from the pickle-able `__dict__`, because `lxml.XPath`   objects are not python-native, and they're re-compiled when the   instances are de-serialized. upgrade PR: odoo/upgrade#5431
1 parent 4d0a75d commit b7976b0

File tree

2 files changed

+367
-73
lines changed

2 files changed

+367
-73
lines changed

src/util/convert_bootstrap.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,8 @@ class BootstrapConverter(EtreeConverter):
418418
}
419419

420420
def __init__(self, src_version, dst_version, *, is_html=False, is_qweb=False):
421+
self.src_version = src_version
422+
self.dst_version = dst_version
421423
conversions = self._get_conversions(src_version, dst_version)
422424
super().__init__(conversions, is_html=is_html, is_qweb=is_qweb)
423425

@@ -455,14 +457,6 @@ def _get_conversions(cls, src_version, dst_version):
455457
return result
456458

457459

458-
convert_tree = BootstrapConverter.convert_tree
459-
convert_arch = BootstrapConverter.convert_arch
460-
convert_file = BootstrapConverter.convert_file
461-
462-
bs3to4_converter = BootstrapConverter("3.0", "4.0")
463-
bs4to5_converter = BootstrapConverter("4.0", "5.0")
464-
465-
466460
# TODO abt: remove this / usages -> replace with refactored converter classes
467461
class BootstrapHTMLConverter:
468462
def __init__(self, src, dst):
@@ -472,5 +466,5 @@ def __init__(self, src, dst):
472466
def __call__(self, content):
473467
if not content:
474468
return False, content
475-
converted_content = convert_arch(content, self.src, self.dst, is_html=True, is_qweb=True)
469+
converted_content = BootstrapConverter.convert_arch(content, self.src, self.dst, is_html=True, is_qweb=True)
476470
return content != converted_content, converted_content

0 commit comments

Comments
 (0)