Skip to content

Commit

Permalink
Merge pull request #645 from dolfinus/maybe_future
Browse files Browse the repository at this point in the history
Use jupyterhub.utils.maybe_future instead of tornado.get.maybe_future
  • Loading branch information
consideRatio committed Oct 13, 2022
2 parents fa19acd + e1dab55 commit 71a9538
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ jobs:
# kubernetes_asyncio: https://github.com/tomplus/kubernetes_asyncio/tags
#
include:
# Tests with oldest supported Python, k8s, and k8s client
# Tests with oldest supported Python, jupyterhub, k8s, and k8s client
- python: "3.7"
k3s: v1.20
test_dependencies: kubernetes_asyncio==19.*
test_dependencies: >-
jupyterhub==1.3.0
kubernetes_asyncio==19.15.1
# Test with modern python and k8s versions
- python: "3.9"
Expand Down
23 changes: 11 additions & 12 deletions kubespawner/spawner.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
from jinja2 import BaseLoader, Environment
from jupyterhub.spawner import Spawner
from jupyterhub.traitlets import Callable, Command
from jupyterhub.utils import exponential_backoff
from jupyterhub.utils import exponential_backoff, maybe_future
from kubernetes_asyncio import client
from kubernetes_asyncio.client.rest import ApiException
from slugify import slugify
from tornado import gen
from traitlets import (
Bool,
Dict,
Expand Down Expand Up @@ -1976,32 +1975,32 @@ async def get_pod_manifest(self):
Make a pod manifest that will spawn current user's notebook pod.
"""
if callable(self.uid):
uid = await gen.maybe_future(self.uid(self))
uid = await maybe_future(self.uid(self))
else:
uid = self.uid

if callable(self.gid):
gid = await gen.maybe_future(self.gid(self))
gid = await maybe_future(self.gid(self))
else:
gid = self.gid

if callable(self.fs_gid):
fs_gid = await gen.maybe_future(self.fs_gid(self))
fs_gid = await maybe_future(self.fs_gid(self))
else:
fs_gid = self.fs_gid

if callable(self.supplemental_gids):
supplemental_gids = await gen.maybe_future(self.supplemental_gids(self))
supplemental_gids = await maybe_future(self.supplemental_gids(self))
else:
supplemental_gids = self.supplemental_gids

if callable(self.container_security_context):
csc = await gen.maybe_future(self.container_security_context(self))
csc = await maybe_future(self.container_security_context(self))
else:
csc = self.container_security_context

if callable(self.pod_security_context):
psc = await gen.maybe_future(self.pod_security_context(self))
psc = await maybe_future(self.pod_security_context(self))
else:
psc = self.pod_security_context

Expand Down Expand Up @@ -2657,7 +2656,7 @@ async def _start(self):
# try again. We try 4 times, and if it still fails we give up.
pod = await self.get_pod_manifest()
if self.modify_pod_hook:
pod = await gen.maybe_future(self.modify_pod_hook(self, pod))
pod = await maybe_future(self.modify_pod_hook(self, pod))

ref_key = f"{self.namespace}/{self.pod_name}"
# If there's a timeout, just let it propagate
Expand Down Expand Up @@ -2886,7 +2885,7 @@ def _render_options_form(self, profile_list):
return profile_form_template.render(profile_list=self._profile_list)

async def _render_options_form_dynamically(self, current_spawner):
profile_list = await gen.maybe_future(self.profile_list(current_spawner))
profile_list = await maybe_future(self.profile_list(current_spawner))
profile_list = self._init_profile_list(profile_list)
return self._render_options_form(profile_list)

Expand Down Expand Up @@ -3025,7 +3024,7 @@ async def _load_profile(self, slug, selected_profile_user_options):
]
for k, v in chosen_option_overrides.items():
if callable(v):
v = await gen.maybe_future(v(self))
v = await maybe_future(v(self))
self.log.debug(
f'.. overriding traitlet {k}={v} for option {option_name}={chosen_option} from callabale'
)
Expand Down Expand Up @@ -3060,7 +3059,7 @@ async def load_user_options(self):

if self._profile_list is None:
if callable(self.profile_list):
profile_list = await gen.maybe_future(self.profile_list(self))
profile_list = await maybe_future(self.profile_list(self))
else:
profile_list = self.profile_list

Expand Down
6 changes: 4 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
setup(
name='jupyterhub-kubespawner',
version='4.2.1.dev',
# NOTE: If lower bounds are updated, also update our test for the lower
# bounds in .github/workflows/test.yaml.
install_requires=[
'escapism',
'python-slugify',
'jupyterhub>=0.9',
'jupyterhub>=1.3.0',
'jinja2',
'kubernetes_asyncio>=19.15.1',
'urllib3',
Expand All @@ -27,7 +29,7 @@
'kubernetes>=11',
'pytest>=5.4',
'pytest-cov',
'pytest-asyncio>=0.11.0',
'pytest-asyncio>=0.17',
]
},
description='JupyterHub Spawner for Kubernetes',
Expand Down

0 comments on commit 71a9538

Please sign in to comment.