1212
1313
1414# conda-store default page size
15- PAGE_SIZE_LIMIT = 100
15+ DEFAULT_PAGE_SIZE_LIMIT = 100
1616
1717@gen .coroutine
1818def get_username_hook (spawner ):
@@ -26,16 +26,24 @@ def get_username_hook(spawner):
2626 )
2727
2828
29+ # TODO: this should get unit tests. Currently, since this is not a python module,
30+ # adding tests in a traditional sense is not possible. See https://github.com/soapy1/nebari/tree/try-unit-test-spawner
31+ # for a demo on one approach to adding test.
2932def get_conda_store_environments (user_info : dict ):
3033 import urllib3
3134 import yarl
3235 import math
36+ import os
37+
38+ # Check for the environment variable `CONDA_STORE_API_PAGE_SIZE_LIMIT`. Fall
39+ # back to using the default page size limit if not set.
40+ page_size = os .environ .get ("CONDA_STORE_API_PAGE_SIZE_LIMIT" , DEFAULT_PAGE_SIZE_LIMIT )
3341
3442 external_url = z2jh .get_config ("custom.conda-store-service-name" )
3543 token = z2jh .get_config ("custom.conda-store-jhub-apps-token" )
3644 endpoint = "conda-store/api/v1/environment"
3745
38- url = yarl .URL (f"http://{ external_url } /{ endpoint } /?size={ PAGE_SIZE_LIMIT } " )
46+ url = yarl .URL (f"http://{ external_url } /{ endpoint } /?size={ page_size } " )
3947 http = urllib3 .PoolManager ()
4048 response = http .request (
4149 "GET" , str (url ), headers = {"Authorization" : f"Bearer { token } " }
@@ -48,11 +56,11 @@ def get_conda_store_environments(user_info: dict):
4856
4957 # If there are more records than the specified size limit, then
5058 # will need to page through to get all the available envs
51- if total_records > PAGE_SIZE_LIMIT :
59+ if total_records > page_size :
5260 # Already pulled the first page of results, start looping through
5361 # the envs starting on the 2nd page
54- for page in range (2 , math .ceil (total_records / PAGE_SIZE_LIMIT )+ 1 ):
55- url = yarl .URL (f"http://{ external_url } /{ endpoint } /?size={ PAGE_SIZE_LIMIT } &page={ page } " )
62+ for page in range (2 , math .ceil (total_records / page_size )+ 1 ):
63+ url = yarl .URL (f"http://{ external_url } /{ endpoint } /?size={ page_size } &page={ page } " )
5664 response = http .request (
5765 "GET" , str (url ), headers = {"Authorization" : f"Bearer { token } " }
5866 )
0 commit comments