From 7d738cf27726edf2025b2ca5206139427939579d Mon Sep 17 00:00:00 2001 From: HansBug Date: Mon, 3 Jan 2022 21:15:16 +0800 Subject: [PATCH] dev(hansbug): add support for treevalue[potc] --- README.md | 11 +++++- docs/source/index.rst | 1 + docs/source/tutorials/plugins/index.rst | 37 +++++++++++++++++++ .../tutorials/plugins/potc_demo.demo.py | 19 ++++++++++ requirements-doc.txt | 3 +- requirements-potc.txt | 1 + 6 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 docs/source/tutorials/plugins/index.rst create mode 100644 docs/source/tutorials/plugins/potc_demo.demo.py create mode 100644 requirements-potc.txt diff --git a/README.md b/README.md index 2ab728cb6f..2c5e082289 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,16 @@ You can simply install it with `pip` command line from the official PyPI site. pip install treevalue ``` -For more information about installation, you can refer to [Installation](https://opendilab.github.io/treevalue/main/tutorials/installation/index.html#). +If you want to link with the [potc](https://github.com/potc-dev/potc) package so that treevalue can support source code conversion, you can use the following command to install it. + +```shell +pip install treevalue[potc] +``` + +For more information about installation, you can refer to + +* [Installation](https://opendilab.github.io/treevalue/main/tutorials/installation/index.html) +* [Potc Plugin Installation](https://opendilab.github.io/treevalue/main/tutorials/plugins/index.html#potc-support) ## Documentation diff --git a/docs/source/index.rst b/docs/source/index.rst index d84cd86b3e..adc64d93a8 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -19,6 +19,7 @@ structure processing when the calculation is tree-based. tutorials/basic_usage/index tutorials/advanced_usage/index tutorials/cli_usage/index + tutorials/plugins/index .. toctree:: diff --git a/docs/source/tutorials/plugins/index.rst b/docs/source/tutorials/plugins/index.rst new file mode 100644 index 0000000000..9d417053ed --- /dev/null +++ b/docs/source/tutorials/plugins/index.rst @@ -0,0 +1,37 @@ +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 + +.. code:: shell + + pip install treevalue[potc] + +After this installation, you will be able to directly convert treevalue to an object without any additional operations. +Such as + +.. literalinclude:: ./potc_demo.demo.py + :language: python + :linenos: + +The output should be + +.. literalinclude:: ./potc_demo.demo.py.txt + :language: text + :linenos: + +Also, you can use the following CLI command to get the same output results as above. + +.. code:: shell + + potc export -v 'test_simple.t' -v 'test_simple.st' -v 'test_simple.r' + +For further information, you can refer to + +* `potc-dev/potc `_ +* `potc-dev/potc-treevalue `_ diff --git a/docs/source/tutorials/plugins/potc_demo.demo.py b/docs/source/tutorials/plugins/potc_demo.demo.py new file mode 100644 index 0000000000..fb155deb27 --- /dev/null +++ b/docs/source/tutorials/plugins/potc_demo.demo.py @@ -0,0 +1,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) diff --git a/requirements-doc.txt b/requirements-doc.txt index 0b603d05a3..9325b15e9d 100644 --- a/requirements-doc.txt +++ b/requirements-doc.txt @@ -8,4 +8,5 @@ sphinx-multiversion~=0.2.4 where~=1.0.2 numpy>=1.19,<2 easydict>=1.7,<2 -scikit-learn>=0.24.2 \ No newline at end of file +scikit-learn>=0.24.2 +potc-treevalue>=0.0.1 \ No newline at end of file diff --git a/requirements-potc.txt b/requirements-potc.txt new file mode 100644 index 0000000000..acf46dddd9 --- /dev/null +++ b/requirements-potc.txt @@ -0,0 +1 @@ +potc-treevalue>=0.0.1 \ No newline at end of file -- GitLab