MCPcopy Create free account
hub / github.com/mlco2/codecarbon / config

Function config

codecarbon/cli/main.py:160–314  ·  view source on GitHub ↗

Initialize CodeCarbon, this will prompt you for configuration of Organisation/Team/Project/Experiment.

()

Source from the content-addressed store, hash-verified

158
159@codecarbon.command("config", short_help="Generate or show config")
160def config():
161 """
162 Initialize CodeCarbon, this will prompt you for configuration of Organisation/Team/Project/Experiment.
163 """
164
165 print("Welcome to CodeCarbon configuration wizard")
166 home = Path.home()
167 global_path = (home / ".codecarbon.config").expanduser().resolve()
168
169 if global_path.exists():
170 print("Existing global config file found :")
171 show_config(global_path)
172
173 use_config = questionary_prompt(
174 "Use existing global ~/.codecarbon.config to configure or create a new file somewhere else ?",
175 ["~/.codecarbon.config", "Create New Config"],
176 default="~/.codecarbon.config",
177 )
178
179 if use_config == "~/.codecarbon.config":
180 modify = Confirm.ask("Do you want to modify the existing config file ?")
181 if modify:
182 print(f"Modifying existing config file {global_path}:")
183 file_path = global_path
184 else:
185 print(f"Using already existing global config file {global_path}")
186
187 return
188 else:
189 file_path = create_new_config_file()
190 else:
191 file_path = create_new_config_file()
192
193 api_endpoint = get_api_endpoint(file_path)
194 api_endpoint = typer.prompt(
195 f"Current API endpoint is {api_endpoint}. Press enter to continue or input other url",
196 type=str,
197 default=api_endpoint,
198 )
199 overwrite_local_config("api_endpoint", api_endpoint, path=file_path)
200 api = ApiClient(endpoint_url=api_endpoint)
201 api.set_access_token(get_access_token())
202 organizations = api.get_list_organizations()
203 org = questionary_prompt(
204 "Pick existing organization from list or Create new organization ?",
205 [org["name"] for org in organizations] + ["Create New Organization"],
206 default="Create New Organization",
207 )
208
209 if org == "Create New Organization":
210 org_name = typer.prompt("Organization name", default="Code Carbon user test")
211 org_description = typer.prompt(
212 "Organization description", default="Code Carbon user test"
213 )
214
215 organization_create = OrganizationCreate(
216 name=org_name,
217 description=org_description,

Callers

nothing calls this directly

Calls 15

set_access_tokenMethod · 0.95
create_organizationMethod · 0.95
create_projectMethod · 0.95
add_experimentMethod · 0.95
create_new_config_fileFunction · 0.90
get_api_endpointFunction · 0.90
overwrite_local_configFunction · 0.90
ApiClientClass · 0.90
get_access_tokenFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…