Skip to content

Commit

Permalink
chore(sdk): adding back the required flag for wandb-core (#7228)
Browse files Browse the repository at this point in the history
  • Loading branch information
kptkin committed Apr 9, 2024
1 parent 1633dc0 commit 371cb83
Show file tree
Hide file tree
Showing 21 changed files with 264 additions and 97 deletions.
4 changes: 2 additions & 2 deletions .bumpversion.core.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@ search = CORE_VERSION = "{current_version}"
replace = CORE_VERSION = "{new_version}"

[bumpversion:file:wandb/__init__.py]
search = _minimum_core_version = "{current_version}"
replace = _minimum_core_version = "{new_version}"
search = __core_version__ = "{current_version}"
replace = __core_version__ = "{new_version}"
7 changes: 7 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,9 @@ jobs:

executor: <<parameters.executor>>

environment:
WANDB__REQUIRE_CORE: <<parameters.with_core>>

# Shards the job, setting $CIRCLE_NODE_TOTAL and $CIRCLE_NODE_INDEX.
# https://circleci.com/docs/parallelism-faster-jobs/
parallelism: 2
Expand Down Expand Up @@ -489,6 +492,9 @@ jobs:

executor: <<parameters.executor>>

environment:
WANDB__REQUIRE_CORE: <<parameters.with_core>>

parallelism: 4

steps:
Expand Down Expand Up @@ -623,6 +629,7 @@ jobs:
environment:
SHARD: << parameters.shard >>
COVERAGE_DIR: << parameters.coverage_dir >>
WANDB__REQUIRE_CORE: << parameters.with_core >>
parallelism: << parameters.parallelism >>
resource_class: xlarge
working_directory: /mnt/ramdisk
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ here on every PR where this is applicable.

* Correctly report file upload errors when using wandb-core by @moredatarequired in https://github.com/wandb/wandb/pull/7196

### Changed

* When using `wandb-core` need to specify a required flag (`wandb.require("core")`) to enable it, before it was picked up automatically by @kptkin in https://github.com/wandb/wandb/pull/7228

## [0.16.6] - 2024-04-03

### Added
Expand Down
12 changes: 11 additions & 1 deletion core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@ the package in your environment. The `wandb` library will automatically detect a
pip install -U wandb wandb-core
```

Note: ensure you have `wandb>=0.16.4`.
in the top of your script add the following:

```python
import wandb

wandb.require("core")
```

Note: ensure you have `wandb>0.16.6`.

### Platform Compatibility

Expand All @@ -42,6 +50,8 @@ To revert to the old SDK backend, simply uninstall `wandb-core` from your enviro
pip uninstall wandb-core
```

or remove the `wandb.require("core")` from your script.

## Contributing

Your contributions are welcome! Check our [contributing guide](docs/contributing.md) for instructions on setting up your development environment and contributing to the project.
Expand Down
102 changes: 52 additions & 50 deletions core/pkg/service/wandb_settings.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,6 @@ def test_notebook_not_exists(mocked_ipython, wandb_init, capsys):

def test_databricks_notebook_doesnt_hang_on_wandb_login(mocked_module):
# test for WB-5264

# make the test think we are running in a databricks notebook
dbutils = mocked_module("dbutils")
dbutils.shell.sc.appName = "Databricks Shell"

# when we try to call wandb.login(), should fail with no-tty
with mock.patch.object(
wandb.sdk.lib.apikey,
Expand Down
73 changes: 73 additions & 0 deletions tests/pytest_tests/unit_tests/test_util_wandb_core.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
from unittest.mock import MagicMock, patch

import pytest
from wandb.errors import WandbCoreNotAvailableError
from wandb.util import get_core_path


def test_wandb_core_dev_mode():
"""Test dev mode, both with and without requiring wandb_core."""
mocked_path = "/path/to/core"
with patch("os.environ", {"_WANDB_CORE_PATH": mocked_path}):
path = get_core_path()

assert path == mocked_path


def mocked_wandb_core(version, path):
return MagicMock(
__version__=version,
get_core_path=MagicMock(return_value=path),
)


def test_wandb_core_installed_compatibly_version():
"""Test that when wandb_core is required, and the installed version is compatible, we return the path."""
version = "0.10.0"
mocked_path = "/path/to/core"

with patch("wandb.__core_version__", version), patch(
"wandb.util.get_module",
return_value=mocked_wandb_core(version, mocked_path),
):
path = get_core_path()

assert path == mocked_path


def test_wandb_core_installed_incompatibly_version():
"""Test that when wandb_core is required, but the installed version is incompatible, we raise an exception."""
with patch("wandb.__core_version__", "0.10.0"), patch(
"wandb.util.get_module",
return_value=mocked_wandb_core(
"0.11.0",
"/path/to/core",
),
):
with pytest.raises(ImportError):
get_core_path()


def test_wandb_core_not_installed():
"""Test that when wandb_core is required, but not installed, we raise an exception."""

class TestError(Exception):
pass

with patch("wandb.util.get_module", side_effect=TestError):
with pytest.raises(TestError):
get_core_path()


def test_wandb_core_installed_no_op():
"""Test that when wandb_core is required, and the installed version is no-op, we raise an exception."""
version = "0.10.0"
with patch("wandb.__core_version__", version), patch(
"wandb.util.get_module",
return_value=mocked_wandb_core(
version,
"",
),
):
with pytest.raises(WandbCoreNotAvailableError):
get_core_path()
4 changes: 4 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ passenv=
CI_PYTEST_PARALLEL
CI
importer-wandb: WANDB_TEST_SERVER_URL2
WANDB__REQUIRE_CORE
allowlist_externals=
mkdir
nox
Expand Down Expand Up @@ -133,6 +134,7 @@ passenv=
SHARD
WANDB_API_KEY
core: GOCOVERDIR
WANDB__REQUIRE_CORE
allowlist_externals=
mkdir
core: nox
Expand Down Expand Up @@ -164,6 +166,7 @@ passenv=
; llm: WANDB_API_KEY
llm: OPENAI_API_KEY
llm: CO_API_KEY
WANDB__REQUIRE_CORE
allowlist_externals=
mkdir
commands_pre=
Expand All @@ -186,6 +189,7 @@ passenv=
USERNAME
WANDB_API_KEY
SHARD
WANDB__REQUIRE_CORE
deps=
yea-wandb=={env:YEA_WANDB_VERSION}
wheel
Expand Down
3 changes: 2 additions & 1 deletion wandb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
For reference documentation, see https://docs.wandb.com/ref/python.
"""
__version__ = "0.16.7.dev1"
_minimum_core_version = "0.17.0b10"
__core_version__ = "0.17.0b10"


# Used with pypi checks and other messages related to pip
_wandb_module = "wandb"
Expand Down
5 changes: 5 additions & 0 deletions wandb/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
LAUNCH_QUEUE_NAME = "WANDB_LAUNCH_QUEUE_NAME"
LAUNCH_QUEUE_ENTITY = "WANDB_LAUNCH_QUEUE_ENTITY"
LAUNCH_TRACE_ID = "WANDB_LAUNCH_TRACE_ID"
_REQUIRE_CORE = "WANDB__REQUIRE_CORE"

# For testing, to be removed in future version
USE_V1_ARTIFACTS = "_WANDB_USE_V1_ARTIFACTS"
Expand Down Expand Up @@ -146,6 +147,10 @@ def _env_as_bool(
return val if isinstance(val, bool) else False


def is_require_core(env: Optional[Env] = None) -> bool:
return _env_as_bool(_REQUIRE_CORE, default="False", env=env)


def is_debug(default: Optional[str] = None, env: Optional[Env] = None) -> bool:
return _env_as_bool(DEBUG, default=default, env=env)

Expand Down
5 changes: 5 additions & 0 deletions wandb/errors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"AuthenticationError",
"UsageError",
"UnsupportedError",
"WandbCoreNotAvailableError",
]

from typing import Optional
Expand Down Expand Up @@ -39,3 +40,7 @@ class UsageError(Error):

class UnsupportedError(UsageError):
"""Raised when trying to use a feature that is not supported."""


class WandbCoreNotAvailableError(Error):
"""Raised when wandb core is not available."""
Loading

0 comments on commit 371cb83

Please sign in to comment.