47
47
_secrets_api = None
48
48
_project_api = None
49
49
50
+
50
51
def hw_formatwarning (message , category , filename , lineno , line = None ):
51
52
return "{}: {}\n " .format (category .__name__ , message )
52
53
@@ -144,7 +145,7 @@ def login(
144
145
elif host is None : # Always do a fallback to Serverless Hopsworks if not defined
145
146
host = constants .HOSTS .APP_HOST
146
147
147
- is_app = ( host == constants .HOSTS .APP_HOST )
148
+ is_app = host == constants .HOSTS .APP_HOST
148
149
149
150
# If port same as default, get HOPSWORKS_HOST environment variable
150
151
if port == 443 and "HOPSWORKS_PORT" in os .environ :
@@ -211,7 +212,9 @@ def login(
211
212
raise e
212
213
213
214
if _connected_project is None :
214
- print ("Could not find any project, use hopsworks.create_project('my_project') to create one" )
215
+ print (
216
+ "Could not find any project, use hopsworks.create_project('my_project') to create one"
217
+ )
215
218
else :
216
219
print ("\n Logged in to project, explore it here " + _connected_project .get_url ())
217
220
@@ -273,7 +276,9 @@ def _prompt_project(valid_connection, project, is_app):
273
276
for index in range (len (saas_projects )):
274
277
print ("\t (" + str (index + 1 ) + ") " + saas_projects [index ].name )
275
278
while True :
276
- project_index = input ("\n Enter number corresponding to the project to use: " )
279
+ project_index = input (
280
+ "\n Enter number corresponding to the project to use: "
281
+ )
277
282
# Handle invalid input type
278
283
try :
279
284
project_index = int (project_index )
@@ -300,8 +305,7 @@ def _prompt_project(valid_connection, project, is_app):
300
305
301
306
302
307
def logout ():
303
- """Cleans up and closes the connection for the hopsworks, hsfs and hsml libraries.
304
- """
308
+ """Cleans up and closes the connection for the hopsworks, hsfs and hsml libraries."""
305
309
global _hw_connection
306
310
global _project_api
307
311
global _secrets_api
@@ -314,10 +318,12 @@ def logout():
314
318
_secrets_api = None
315
319
_hw_connection = Connection .connection
316
320
321
+
317
322
def _is_connection_active ():
318
323
global _hw_connection
319
324
return isinstance (_hw_connection , Connection )
320
325
326
+
321
327
def get_current_project () -> project .Project :
322
328
"""Get a reference to the current logged in project.
323
329
@@ -341,15 +347,15 @@ def get_current_project() -> project.Project:
341
347
raise ProjectException ("No project is set for this session" )
342
348
return _connected_project
343
349
350
+
344
351
def _initialize_module_apis ():
345
352
global _project_api
346
353
global _secrets_api
347
354
_project_api = project_api .ProjectApi ()
348
355
_secrets_api = secret_api .SecretsApi ()
349
356
350
- def create_project (
351
- name : str , description : str = None , feature_store_topic : str = None
352
- ):
357
+
358
+ def create_project (name : str , description : str = None , feature_store_topic : str = None ):
353
359
"""Create a new project.
354
360
355
361
Example for creating a new project
@@ -377,13 +383,24 @@ def create_project(
377
383
if not _is_connection_active ():
378
384
raise NoHopsworksConnectionError ()
379
385
380
- new_project = _hw_connection ._project_api ._create_project (name , description , feature_store_topic )
386
+ new_project = _hw_connection ._project_api ._create_project (
387
+ name , description , feature_store_topic
388
+ )
381
389
if _connected_project is None :
382
390
_connected_project = new_project
383
- print ("Setting {} as the current project, a reference can be retrieved by calling hopsworks.get_current_project()" .format (_connected_project .name ))
391
+ print (
392
+ "Setting {} as the current project, a reference can be retrieved by calling hopsworks.get_current_project()" .format (
393
+ _connected_project .name
394
+ )
395
+ )
384
396
return _connected_project
385
397
else :
386
- print ("You are already using the project {}, to access the new project use hopsworks.login(..., project='{}')" .format (_connected_project .name , new_project .name ))
398
+ print (
399
+ "You are already using the project {}, to access the new project use hopsworks.login(..., project='{}')" .format (
400
+ _connected_project .name , new_project .name
401
+ )
402
+ )
403
+
387
404
388
405
def get_secrets_api ():
389
406
"""Get the secrets api.
@@ -394,4 +411,4 @@ def get_secrets_api():
394
411
global _secrets_api
395
412
if not _is_connection_active ():
396
413
raise NoHopsworksConnectionError ()
397
- return _secrets_api
414
+ return _secrets_api
0 commit comments