@@ -444,7 +444,8 @@ def delete(self):
444444 raise Exception ('Env deletion returned no data' )
445445 if resp .get ('messages' , {}).get ('error' , False ):
446446 raise Exception ('Env deletion failed : %s' % (json .dumps (resp .get ('messages' , {}).get ('messages' , {}))))
447-
447+ return resp
448+
448449
449450 ########################################################
450451 # Code env description
@@ -461,42 +462,69 @@ def get_definition(self):
461462 """
462463 return self .client ._perform_json (
463464 "GET" , "/admin/code-envs/%s/%s" % (self .env_lang , self .env_name ))
465+
466+ def set_definition (self , env ):
467+ """
468+ Set the code env's definition. The definition should come from a call to the get_definition()
469+ method.
470+
471+ Fields that can be updated in design node:
472+
473+ * env.permissions, env.usableByAll, env.desc.owner
474+ * env.specCondaEnvironment, env.specPackageList, env.externalCondaEnvName, env.desc.installCorePackages,
475+ env.desc.installJupyterSupport, env.desc.yarnPythonBin
476+
477+ Fields that can be updated in automation node (where {version} is the updated version):
478+
479+ * env.permissions, env.usableByAll, env.owner
480+ * env.{version}.specCondaEnvironment, env.{version}.specPackageList, env.{version}.externalCondaEnvName,
481+ env.{version}.desc.installCorePackages, env.{version}.desc.installJupyterSupport, env.{version}.desc.yarnPythonBin
482+
483+
484+
485+ Note: this call requires an API key with admin rights
486+
487+ :param data: a code env definition
488+
489+ Returns:
490+ the updated code env definition, as a JSON object
491+ """
492+ return self .client ._perform_json (
493+ "PUT" , "/admin/code-envs/%s/%s" % (self .env_lang , self .env_name ), body = env )
494+
464495
465496 ########################################################
466- # Code env modification
497+ # Code env actions
467498 ########################################################
468- def update (self , external_conda_name = None , conda_spec = None , spec = None ):
499+
500+ def set_jupyter_support (self , active ):
469501 """
470- Update the code env definition and apply the changes
502+ Update the code env jupyter support
471503
472504 Note: this call requires an API key with admin rights
473505
474- :param external_conda_name: name of an external conda env
475- :param conda_spec: spec of the conda env
476- :param spec: list of pip or R packages
506+ :param active: True to activate jupyter support, False to deactivate
477507 """
478- modifications = {'externalCondaEnvName' :external_conda_name ,'condaSpec' :conda_spec ,'spec' :spec }
479508 resp = self .client ._perform_json (
480- "PUT " , "/admin/code-envs/%s/%s" % (self .env_lang , self .env_name ),
481- body = modifications )
509+ "POST " , "/admin/code-envs/%s/%s/jupyter " % (self .env_lang , self .env_name ),
510+ params = { 'active' : active } )
482511 if resp is None :
483512 raise Exception ('Env update returned no data' )
484513 if resp .get ('messages' , {}).get ('error' , False ):
485514 raise Exception ('Env update failed : %s' % (json .dumps (resp .get ('messages' , {}).get ('messages' , {}))))
515+ return resp
486516
487- def set_jupyter_support (self , active ):
517+ def update_packages (self ):
488518 """
489- Update the code env jupyter support
519+ Update the code env packages so that it matches its spec
490520
491521 Note: this call requires an API key with admin rights
492-
493- :param active: True to activate jupyter support, False to deactivate
494522 """
495523 resp = self .client ._perform_json (
496- "POST" , "/admin/code-envs/%s/%s/jupyter" % (self .env_lang , self .env_name ),
497- params = {'active' :active })
524+ "POST" , "/admin/code-envs/%s/%s/packages" % (self .env_lang , self .env_name ))
498525 if resp is None :
499526 raise Exception ('Env update returned no data' )
500527 if resp .get ('messages' , {}).get ('error' , False ):
501528 raise Exception ('Env update failed : %s' % (json .dumps (resp .get ('messages' , {}).get ('messages' , {}))))
529+ return resp
502530
0 commit comments