-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
41a3ed5
commit d6ec2f4
Showing
14 changed files
with
183 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
0.0.1 (February 15, 2022) | ||
========================= | ||
|
||
Initial release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Copyright 2021 David Brochart and the FPS contributors. | ||
|
||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: | ||
|
||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. | ||
|
||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. | ||
|
||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# FPS Dashboard | ||
|
||
An [FPS](https://github.com/jupyter-server/fps) plugin to show a dashboard using Rich/Textual. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from fps_dashboard._version import __version__ # noqa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
version_info = (0, 0, 1) | ||
__version__ = ".".join(map(str, version_info)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from .dashboard import Dashboard | ||
|
||
|
||
def app(): | ||
Dashboard.run(title="API Summary") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from fps.config import PluginModel | ||
from fps.hooks import register_config, register_plugin_name | ||
|
||
|
||
class DashboardConfig(PluginModel): | ||
foo: bool = False | ||
|
||
|
||
c = register_config(DashboardConfig) | ||
n = register_plugin_name("dashboard") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import asyncio | ||
import atexit | ||
import json | ||
import sys | ||
|
||
from rich.table import Table | ||
from textual import events | ||
from textual.app import App | ||
from textual.widgets import ScrollView | ||
|
||
FPS = None | ||
|
||
|
||
def stop_fps(): | ||
if FPS is not None: | ||
FPS.terminate() | ||
|
||
|
||
atexit.register(stop_fps) | ||
|
||
|
||
async def show(queue: asyncio.Queue): | ||
|
||
console = Console() | ||
with console.capture() as capture: | ||
console.print() | ||
console.print(table) | ||
|
||
str_output = capture.get() | ||
print(str_output) | ||
|
||
|
||
class Dashboard(App): | ||
"""An example of a very simple Textual App""" | ||
|
||
async def on_load(self, event: events.Load) -> None: | ||
await self.bind("q", "quit", "Quit") | ||
|
||
async def on_mount(self, event: events.Mount) -> None: | ||
|
||
self.body = body = ScrollView(auto_width=True) | ||
|
||
await self.view.dock(body) | ||
|
||
async def add_content(): | ||
global FPS | ||
cmd = ["fps-uvicorn", "--fps.show_endpoints"] + sys.argv[1:] | ||
FPS = await asyncio.create_subprocess_exec( | ||
*cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE | ||
) | ||
queue = asyncio.Queue() | ||
asyncio.create_task(get_log(queue)) | ||
endpoint_marker = "ENDPOINT:" | ||
endpoints = [] | ||
get_endpoint = False | ||
while True: | ||
line = await queue.get() | ||
if endpoint_marker in line: | ||
get_endpoint = True | ||
elif get_endpoint: | ||
break | ||
if get_endpoint: | ||
i = line.find(endpoint_marker) + len(endpoint_marker) | ||
line = line[i:].strip() | ||
if not line: | ||
break | ||
endpoint = json.loads(line) | ||
endpoints.append(endpoint) | ||
|
||
table = Table(title="API Summary") | ||
table.add_column("Path", justify="left", style="cyan", no_wrap=True) | ||
table.add_column("Methods", justify="right", style="green") | ||
table.add_column("Plugin", style="magenta") | ||
|
||
for endpoint in endpoints: | ||
path = endpoint["path"] | ||
methods = ", ".join(endpoint["methods"]) | ||
plugin = ", ".join(endpoint["plugin"]) | ||
if "WEBSOCKET" in methods: | ||
path = f"[cyan on red]{path}[/]" | ||
table.add_row(path, methods, plugin) | ||
|
||
await body.update(table) | ||
|
||
await self.call_later(add_content) | ||
|
||
|
||
async def get_log(queue): | ||
while True: | ||
line = await FPS.stderr.readline() | ||
if line: | ||
await queue.put(line.decode().strip()) | ||
else: | ||
break |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
[metadata] | ||
name = fps_dashboard | ||
version = attr: fps_dashboard._version.__version__ | ||
description = A dashboard plugin for FPS | ||
long_description = file: README.md | ||
long_description_content_type = text/markdown | ||
license_file = LICENSE | ||
author = David Brochart | ||
author_email = [email protected] | ||
url = https://github.com/jupyter-server/fps | ||
platforms = Windows, Linux, Mac OS X | ||
keywords = server, fastapi, pluggy, plugins, fps, rich | ||
|
||
[bdist_wheel] | ||
universal = 1 | ||
|
||
[options] | ||
include_package_data = True | ||
packages = find: | ||
python_requires = >=3.7 | ||
|
||
install_requires = | ||
fps-uvicorn | ||
rich | ||
textual | ||
|
||
[options.entry_points] | ||
fps_config = | ||
fps_dashboard_config = fps_dashboard.config | ||
|
||
console_scripts = | ||
fps-dashboard = fps_dashboard.cli:app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import setuptools | ||
|
||
setuptools.setup() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,6 @@ install_requires = | |
fastapi | ||
pluggy>=1.0,<2.0 | ||
click | ||
rich | ||
|
||
[options.extras_require] | ||
uvicorn = | ||
|