Skip to content

Commit

Permalink
Add README + minor code changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Harizo Rajaona committed Nov 5, 2021
1 parent 7e70af6 commit 1b7cc3e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
7 changes: 7 additions & 0 deletions admin/map_code_envs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# List the mappings between code recipes and code envs

## Questions
* I want to retrieve the associated code env for each code recipe (Python, R) in a given project.

## Answers
This is possible thanks to the [recipe endpoints of the DSS API](https://doc.dataiku.com/dss/latest/python-api/recipes.html).
18 changes: 5 additions & 13 deletions admin/map_code_envs/code.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import dataiku

def get_instance_default_code_env(client=None):
"""Return the global default code envs (instance-level).
"""

defaults = {}
general_settings = client.get_general_settings()
for rcp_type in [("python", "defaultPythonEnv"), ("r", "defaultREnv")]:
Expand All @@ -14,26 +17,15 @@ def get_instance_default_code_env(client=None):

def get_code_env_mapping(client=None, project_key=None):
"""Return a dict mapping code-based items with their code envs.
Example of output:
{
"python": {
"recipes": [{"name": "xxx", "code_env": "yyy"}, ...],
"notebooks": [{"name": "xxx", code_env": "yy"}]
}
"r": {
...
}
}
"""

rcp_types = ["python", "r"]
mapping = {"python": [], "r": []}

prj = client.get_project(project_key)

# Retrieve the project's default code env
settings = prj.get_settings()
env_default = {}

settings = prj.get_settings()
prj_default_modes = settings.get_raw()["settings"]["codeEnvs"]
all_recipes = prj.list_recipes()
for rcp_type in rcp_types:
Expand Down

0 comments on commit 1b7cc3e

Please sign in to comment.