Skip to content

Commit 645df3d

Browse files
committed
doc(hansbug): add new part of quick start
1 parent 8da2f52 commit 645df3d

File tree

7 files changed

+92
-0
lines changed

7 files changed

+92
-0
lines changed

docs/source/_shims/potc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env python
2+
3+
from potc.entry.cli import potc_cli
4+
5+
if __name__ == '__main__':
6+
potc_cli()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
potc trans data.v_a
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
potc trans data.v_b -I
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
potc export -v 'data.v_*'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
potc export -v 'data.v_*' -r plugins.potc_dict.potc_dict.plugin.__rules__
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import math
2+
3+
v_a = [1, 'kdfgjs', None, math.pi]
4+
v_b = {
5+
'a': v_a,
6+
'b': (3, 4, 'dfg'),
7+
0: {'a': 3, 'b': None, 'c': math.e}
8+
}

docs/source/tutorials/quick_start/index.rst

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ A simplest translation can be processed with the code below.
1111

1212
.. literalinclude:: simple.demo.py
1313
:language: python
14+
:linenos:
1415

1516
The output result should be
1617

1718
.. literalinclude:: simple.demo.py.txt
1819
:language: text
20+
:linenos:
1921

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

2931
.. literalinclude:: vars.demo.py
3032
:language: python
33+
:linenos:
3134

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

3437
.. literalinclude:: vars.demo.py.txt
3538
:language: python
39+
:linenos:
3640

3741
It is runnable, you can take a try.
3842

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

5054
.. literalinclude:: diy_rule.demo.py
5155
:language: python
56+
:linenos:
5257

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

5560
.. literalinclude:: diy_rule.demo.py.txt
5661
:language: python
62+
:linenos:
5763

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

69+
70+
Use CLI For Translating
71+
-------------------------------
72+
73+
In ``potc``, cli is provided to quickly generate python code. \
74+
For example, you can translate an object with ``potc trans`` \
75+
command. Firstly, here is the content of python source \
76+
file ``data.py``
77+
78+
.. literalinclude:: data.py
79+
:language: shell
80+
:linenos:
81+
82+
based on this, we can translate ``v_a`` from ``data.py`` by \
83+
this command
84+
85+
.. literalinclude:: cli_obj_1.demo.sh
86+
:language: shell
87+
:linenos:
88+
89+
The output should be
90+
91+
.. literalinclude:: cli_obj_1.demo.sh.txt
92+
:language: text
93+
:linenos:
94+
95+
Also, if you need to take a look at the full information of \
96+
this translation, you can use ``-I`` option to display them, \
97+
like this
98+
99+
.. literalinclude:: cli_obj_2.demo.sh
100+
:language: shell
101+
:linenos:
102+
103+
The output (including information) should be
104+
105+
.. literalinclude:: cli_obj_2.demo.sh.txt
106+
:language: text
107+
:linenos:
108+
109+
110+
In further cases, we may need to directly dump a runnable \
111+
python source code and then maybe execute it. You can dump \
112+
the variables from ``data.py`` by this command
113+
114+
.. literalinclude:: cli_vars_1.demo.sh
115+
:language: shell
116+
:linenos:
117+
118+
The dumped code should be
119+
120+
.. literalinclude:: cli_vars_1.demo.sh.txt
121+
:language: shell
122+
:linenos:
123+
124+
125+
Besides, you can use your self-defined rules to change the \
126+
dumping result, like this
127+
128+
.. literalinclude:: cli_vars_2.demo.sh
129+
:language: shell
130+
:linenos:
131+
132+
The new dumped code should be
133+
134+
.. literalinclude:: cli_vars_2.demo.sh.txt
135+
:language: shell
136+
:linenos:

0 commit comments

Comments
 (0)