Skip to content

Commit

Permalink
apply black
Browse files Browse the repository at this point in the history
  • Loading branch information
aktech committed Aug 22, 2023
1 parent fb2a341 commit 81580d5
Show file tree
Hide file tree
Showing 16 changed files with 176 additions and 133 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: build

on:
push:
jobs:
build:
runs-on: ubuntu-latest
defaults:
run:
shell: bash -el {0}
strategy:
fail-fast: false
matrix:
python-version: ["3.11"]
steps:
- uses: actions/checkout@v3

- name: Setup Miniconda
uses: conda-incubator/[email protected]
with:
python-version: ${{ matrix.python-version }}
environment-file: environment-dev.yml

- name: Install Test dependencies
run: |
pip install flake8 pytest
- name: Lint with black
uses: psf/black@stable

31 changes: 0 additions & 31 deletions .github/workflows/python-package.yml

This file was deleted.

1 change: 1 addition & 0 deletions environment-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ dependencies:
- plotlydash-tornado-cmd
- bokeh-root-cmd
- jhsingle-native-proxy
- black
2 changes: 1 addition & 1 deletion jhub_apps/__about__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.1'
__version__ = "0.1"
10 changes: 6 additions & 4 deletions jhub_apps/examples/bokeh_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ def modify_doc(doc):
doc: A bokeh document to which elements can be added.
"""
x_values = list(range(10))
y_values = [x ** 2 for x in x_values]
y_values = [x**2 for x in x_values]
data_source = ColumnDataSource(data=dict(x=x_values, y=y_values))
plot = figure(title="f(x) = x^2",
tools="crosshair,pan,reset,save,wheel_zoom", )
plot.line('x', 'y', source=data_source, line_width=3, line_alpha=0.6)
plot = figure(
title="f(x) = x^2",
tools="crosshair,pan,reset,save,wheel_zoom",
)
plot.line("x", "y", source=data_source, line_width=3, line_alpha=0.6)
doc.add_root(plot)
doc.title = "Hello World"

Expand Down
1 change: 1 addition & 0 deletions jhub_apps/examples/panel_basic.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""We can use this to test the bokeh_root_cmd"""
import panel as pn

pn.extension(sizing_mode="stretch_width")


Expand Down
25 changes: 13 additions & 12 deletions jhub_apps/examples/plotlydash_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,26 @@
import plotly.express as px
import pandas as pd

df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/gapminder_unfiltered.csv')
df = pd.read_csv(
"https://raw.githubusercontent.com/plotly/datasets/master/gapminder_unfiltered.csv"
)

app = Dash(__name__)

app.layout = html.Div([
html.H1(children='Plotly Dash App', style={'textAlign': 'center'}),
dcc.Dropdown(df.country.unique(), 'Canada', id='dropdown-selection'),
dcc.Graph(id='graph-content')
])
app.layout = html.Div(
[
html.H1(children="Plotly Dash App", style={"textAlign": "center"}),
dcc.Dropdown(df.country.unique(), "Canada", id="dropdown-selection"),
dcc.Graph(id="graph-content"),
]
)


@callback(
Output('graph-content', 'figure'),
Input('dropdown-selection', 'value')
)
@callback(Output("graph-content", "figure"), Input("dropdown-selection", "value"))
def update_graph(value):
dff = df[df.country == value]
return px.line(dff, x='year', y='pop')
return px.line(dff, x="year", y="pop")


