Skip to content

Commit d5e7f79

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 2553f7c commit d5e7f79

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
@@ -419,6 +419,8 @@ class BootstrapConverter(EtreeConverter):
419419
}
420420

421421
def __init__(self, src_version, dst_version, *, is_html=False, is_qweb=False):
422+
self.src_version = src_version
423+
self.dst_version = dst_version
422424
conversions = self._get_conversions(src_version, dst_version)
423425
super().__init__(conversions, is_html=is_html, is_qweb=is_qweb)
424426

@@ -456,14 +458,6 @@ def _get_conversions(cls, src_version, dst_version):
456458
return result
457459

458460

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

0 commit comments

Comments
 (0)