How to use the wandb.apis.InternalApi function in wandb

To help you get started, we’ve selected a few wandb examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wandb / client / tests / test_cli.py View on Github external
def test_restore_bad_remote(runner, request_mocker, query_run, git_repo, docker, monkeypatch):
    # git_repo creates it's own isolated filesystem
    mock = query_run(request_mocker, {"git": {"repo": "http://fake.git/foo/bar"}})
    api = InternalApi({'project': 'test'})
    monkeypatch.setattr(cli, 'api', api)
    def bad_commit(cmt):
        raise ValueError()
    monkeypatch.setattr(api.git.repo, 'commit', bad_commit)
    monkeypatch.setattr(api, "download_urls", lambda *args, **kwargs: []) 
    result = runner.invoke(cli.restore, ["wandb/test:abcdef"])
    print(result.output)
    print(traceback.print_tb(result.exc_info[2]))
    assert result.exit_code == 1
    assert "Run `git clone http://fake.git/foo/bar`" in result.output
github wandb / client / tests / test_system_stats.py View on Github external
def api():
    return wandb.apis.InternalApi()
github wandb / client / tests / test_cli.py View on Github external
def test_login_anonymously(runner, monkeypatch, empty_netrc, local_netrc):
    with runner.isolated_filesystem():
        api = InternalApi()
        monkeypatch.setattr(cli, 'api', api)
        monkeypatch.setattr(api, 'create_anonymous_api_key', lambda *args, **kwargs: DUMMY_API_KEY)
        result = runner.invoke(cli.login, ['--anonymously'])
        print('Output: ', result.output)
        print('Exception: ', result.exception)
        print('Traceback: ', traceback.print_tb(result.exc_info[2]))
        assert result.exit_code == 0
        with open("netrc", "r") as f:
            generated_netrc = f.read()
        assert DUMMY_API_KEY in generated_netrc
github wandb / client / tests / test_cli.py View on Github external
def docker(request_mocker, query_run, mocker, monkeypatch):
    mock = query_run(request_mocker)
    docker = mocker.MagicMock()
    api_key = mocker.patch('wandb.apis.InternalApi.api_key', new_callable=mocker.PropertyMock)
    api_key.return_value = "test"
    api = InternalApi({'project': 'test'})
    monkeypatch.setattr(cli, 'find_executable', lambda name: True)
    monkeypatch.setattr(cli, 'api', api)
    old_call = subprocess.call
    def new_call(command, **kwargs):
        if command[0] == "docker":
            return docker(command)
        else:
            return old_call(command, **kwargs)
    monkeypatch.setattr(subprocess, 'call', new_call)
    monkeypatch.setattr(subprocess, 'check_output',
                        lambda *args, **kwargs: b"wandb/deepo@sha256:abc123")
    return docker
github wandb / client / tests / test_meta.py View on Github external
def test_git_untracked_notebook_env(monkeypatch, git_repo, mocker):
    mocker.patch('wandb._get_python_type', lambda: "jupyter")
    with open("test.ipynb", "w") as f:
        f.write("{}")
    os.environ[env.NOTEBOOK_NAME] = "test.ipynb"
    meta = Meta(InternalApi())
    assert meta.data["program"] == "test.ipynb"
    assert meta.data["codeSaved"]
    assert os.path.exists("code/test.ipynb")
    os.environ[env.NOTEBOOK_NAME]
github wandb / client / wandb / internal_cli.py View on Github external
def agent_run(args):
    """A version of `wandb run` that the agent uses to run things.
    """
    run = wandb.wandb_run.Run.from_environment_or_defaults()
    run.enable_logging()

    api = wandb.apis.InternalApi()
    api.set_current_run_id(run.id)

    # TODO: better failure handling
    root = api.git.root
    # handle non-git directories
    if not root:
        root = os.path.abspath(os.getcwd())
        host = socket.gethostname()
        remote_url = 'file://%s%s' % (host, root)

    run.save(program=args['program'], api=api)
    env = dict(os.environ)
    run.set_environment(env)

    try:
        rm = wandb.run_manager.RunManager(api, run)
github wandb / client / wandb / wandb_agent.py View on Github external
env.set_entity(entity)
    if project:
        env.set_project(project)
    logger.setLevel(logging.DEBUG)
    ch = logging.StreamHandler()
    log_level = logging.DEBUG
    if in_jupyter:
        log_level = logging.ERROR
    ch.setLevel(log_level)
    formatter = logging.Formatter(
        '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    ch.setFormatter(formatter)
    try:
        logger.addHandler(ch)

        api = InternalApi()
        queue = multiprocessing.Queue()
        agent = Agent(api, queue, sweep_id=sweep_id, function=function, in_jupyter=in_jupyter, count=count)
        agent.run()
    finally:
        # make sure we remove the logging handler (important for jupyter notebooks)
        logger.removeHandler(ch)
github wandb / client / wandb / wandb_run.py View on Github external
def api(self):
        if self._api is None:
            self._api = InternalApi()
            self._api.set_current_run_id(self.id)
        return self._api
github wandb / client / wandb / wandb_controller.py View on Github external
if isinstance(sweep, types.FunctionType):
        sweep = sweep()
    if isinstance(sweep, SweepConfig):
        sweep = dict(sweep)
    """Sweep create for controller api and jupyter (eventually for cli)."""
    in_jupyter = wandb._get_python_type() != "python"
    if in_jupyter:
        os.environ[env.JUPYTER] = "true"
        _api0 = InternalApi()
        if not _api0.api_key:
            wandb._jupyter_login(api=_api0)
    if entity:
        env.set_entity(entity)
    if project:
        env.set_project(project)
    api = InternalApi()
    sweep_id = api.upsert_sweep(sweep)
    print('Create sweep with ID:', sweep_id)
    sweep_url = _get_sweep_url(api, sweep_id)
    if sweep_url:
        print('Sweep URL:', sweep_url)
    return sweep_id