if __name__ == '__main__':
if __name__ == "__main__":
app.run(debug=True)
12 changes: 7 additions & 5 deletions jhub_apps/examples/streamlit_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
"""


with st.echo(code_location='below'):
with st.echo(code_location="below"):
total_points = st.slider("Number of points in spiral", 1, 5000, 2000)
num_turns = st.slider("Number of turns in spiral", 1, 100, 9)

Point = namedtuple('Point', 'x y')
Point = namedtuple("Point", "x y")
data = []

points_per_turn = total_points / num_turns
Expand All @@ -33,6 +33,8 @@
y = radius * math.sin(angle)
data.append(Point(x, y))

st.altair_chart(alt.Chart(pd.DataFrame(data), height=500, width=500)
.mark_circle(color='#0068c9', opacity=0.5)
.encode(x='x:Q', y='y:Q'))
st.altair_chart(
alt.Chart(pd.DataFrame(data), height=500, width=500)
.mark_circle(color="#0068c9", opacity=0.5)
.encode(x="x:Q", y="y:Q")
)
11 changes: 4 additions & 7 deletions jhub_apps/launcher/hub_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import requests

API_URL = 'http://127.0.0.1:8000/hub/api'
API_URL = "http://127.0.0.1:8000/hub/api"

JHUB_APP_TOKEN = os.environ.get("JHUB_APP_LAUNCHER_TOKEN", "super-secret")

Expand All @@ -12,21 +12,18 @@ def __init__(self, token=None):
self.token = token or JHUB_APP_TOKEN

def _headers(self):
return {'Authorization': f'token {self.token}'}
return {"Authorization": f"token {self.token}"}

def get_users(self):
r = requests.get(API_URL + '/users', headers=self._headers())
r = requests.get(API_URL + "/users", headers=self._headers())
r.raise_for_status()
users = r.json()
return users

def create_server(self, username, servername="foobarlar", params=None):
url = f"/users/{username}/servers/{servername}"
params = params or {}
data = {
"jhub_app": True,
**params
}
data = {"jhub_app": True, **params}
r = requests.post(API_URL + url, headers=self._headers(), json=data)
r.raise_for_status()
return r.status_code
4 changes: 2 additions & 2 deletions jhub_apps/launcher/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

def app():
pn.serve(
{'/app': create_app},
{"/app": create_app},
port=5000,
address="localhost",
allow_websocket_origin=[
Expand All @@ -16,5 +16,5 @@ def app():
)


if __name__ == '__main__':
if __name__ == "__main__":
app()
34 changes: 20 additions & 14 deletions jhub_apps/launcher/panel_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
from jhub_apps.launcher.hub_client import HubClient

FRAMEWORKS = {
'Panel': 'panel',
"Panel": "panel",
"Bokeh": "bokeh",
'Streamlit': 'streamlit',
'Voila': 'voila',
"Streamlit": "streamlit",
"Voila": "voila",
"Plotly": "plotlydash",
"Gradio": "gradio",
}
Expand All @@ -27,12 +27,14 @@ class InputFormWidget:

def create_input_form():
input_form_widget = InputFormWidget(
name_input=pn.widgets.TextInput(name='Name'),
filepath_input=pn.widgets.TextInput(name='Filepath'),
description_input=pn.widgets.TextAreaInput(name='Description'),
spinner=pn.indicators.LoadingSpinner(size=30, value=True, color="secondary", bgcolor='dark', visible=True),
button_widget=pn.widgets.Button(name='Create Dashboard', button_type='primary'),
framework=pn.widgets.Select(name='Framework', options=FRAMEWORKS)
name_input=pn.widgets.TextInput(name="Name"),
filepath_input=pn.widgets.TextInput(name="Filepath"),
description_input=pn.widgets.TextAreaInput(name="Description"),
spinner=pn.indicators.LoadingSpinner(
size=30, value=True, color="secondary", bgcolor="dark", visible=True
),
button_widget=pn.widgets.Button(name="Create Dashboard", button_type="primary"),
framework=pn.widgets.Select(name="Framework", options=FRAMEWORKS),
)
input_form = pn.Column(
input_form_widget.name_input,
Expand All @@ -52,7 +54,9 @@ def create_dashboard(event, input_form_widget, input_form):
filepath = input_form_widget.filepath_input.value
description = input_form_widget.description_input.value
framework = input_form_widget.framework.value
print(f"Name: {name}, Filepath: {filepath}, Description: {description}, framework: {framework}")
print(
f"Name: {name}, Filepath: {filepath}, Description: {description}, framework: {framework}"
)
hclient = HubClient()
params = {
"name": input_form_widget.name_input.value,
Expand All @@ -65,17 +69,19 @@ def create_dashboard(event, input_form_widget, input_form):
input_form.pop(-1)
# TODO: Fix Url hardcoding
dashboard_link = f"http://localhost:8000/user/aktech/{name}"
text_with_link = pn.pane.Markdown(f"""
text_with_link = pn.pane.Markdown(
f"""
## 🚀 Dashboard created: [{dashboard_link}]({dashboard_link}).
""")
"""
)
input_form.append(text_with_link)
print(event)


def create_app():
print("*"*100)
print("*" * 100)
print("CREATING APP")
print("*"*100)
print("*" * 100)
input_form_widget, input_form = create_input_form()

def button_callback(event):
Expand Down
1 change: 1 addition & 0 deletions jhub_apps/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
def app():
print("Hello world")
import time

time.sleep(500)
return 1
8 changes: 5 additions & 3 deletions jhub_apps/service/app/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,18 @@ async def get_token(code: str = Form(...)):
@router.get("/")
async def index(request: Request):
"Non-authenticated function that returns {'Hello': 'World'}"
script = server_document('http://127.0.0.1:5000/app')
return templates.TemplateResponse("launcher_base.html", {"request": request, "script": script})
script = server_document("http://127.0.0.1:5000/app")
return templates.TemplateResponse(
"launcher_base.html", {"request": request, "script": script}
)


# response_model and responses dict translate to OpenAPI (Swagger) hints
# compare and contrast what the /me endpoint looks like in Swagger vs /debug
@router.get(
"/me",
response_model=User,
responses={401: {'model': AuthorizationError}, 400: {'model': HubApiError}},
responses={401: {"model": AuthorizationError}, 400: {"model": HubApiError}},
)
async def me(user: User = Depends(get_current_user)):
"Authenticated function that returns the User model"
Expand Down
Loading

0 comments on commit 81580d5

Please sign in to comment.