Skip to content

Commit c0463d7

Browse files
committed
update docs
1 parent 09840a6 commit c0463d7

7 files changed

Lines changed: 294 additions & 11 deletions

File tree

README.rst

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,43 @@ PythonHere
2222
:alt: Code coverage Status
2323
.. end-badges
2424
25-
Here` is the `Kivy <https://kivy.org>`_ based app to run Python code from the `Jupyter <https://jupyter.org/>`_ magic %there.
25+
*Here* is the `Kivy <https://kivy.org>`_ based app to run Python code from the `Jupyter <https://jupyter.org/>`_ magic %there.
2626

2727
- *Here* is a server part with the GUI interface. It could be Android, Raspberry Pi, some other remote device that being debugged.
2828
- And *%there* is a client - Jupyter magic command to run code interactively on remote device.
2929

3030

31+
.. |jupyter| image:: https://raw.githubusercontent.com/b3b/pythonhere/master/docs/left_jupyter.png
32+
:align: middle
33+
:height: 400
34+
.. |android| image:: https://raw.githubusercontent.com/b3b/pythonhere/master/docs/right_android.png
35+
:align: middle
36+
:height: 400
37+
38+
.. list-table::
39+
:widths: 50 50
40+
:header-rows: 1
41+
42+
* - Jupyter on PC
43+
- Android app
44+
* - |jupyter|
45+
- |android|
46+
47+
Project documentation: https://herethere.me
48+
49+
3150
Install on Android
3251
------------------
3352

34-
Ready-to-use `PythonHere` APKs are available in the `Releases <https://github.com/b3b/pythonhere/releases>`_ section.
53+
Ready-to-use *PythonHere* APKs are available in the `Releases <https://github.com/b3b/pythonhere/releases>`_ section.
3554

3655
For a list of installed Python packages, see: `buildozer.spec <./buildozer.spec>`_.
3756

3857

3958
Quick Start with Docker
4059
-----------------------
4160

42-
Docker image is based on `Jupyter Docker Stacks <https://jupyter-docker-stacks.readthedocs.io/en/latest/>`_, and includes installed `PythonHere` with usage examples.
61+
Docker image is based on `Jupyter Docker Stacks <https://jupyter-docker-stacks.readthedocs.io/en/latest/>`_, and includes installed *PythonHere* with usage examples.
4362

4463
Example command to start the Docker container::
4564

@@ -56,18 +75,37 @@ Files from the directory **work** inside container, will be available in the hos
5675

5776

5877
Run with Docker Compose
59-
^^^^^^^^^^^^^^^^^^^^^^^
78+
-----------------------
6079

61-
Commands to run with Docker Compose::
80+
Commands to run with Docker Compose, in the source directory:::
6281

6382
cp docker-compose.yml.tmpl docker-compose.yml
6483
docker-compose up
6584

6685

86+
Run locally
87+
-----------
88+
89+
Commands to run locally::
90+
91+
pip install pythonhere
92+
jupyter notebook start
93+
94+
95+
Build Android app
96+
-----------------
97+
98+
To build with `Buildozer <https://github.com/kivy/buildozer>`_, run in the source directory::
99+
100+
101+
buildozer android debug
102+
103+
104+
67105
Related resources
68106
-----------------
69107

70108
* `Kivy Remote Shell <https://github.com/kivy/kivy-remote-shell>`_: Remote SSH+Python interactive shell application
71109
* `herethere <https://github.com/b3b/herethere>`_ : Library for interactive code execution, based on AsyncSSH
72110
* `AsyncSSH <https://github.com/ronf/asyncssh>`_ : Asynchronous SSH for Python
73-
* `Buildozer action <https://github.com/ArtemSBulgakov/buildozer-action>`_ : GitHub action that is used to build Android APK with `Buildozer <https://github.com/kivy/buildozer>`_
111+
* `Buildozer action <https://github.com/ArtemSBulgakov/buildozer-action>`_ : GitHub action that is used to build Android APK with Buildozer

docs/left_jupyter.png

96.6 KB
Loading

docs/right_android.png

21.7 KB
Loading

