Skip to content

Commit 3e66cea

Browse files
committed
[REF] util.views_convert: move views/html convert helpers from BS5 mig
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. Made docstrings for new functions private (excluded from online docs). upgrade PR: odoo/upgrade#5431
1 parent d47d0f6 commit 3e66cea

File tree

2 files changed

+405
-75
lines changed

2 files changed

+405
-75
lines changed

src/util/convert_bootstrap.py

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

435435
def __init__(self, src_version, dst_version, *, is_html=False, is_qweb=False):
436+
self.src_version = src_version
437+
self.dst_version = dst_version
436438
conversions = self._get_conversions(src_version, dst_version)
437439
super().__init__(conversions, is_html=is_html, is_qweb=is_qweb)
438440

@@ -476,14 +478,6 @@ def _get_conversions(cls, src_version, dst_version):
476478
return result
477479

478480

479-
convert_tree = BootstrapConverter.convert_tree
480-
convert_arch = BootstrapConverter.convert_arch
481-
convert_file = BootstrapConverter.convert_file
482-
483-
bs3to4_converter = BootstrapConverter("3.0", "4.0")
484-
bs4to5_converter = BootstrapConverter("4.0", "5.0")
485-
486-
487481
# TODO abt: remove this / usages -> replace with refactored converter classes
488482
class BootstrapHTMLConverter:
489483
def __init__(self, src, dst):
@@ -493,5 +487,5 @@ def __init__(self, src, dst):
493487
def __call__(self, content):
494488
if not content:
495489
return False, content
496-
converted_content = convert_arch(content, self.src, self.dst, is_html=True, is_qweb=True)
490+
converted_content = BootstrapConverter.convert_arch(content, self.src, self.dst, is_html=True, is_qweb=True)
497491
return content != converted_content, converted_content

0 commit comments

Comments
 (0)