Exemplo n.º 1
0
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
Exemplo n.º 2
0
def docs(ctx):
    import webbrowser
    if util.launch_browser():
        launched = webbrowser.open_new_tab(DOCS_URL)
    else:
        launched = False
    if launched:
        click.echo(click.style(
            "Opening %s in your default browser" % DOCS_URL, fg="green"))
    else:
        click.echo(click.style(
            "You can find our documentation here: %s" % DOCS_URL, fg="green"))
Exemplo n.º 3
0
def login(key, server=LocalServer(), browser=True):
    global api

    key = key[0] if len(key) > 0 else None
    # Import in here for performance reasons
    import webbrowser
    # TODO: use Oauth?: https://community.auth0.com/questions/6501/authenticating-an-installed-cli-with-oidc-and-a-th
    url = api.app_url + '/authorize'
    browser = util.launch_browser(browser)
    if key or not browser:
        launched = False
    else:
        launched = webbrowser.open_new_tab(url + "?{}".format(server.qs()))
    if launched:
        click.echo('Opening [{}] in your default browser'.format(url))
        server.start(blocking=False)
    elif not key:
        click.echo(
            "You can find your API keys in your browser here: {}".format(url))

    def cancel_prompt(*args):
        raise KeyboardInterrupt()

    # Hijacking this signal broke tests in py2...
    # if not os.getenv("WANDB_TEST"):
    signal.signal(signal.SIGINT, cancel_prompt)
    try:
        key = key or click.prompt("Paste an API key from your profile",
                                  value_proc=lambda x: x.strip())
    except Abort:
        if server.result.get("key"):
            key = server.result["key"][0]

    if key:
        # TODO: get the username here...
        # username = api.viewer().get('entity', 'models')
        if util.write_netrc(api.api_url, "user", key):
            click.secho("Successfully logged in to Weights & Biases!",
                        fg="green")
    else:
        click.echo("No key provided, please try again")

    # reinitialize API to create the new client
    api = InternalApi()

    return key
Exemplo n.º 4
0
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
Exemplo n.º 5
0
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
Exemplo n.º 6
0
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)

    # Go through the regular user login flow first, unless --anonymous is specified.
    if not key and not anonymous:
        # TODO: use Oauth?: https://community.auth0.com/questions/6501/authenticating-an-installed-cli-with-oidc-and-a-th
        url = api.app_url + '/authorize'
        if key or not browser:
            launched = False
        else:
            launched = webbrowser.open_new_tab(url + "?{}".format(server.qs()))
        if launched:
            click.echo('Opening [{}] in your default browser'.format(url))
            server.start(blocking=False)
        elif not key:
            click.echo(
                "You can find your API keys in your browser here: {}".format(
                    url))

        def cancel_prompt(*args):
            raise KeyboardInterrupt()

        # Hijacking this signal broke tests in py2...
        # if not os.getenv("WANDB_TEST"):
        signal.signal(signal.SIGINT, cancel_prompt)
        try:
            key = key or click.prompt("Paste an API key from your profile",
                                      value_proc=lambda x: x.strip())
        except Abort:
            if server.result.get("key"):
                key = server.result["key"][0]

        # If we still don't have a key, go through the anonymous user flow if we're running interactively.
        if not key:
            try:
                click.confirm(
                    'No API key found. Would you like to log runs anonymously?',
                    abort=True)
                anonymous = True
            except Abort:
                anonymous = False

    # Go through the anonymous login flow.
    if not key and anonymous:
        if api.api_key:
            click.confirm(
                'You are already logged in. Are you sure you want to create a new anonymous login?',
                abort=True)

        # Generate a new anonymous user and use its API key.
        key = api.create_anonymous_api_key()

        url = api.app_url + '/login?apiKey={}'.format(key)
        if browser:
            webbrowser.open_new_tab(url)

        click.echo(
            "Your anonymous login link: {}. Do not share or lose this link!".
            format(url))

    if key:
        # TODO: get the username here...
        # username = api.viewer().get('entity', 'models')
        if util.write_netrc(api.api_url, "user", key):
            api.set_setting('anonymous', anonymous)
            util.write_settings(settings=api.settings())
            click.secho("Successfully logged in to Weights & Biases!",
                        fg="green")
    else:
        click.echo("No key provided, please try again")

    # reinitialize API to create the new client
    api = InternalApi()

    return key