examples/commands.md

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
---
2+
jupyter:
3+
jupytext:
4+
text_representation:
5+
extension: .md
6+
format_name: markdown
7+
format_version: '1.2'
8+
jupytext_version: 1.7.1
9+
kernelspec:
10+
display_name: Python 3
11+
language: python
12+
name: python3
13+
---
14+
15+
# Jupyter magic commands
16+
17+
Commands are provided by the *pythonhere* extension
18+
19+
```python
20+
%load_ext pythonhere
21+
```
22+
23+
## connect-there
24+
**Connect to remote interpreter via SSH.**
25+
26+
Command takes single optional argument: location of connection config.<br>
27+
If argument is not provided, values are loaded from the **there.env** file.
28+
29+
Config values could be overridden by environment variables with same names.
30+
31+
```python
32+
import os
33+
os.environ["THERE_PORT"] = "8022"
34+
```
35+
36+
```python
37+
%connect-there there.env
38+
```
39+
40+
### there.env example
41+
```
42+
# PythonHere device IP address
43+
THERE_HOST=127.0.0.1
44+
45+
# Port, as set in PythonHere app Settings section
46+
THERE_PORT=8023
47+
48+
# Username, as set in PythonHere app Settings section
49+
THERE_USERNAME=admin
50+
51+
# Password, as set in PythonHere app Settings section
52+
THERE_PASSWORD=xxx
53+
```
54+
55+
56+
## %there group of commands
57+
58+
```python
59+
%there --help
60+
```
61+
62+
Default action for *%there*, if command is not specified - execute python code.
63+
64+
65+
## there
66+
**Execute python code on the remote side.**<br>
67+
68+
```python
69+
%%there
70+
import this
71+
```
72+
73+
## kv
74+
75+
```python
76+
%there kv --help
77+
```
78+
79+
If option `--clear-style` is provided,<br> all previous rules, that was loaded with *%%there kv* command,
80+
are unloaded before command execution.
81+
82+
If root widget is defined, it will replace App's current root.
83+
84+
85+
86+
```python
87+
%%there kv
88+
Image:
89+
source: "../app/data/logo/logo-128.png"
90+
canvas.before:
91+
PushMatrix
92+
Rotate:
93+
angle: 45
94+
origin: self.center
95+
canvas.after:
96+
PopMatrix
97+
```
98+
99+
## shell
100+
101+
```python
102+
%there shell --help
103+
```
104+
105+
```python
106+
%%there shell
107+
pwd
108+
```
109+
110+
```python
111+
%%there shell
112+
for i in 1 2 3
113+
do
114+
echo -n "$i"
115+
done
116+
```
117+
118+
<!-- #region hideCode=false -->
119+
Listen to Android system logs in the background and show last two lines of output:
120+
<!-- #endregion -->
121+
122+
```python
123+
%%there -bl 2 shell
124+
logcat
125+
```
126+
127+
## upload
128+
129+
```python
130+
%there upload --help
131+
```
132+
133+
*upload* root directory is application current working directory.
134+
135+
```python
136+
!touch some.ico script.py
137+
!mkdir -p dir1/dir2
138+
```
139+
140+
```python
141+
%there upload some.ico script.py dir1 ../
142+
```
143+
144+
```python
145+
%%there shell
146+
find
147+
```
148+
149+
## log
150+
151+
```python
152+
%there log --help
153+
```
154+
155+
```{note}
156+
Since the command blocks and never ends, it is useful to run with --backgroud (-b) option
157+
```
158+
159+
```python
160+
%there -bl 1 log
161+
```
162+
163+
```python
164+
%%there
165+
from kivy.logger import Logger
166+
Logger.info("Hello from the future cell")
167+
```
168+
169+
## screeenshot
170+
171+
```python
172+
%there screenshot --help
173+
```
174+
175+
* Wait for half of a second before a command execution,<br>
176+
* make a screenshot,
177+
* display a result constrained to 200px width,
178+
* and save image to a local file:
179+
180+
```python
181+
%there -d .5 screenshot -w 200 -o /tmp/screenshot_test.png
182+
```

examples/environment.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
---
2+
jupyter:
3+
jupytext:
4+
text_representation:
5+
extension: .md
6+
format_name: markdown
7+
format_version: '1.2'
8+
jupytext_version: 1.7.1
9+
kernelspec:
10+
display_name: Python 3
11+
language: python
12+
name: python3
13+
---
14+
15+
# Execution environment
16+
17+
```python
18+
%load_ext pythonhere
19+
%connect-there
20+
```
21+
22+
Commands are executed in the application main thread, thread is blocked until the end of a cell code execution.<br>
23+
On first SSH connection, BoxLayout is set as a root widget.
24+
25+
Variables in the scope of the *%there* command:
26+
* **app** - Kivy application instance
27+
* **root** - current root widget
28+
29+
```python
30+
%%there
31+
print(app)
32+
print(root)
33+
```
34+
35+
## KV rules
36+
*%there kv* rules processing is different from the normal Kivy behavior.<br>
37+
When class is registered for second time with the same name, previous declaration for that class is deleted.
38+
39+
```python
40+
%%there kv
41+
<MyButton@Button>:
42+
color: "orange"
43+
text: "Orange"
44+
45+
MyButton:
46+
font_size: 100
47+
```
48+
49+
```python
50+
%there screenshot -w 200
51+
```
52+
53+
```python
54+
%%there kv
55+
<MyButton@Button>:
56+
text: "Orange?"
57+
58+
MyButton:
59+
font_size: 100
60+
```
61+
62+
`color: "orange"` rule is removed:
63+
64+
```python
65+
%there screenshot -w 200
66+
```

pythonhere/magic_here/shortcuts.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@
2727
"-c", "--clear-style", is_flag=True, help="Unload previously applied rules"
2828
)
2929
def kv(code: str, clear_style: bool) -> str:
30-
"""Insert given rules into the Kivy Language Builder.
31-
32-
:param code: KV language rules
33-
"""
30+
"""Insert given rules into the Kivy Language Builder."""
3431
code = "# %%there ... \n" + code.replace("'''", '"""')
3532
return KV_COMMAND_TEMPLATE.format(code=code, clear_style=clear_style)
3633

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
url="https://github.com/b3b/ipython-pythonhere",
5252
# https://pypi.org/classifiers/
5353
classifiers=[
54-
"Development Status :: 2 - Pre-Alpha",
54+
"Development Status :: 3 - Alpha",
5555
"Programming Language :: Python :: 3.7",
5656
"Programming Language :: Python :: 3.8",
5757
],

0 commit comments

Comments
 (0)