Skip to content

Commit 6d79820

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 efc1311 commit 6d79820

File tree

2 files changed

+377
-73
lines changed

2 files changed

+377
-73
lines changed

src/util/convert_bootstrap.py

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

413413
def __init__(self, src_version, dst_version, *, is_html=False, is_qweb=False):
414+
self.src_version = src_version
415+
self.dst_version = dst_version
414416
conversions = self._get_conversions(src_version, dst_version)
415417
super().__init__(conversions, is_html=is_html, is_qweb=is_qweb)
416418

@@ -448,14 +450,6 @@ def _get_conversions(cls, src_version, dst_version):
448450
return result
449451

450452

451-
convert_tree = BootstrapConverter.convert_tree
452-
convert_arch = BootstrapConverter.convert_arch
453-
convert_file = BootstrapConverter.convert_file
454-
455-
bs3to4_converter = BootstrapConverter("3.0", "4.0")
456-
bs4to5_converter = BootstrapConverter("4.0", "5.0")
457-
458-
459453
# TODO abt: remove this / usages -> replace with refactored converter classes
460454
class BootstrapHTMLConverter:
461455
def __init__(self, src, dst):
@@ -465,5 +459,5 @@ def __init__(self, src, dst):
465459
def __call__(self, content):
466460
if not content:
467461
return False, content
468-
converted_content = convert_arch(content, self.src, self.dst, is_html=True, is_qweb=True)
462+
converted_content = BootstrapConverter.convert_arch(content, self.src, self.dst, is_html=True, is_qweb=True)
469463
return content != converted_content, converted_content

0 commit comments

Comments
 (0)