Skip to content

Commit cc7e545

Browse files
add docs for run in README (#108)
1 parent 7b08e2d commit cc7e545

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

README.md

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ $ pip install pyscript
2828

2929
## Usage
3030

31-
### Embed a Python script into a PyScript HTML file
31+
### wrap
32+
33+
#### Embed a Python script into a PyScript HTML file
3234

3335
```shell
3436
$ pyscript wrap <filename.py>
@@ -41,25 +43,49 @@ This can be overwritten with the `-o` or `--output` option:
4143
$ pyscript wrap <filename.py> -o <another_filename.html>
4244
```
4345

44-
### Open the script inside the browser using the `--show` option
46+
#### Open the script inside the browser using the `--show` option
4547

4648
```shell
4749
$ pyscript wrap <filename.py> --show
4850
```
4951

50-
### Set a title for the browser tab
52+
#### Set a title for the browser tab
5153

5254
You can set the title of the browser tab with the `--title` option:
5355

5456
```shell
5557
$ pyscript wrap <filename.py> --title "My cool app!"
5658
```
5759

58-
### Very simple command examples with `--command` option
60+
#### Very simple command examples with `--command` option
5961

6062
The `-c` or `--command` option can be used to demo very simple cases.
6163
In this case, if the `--show` option is used and no `--output` file is used, a temporary file will be generated.
6264

6365
```shell
6466
$ pyscript wrap -c 'print("Hello World!")' --show
6567
```
68+
69+
### run
70+
71+
#### Spin up a local server to run on the path and specified port
72+
73+
```shell
74+
$ pyscript run <path_of_folder>
75+
```
76+
77+
This will serve the folder `path_of_folder` at `localhost:8000` by default
78+
and will open the URL in a browser window. Default is current directory if
79+
`path_of_folder` is not supplied.
80+
81+
To use a different port, use `--port` option.
82+
83+
```shell
84+
$ pyscript run <path_of_folder> --port 9000
85+
```
86+
87+
To avoid opening a browser window, use `--silent` option.
88+
89+
```shell
90+
$ pyscript run <path_of_folder> --silent
91+
```

src/pyscript/plugins/run.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ def split_path_and_filename(path: Path) -> tuple[Path, str]:
4444
Args:
4545
path (str): The path to the pyscript project or file.
4646
47-
4847
Returns:
4948
tuple(str, str): The base path of the project and the filename
5049
"""
@@ -94,7 +93,7 @@ def start_server(path: Path, show: bool, port: int):
9493
except KeyboardInterrupt:
9594
console.print("\nStopping server... Bye bye!")
9695

97-
# Clean after ourselves....
96+
# Clean up resources....
9897
httpd.shutdown()
9998
httpd.socket.close()
10099
raise typer.Exit(1)
@@ -122,7 +121,7 @@ def run(
122121
if e.errno == 48:
123122
console.print(
124123
f"Error: Port {port} is already in use! :( Please, stop the process using that port"
125-
f"or ry another port using the --port option.",
124+
f"or try another port using the --port option.",
126125
style="red",
127126
)
128127
else:

0 commit comments

Comments
 (0)