Skip to content

Commit

Permalink
add slugs to profile list
Browse files Browse the repository at this point in the history
  • Loading branch information
aktech committed Jan 7, 2024
1 parent d74dbb5 commit c757b84
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 7 deletions.
1 change: 1 addition & 0 deletions environment-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ dependencies:
- streamlit
- tornado>=5.1
- traitlets
- python-slugify
- pip:
- gradio
2 changes: 1 addition & 1 deletion jhub_apps/service/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles

from .service import router
from .routes import router

### When managed by Jupyterhub, the actual endpoints
### will be served out prefixed by /services/:name.
Expand Down
File renamed without changes.
19 changes: 18 additions & 1 deletion jhub_apps/service/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from traitlets.config import LazyConfigValue

from jhub_apps.spawner.types import FrameworkConf, FRAMEWORKS_MAPPING
from slugify import slugify


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -56,6 +57,21 @@ async def get_auth_state():
return fake_spawner


def _slugify_profile_list(profile_list):
# this is replicating the following:
# https://github.com/jupyterhub/kubespawner/blob/a4b9b190f0335406c33c6de11b5d1b687842dd89/kubespawner/spawner.py#L3279
# Since we are not inside spawner yet, the profiles might not be slugified yet
if not profile_list:
# empty profile lists are just returned
return profile_list

for profile in profile_list:
# generate missing slug fields from display_name
if 'slug' not in profile:
profile['slug'] = slugify(profile['display_name'])
return profile_list


async def get_spawner_profiles(config, auth_state=None):
"""This will extract spawner profiles from the JupyterHub config
If the Spawner is KubeSpawner
Expand All @@ -68,7 +84,8 @@ async def get_spawner_profiles(config, auth_state=None):
elif callable(profile_list):
try:
logger.info("config.KubeSpawner.profile_list is a callable, calling now..")
return await profile_list(get_fake_spawner_object(auth_state))
profile_list = await profile_list(get_fake_spawner_object(auth_state))
return _slugify_profile_list(profile_list)
except Exception as e:
logger.exception(e)
return []
Expand Down
2 changes: 1 addition & 1 deletion jhub_apps/static/js/index.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ dependencies = [
"panel",
"bokeh",
"traitlets",
"python-slugify",
"PyJWT",
]
dynamic = ["version"]
Expand Down
6 changes: 3 additions & 3 deletions ui/src/data/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ export const frameworks: AppFrameworkProps[] = [
export const environments = ['env-1', 'env-2', 'env-3', 'env-4', 'env-5'];

export const profiles: AppProfileProps[] = [
{ display_name: 'Small' },
{ display_name: 'Medium' },
{ display_name: 'Large' },
{ display_name: 'Small', slug: 'small' },
{ display_name: 'Medium', slug: 'medium' },
{ display_name: 'Large', slug: 'large' },
];

export const app: AppQueryGetProps = {
Expand Down
2 changes: 1 addition & 1 deletion ui/src/pages/home/app-form/app-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ export const AppForm = ({
options={[
{ value: '', label: 'Select...' },
...profiles.map((profile: AppProfileProps) => ({
value: profile.display_name,
value: profile.slug,
label: profile.display_name,
})),
]}
Expand Down
1 change: 1 addition & 0 deletions ui/src/types/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,5 @@ export interface AppFrameworkProps {

export interface AppProfileProps {
display_name: string;
slug: string;
}

0 comments on commit c757b84

Please sign in to comment.