33import time
44from pathlib import Path
55from typing import Optional
6+ from uuid import uuid4
67
78import questionary
89import requests
1617from codecarbon import __app_name__ , __version__
1718from codecarbon .cli .cli_utils import (
1819 create_new_config_file ,
20+ get_api_enabled ,
1921 get_api_endpoint ,
2022 get_config ,
2123 get_existing_local_exp_id ,
@@ -201,13 +203,29 @@ def config():
201203 else :
202204 file_path = create_new_config_file ()
203205
206+ api_enabled = get_api_enabled ()
207+ api_enabled = typer .prompt (
208+ f"API is currently { 'enabled' if api_enabled == '1' else 'disabled' } . Press enter to continue or change to 0/1" ,
209+ type = str ,
210+ default = "0" ,
211+ )
212+ overwrite_local_config ("api_enabled" , api_enabled , path = file_path )
213+
214+ if api_enabled == "0" :
215+ overwrite_local_config ("experiment_id" , str (uuid4 ()), path = file_path )
216+ return
217+
204218 api_endpoint = get_api_endpoint (file_path )
205219 api_endpoint = typer .prompt (
206- f"Current API endpoint is { api_endpoint } . Press enter to continue or input other url" ,
220+ f"Current API endpoint is at { api_endpoint } . Press enter to continue or input other url" ,
207221 type = str ,
208222 default = api_endpoint ,
209223 )
210224 overwrite_local_config ("api_endpoint" , api_endpoint , path = file_path )
225+
226+ print (f"Logging into the auth server at { AUTH_SERVER_URL } " )
227+ fief_auth .authorize ()
228+
211229 api = ApiClient (endpoint_url = api_endpoint )
212230 api .set_access_token (_get_access_token ())
213231 organizations = api .get_list_organizations ()
@@ -334,8 +352,8 @@ def monitor(
334352 int , typer .Argument (help = "Number of measures between API calls." )
335353 ] = 30 ,
336354 api : Annotated [
337- bool , typer .Option (help = "Choose to call Code Carbon API or not" )
338- ] = True ,
355+ Optional [ bool ] , typer .Option (help = "Choose to call Code Carbon API or not" )
356+ ] = None ,
339357):
340358 """Monitor your machine's carbon emissions.
341359
@@ -344,6 +362,8 @@ def monitor(
344362 api_call_interval (Annotated[int, typer.Argument, optional): Number of measures before calling API. Defaults to 30.
345363 api (Annotated[bool, typer.Option, optional): Choose to call Code Carbon API or not. Defaults to True.
346364 """
365+ if api is None :
366+ api = get_api_enabled () == "1"
347367 experiment_id = get_existing_local_exp_id ()
348368 if api :
349369 if experiment_id is None :
0 commit comments