Skip to content

Commit 22df404

Browse files
committed
feat: Add CLI command pandas serve for serving local files
1 parent 9ecc0be commit 22df404

File tree

4 files changed

+93
-0
lines changed

4 files changed

+93
-0
lines changed

pandas_render/cli/__init__.py

Whitespace-only changes.

pandas_render/cli/__main__.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from functools import partial
2+
from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer
3+
from pathlib import Path
4+
5+
import typer
6+
from typing_extensions import Annotated
7+
8+
app = typer.Typer()
9+
10+
11+
@app.command()
12+
def render():
13+
print("Render dataframe")
14+
15+
16+
@app.command()
17+
def serve(
18+
host: str = "0.0.0.0",
19+
port: int = 8080,
20+
directory: Annotated[str, Path, typer.Argument()] = Path.cwd(),
21+
):
22+
if not directory:
23+
directory = Path.cwd()
24+
25+
if not isinstance(directory, Path):
26+
directory = Path(directory)
27+
28+
assert directory.exists() and directory.is_dir()
29+
30+
directory = str(directory.resolve().absolute())
31+
32+
handler = partial(SimpleHTTPRequestHandler, directory=directory)
33+
server = ThreadingHTTPServer((host, port), handler)
34+
35+
print(f"Serving files at http://{host}:{port} ... (ctrl+c to stop)")
36+
37+
server.serve_forever()

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ requires-python = ">=3.9"
1010
dependencies = [
1111
"ipython>=7.11.1",
1212
"jinja2>=3.0.0",
13+
"typer>=0.15.2",
1314
]
1415
license = "BSD-3-Clause"
1516
classifiers = [
@@ -42,6 +43,9 @@ dev = [
4243
"pytest-xdist>=3.6.1",
4344
]
4445

46+
[project.scripts]
47+
pandas = "pandas_render.cli.__main__:app"
48+
4549
[tool.coverage.run]
4650
source = ["pandas_render"]
4751

uv.lock

Lines changed: 52 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)