-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__main__.py
More file actions
37 lines (25 loc) · 874 Bytes
/
__main__.py
File metadata and controls
37 lines (25 loc) · 874 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from functools import partial
from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer
from pathlib import Path
import typer
from typing_extensions import Annotated
app = typer.Typer()
@app.command()
def render():
print("Render dataframe")
@app.command()
def serve(
host: str = "0.0.0.0",
port: int = 8080,
directory: Annotated[str, Path, typer.Argument()] = Path.cwd(),
):
if not directory:
directory = Path.cwd()
if not isinstance(directory, Path):
directory = Path(directory)
assert directory.exists() and directory.is_dir()
directory = str(directory.resolve().absolute())
handler = partial(SimpleHTTPRequestHandler, directory=directory)
server = ThreadingHTTPServer((host, port), handler)
print(f"Serving files at http://{host}:{port} ... (ctrl+c to stop)")
server.serve_forever()