def login(anonymous=None, key=None): """Ensure this machine is logged in You can manually specify a key, but this method is intended to prompt for user input. anonymous can be "never", "must", or "allow". If set to "must" we'll always login anonymously, if set to "allow" we'll only create an anonymous user if the user isn't already logged in. Returns: True if login was successful False on failure """ # This ensures we have a global api object ensure_configured() if anonymous: os.environ[env.ANONYMOUS] = anonymous anonymous = anonymous or "never" in_jupyter = _get_python_type() != "python" if key: termwarn("If you're specifying your api key in code, ensure this code is not shared publically.\nConsider setting the WANDB_API_KEY environment variable, or running `wandb login` from the command line.") if in_jupyter: termwarn("Calling wandb.login() without arguments from jupyter should prompt you for an api key.") util.set_api_key(api, key) elif api.api_key and anonymous != "must": key = api.api_key elif in_jupyter: os.environ[env.JUPYTER] = "true" # Don't return key to ensure it's not displayed in the notebook. key = _jupyter_login(api=api) else: key = util.prompt_api_key(api) return True if key else False
def login(key, host, anonymously, server=LocalServer(), browser=True, no_offline=False): global api if host == "https://api.wandb.ai": api.clear_setting("base_url", globally=True) elif host: if not host.startswith("http"): raise ClickException("host must start with http(s)://") api.set_setting("base_url", host, globally=True) key = key[0] if len(key) > 0 else None # Import in here for performance reasons import webbrowser browser = util.launch_browser(browser) def get_api_key_from_browser(signup=False): if not browser: return None query = '?signup=true' if signup else '' webbrowser.open_new_tab('{}/authorize{}'.format(api.app_url, query)) #Getting rid of the server for now. We would need to catch Abort from server.stop and deal accordingly #server.start(blocking=False) #if server.result.get("key"): # return server.result["key"][0] return None if key: util.set_api_key(api, key) else: if anonymously: os.environ[env.ANONYMOUS] = "must" # Don't allow signups or dryrun for local local = host != None or host != "https://api.wandb.ai" key = util.prompt_api_key(api, input_callback=click.prompt, browser_callback=get_api_key_from_browser, no_offline=no_offline, local=local) if key: api.clear_setting('disabled') click.secho("Successfully logged in to Weights & Biases!", fg="green") elif not no_offline: api.set_setting('disabled', 'true') click.echo( "Disabling Weights & Biases. Run 'wandb login' again to re-enable." ) # reinitialize API to create the new client api = InternalApi() return key
def login(key, server=LocalServer(), browser=True, anonymous=False): global api key = key[0] if len(key) > 0 else None # Import in here for performance reasons import webbrowser browser = util.launch_browser(browser) def get_api_key_from_browser(): if not browser: return None launched = webbrowser.open_new_tab('{}/authorize?{}'.format( api.app_url, server.qs())) if not launched: return None server.start(blocking=True) if server.result.get("key"): return server.result["key"][0] return None if key: util.set_api_key(api, key) else: key = util.prompt_api_key(api, browser_callback=get_api_key_from_browser, anonymous=anonymous) if key: api.clear_setting('disabled') click.secho("Successfully logged in to Weights & Biases!", fg="green") else: api.set_setting('disabled', 'true') click.echo( "Disabling Weights & Biases. Run 'wandb login' again to re-enable." ) # reinitialize API to create the new client api = InternalApi() return key
def login(key, anonymously, server=LocalServer(), browser=True): global api key = key[0] if len(key) > 0 else None # Import in here for performance reasons import webbrowser browser = util.launch_browser(browser) def get_api_key_from_browser(signup=False): if not browser: return None query = '?signup=true' if signup else '' webbrowser.open_new_tab('{}/authorize{}'.format(api.app_url, query)) #Getting rid of the server for now. We would need to catch Abort from server.stop and deal accordingly #server.start(blocking=False) #if server.result.get("key"): # return server.result["key"][0] return None if key: util.set_api_key(api, key) else: if anonymously: os.environ[env.ANONYMOUS] = "must" key = util.prompt_api_key(api, input_callback=click.prompt, browser_callback=get_api_key_from_browser) if key: api.clear_setting('disabled') click.secho("Successfully logged in to Weights & Biases!", fg="green") else: api.set_setting('disabled', 'true') click.echo( "Disabling Weights & Biases. Run 'wandb login' again to re-enable." ) # reinitialize API to create the new client api = InternalApi() return key