Plugins

Potc support

Potc is a package that can convert any object into executable source code. For treevalue, potc can support the source code transformation of treevalue objects through the installation of additional plugins. So we can execute the following installation command

pip install treevalue[potc]

After this installation, you will be able to directly convert treevalue to an object without any additional operations. Such as

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
from potc import transvars

from treevalue import FastTreeValue, raw

r = raw({'a': 1, 'b': 2, 'c': [3, 4]})
t = FastTreeValue({
    'a': 1, 'b': 'this is a string',
    'c': [], 'd': {
        'x': raw({'a': 1, 'b': (None, Ellipsis)}),
        'y': {3, 4, 5}
    }
})
st = t._detach()
if __name__ == '__main__':
    _code = transvars(
        {'t': t, 'st': t._detach(), 'r': r},
        reformat='pep8'
    )
    print(_code)

The output should be

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from treevalue import FastTreeValue, raw
from treevalue.tree.common import create_storage

__all__ = ['r', 'st', 't']
r = raw({'a': 1, 'b': 2, 'c': [3, 4]})
st = create_storage({
    'a': 1,
    'b': 'this is a string',
    'c': [],
    'd': {
        'x': {
            '__treevalue/raw/wrapper': {
                'a': 1,
                'b': (None, ...)
            }
        },
        'y': {3, 4, 5}
    }
})
t = FastTreeValue({
    'a': 1,
    'b': 'this is a string',
    'c': [],
    'd': {
        'x': {
            '__treevalue/raw/wrapper': {
                'a': 1,
                'b': (None, ...)
            }
        },
        'y': {3, 4, 5}
    }
})

Also, you can use the following CLI command to get the same output results as above.

potc export -v 'test_simple.t' -v 'test_simple.st' -v 'test_simple.r'

For further information, you can refer to