Skip to content

Commit

Permalink
doc(hansbug): add new part of quick start
Browse files Browse the repository at this point in the history
  • Loading branch information
HansBug committed Oct 8, 2021
1 parent 8da2f52 commit 645df3d
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/source/_shims/potc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env python

from potc.entry.cli import potc_cli

if __name__ == '__main__':
potc_cli()
1 change: 1 addition & 0 deletions docs/source/tutorials/quick_start/cli_obj_1.demo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
potc trans data.v_a
1 change: 1 addition & 0 deletions docs/source/tutorials/quick_start/cli_obj_2.demo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
potc trans data.v_b -I
1 change: 1 addition & 0 deletions docs/source/tutorials/quick_start/cli_vars_1.demo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
potc export -v 'data.v_*'
1 change: 1 addition & 0 deletions docs/source/tutorials/quick_start/cli_vars_2.demo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
potc export -v 'data.v_*' -r plugins.potc_dict.potc_dict.plugin.__rules__
8 changes: 8 additions & 0 deletions docs/source/tutorials/quick_start/data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import math

v_a = [1, 'kdfgjs', None, math.pi]
v_b = {
'a': v_a,
'b': (3, 4, 'dfg'),
0: {'a': 3, 'b': None, 'c': math.e}
}
74 changes: 74 additions & 0 deletions docs/source/tutorials/quick_start/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ A simplest translation can be processed with the code below.

.. literalinclude:: simple.demo.py
:language: python
:linenos:

The output result should be

.. literalinclude:: simple.demo.py.txt
:language: text
:linenos:

Most of the primitive data types supported by python can be \
turned back to runnable source code with ``potc``.
Expand All @@ -28,11 +30,13 @@ result to a runnable ``.py`` script, we can do like this

.. literalinclude:: vars.demo.py
:language: python
:linenos:

The output result (as well as the dumped script) should be

.. literalinclude:: vars.demo.py.txt
:language: python
:linenos:

It is runnable, you can take a try.

Expand All @@ -49,14 +53,84 @@ You can define your own rule like the example below.

.. literalinclude:: diy_rule.demo.py
:language: python
:linenos:

The output result (as well as the dumped script) should be

.. literalinclude:: diy_rule.demo.py.txt
:language: python
:linenos:

Now you can see the dictionaries will be expressed with \
``dict`` form when the keys is allowed to do so, \
the ``np.ndarray`` objects will be expressed with the \
visible format as well.


Use CLI For Translating
-------------------------------

In ``potc``, cli is provided to quickly generate python code. \
For example, you can translate an object with ``potc trans`` \
command. Firstly, here is the content of python source \
file ``data.py``

.. literalinclude:: data.py
:language: shell
:linenos:

based on this, we can translate ``v_a`` from ``data.py`` by \
this command

.. literalinclude:: cli_obj_1.demo.sh
:language: shell
:linenos:

The output should be

.. literalinclude:: cli_obj_1.demo.sh.txt
:language: text
:linenos:

Also, if you need to take a look at the full information of \
this translation, you can use ``-I`` option to display them, \
like this

.. literalinclude:: cli_obj_2.demo.sh
:language: shell
:linenos:

The output (including information) should be

.. literalinclude:: cli_obj_2.demo.sh.txt
:language: text
:linenos:


In further cases, we may need to directly dump a runnable \
python source code and then maybe execute it. You can dump \
the variables from ``data.py`` by this command

.. literalinclude:: cli_vars_1.demo.sh
:language: shell
:linenos:

The dumped code should be

.. literalinclude:: cli_vars_1.demo.sh.txt
:language: shell
:linenos:


Besides, you can use your self-defined rules to change the \
dumping result, like this

.. literalinclude:: cli_vars_2.demo.sh
:language: shell
:linenos:

The new dumped code should be

.. literalinclude:: cli_vars_2.demo.sh.txt
:language: shell
:linenos:

0 comments on commit 645df3d

Please sign in to comment.