Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added NEPTUNE_MODE env variables and support in all metadata containers #928

Merged
merged 5 commits into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## [UNRELEASED] neptune-client 0.16.5


## Features
- Added `NEPTUNE_MODE` environment variable ([#928](https://github.com/neptune-ai/neptune-client/pull/928))
- Added support of Service account management ([#927](https://github.com/neptune-ai/neptune-client/pull/927))

## neptune-client 0.16.4

Expand Down
2 changes: 2 additions & 0 deletions neptune/new/envs.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#


CONNECTION_MODE = "NEPTUNE_MODE"
Raalsky marked this conversation as resolved.
Show resolved Hide resolved

PROJECT_ENV_NAME = "NEPTUNE_PROJECT"

API_TOKEN_ENV_NAME = "NEPTUNE_API_TOKEN"
Expand Down
9 changes: 6 additions & 3 deletions neptune/new/internal/init/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
# limitations under the License.
#

import os
import threading
from typing import Optional

from neptune.new.attributes import constants as attr_consts
from neptune.new.envs import CONNECTION_MODE
from neptune.new.exceptions import (
NeedExistingModelForReadOnlyMode,
NeptuneException,
Expand Down Expand Up @@ -49,7 +51,7 @@ def init_model(
key: Optional[str] = None,
project: Optional[str] = None,
api_token: Optional[str] = None,
mode: str = Mode.ASYNC.value,
mode: Optional[str] = None,
flush_period: float = DEFAULT_FLUSH_PERIOD,
proxies: Optional[dict] = None,
) -> Model:
Expand All @@ -58,11 +60,12 @@ def init_model(
verify_type("key", key, (str, type(None)))
verify_type("project", project, (str, type(None)))
verify_type("api_token", api_token, (str, type(None)))
verify_type("mode", mode, str)
verify_type("mode", mode, (str, type(None)))
verify_type("flush_period", flush_period, (int, float))
verify_type("proxies", proxies, (dict, type(None)))

# make mode proper Enum instead of string
mode = Mode(mode)
mode = Mode(mode or os.getenv(CONNECTION_MODE) or Mode.ASYNC.value)

if mode == Mode.OFFLINE:
raise NeptuneException("Model can't be initialized in OFFLINE mode")
Expand Down
9 changes: 6 additions & 3 deletions neptune/new/internal/init/model_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
# limitations under the License.
#

import os
import threading
from typing import Optional

from neptune.new.attributes import constants as attr_consts
from neptune.new.envs import CONNECTION_MODE
from neptune.new.exceptions import (
NeedExistingModelVersionForReadOnlyMode,
NeptuneException,
Expand Down Expand Up @@ -47,7 +49,7 @@ def init_model_version(
model: Optional[str] = None,
project: Optional[str] = None,
api_token: Optional[str] = None,
mode: str = Mode.ASYNC.value,
mode: Optional[str] = None,
flush_period: float = DEFAULT_FLUSH_PERIOD,
proxies: Optional[dict] = None,
) -> ModelVersion:
Expand All @@ -56,11 +58,12 @@ def init_model_version(
verify_type("model", model, (str, type(None)))
verify_type("project", project, (str, type(None)))
verify_type("api_token", api_token, (str, type(None)))
verify_type("mode", mode, str)
verify_type("mode", mode, (str, type(None)))
verify_type("flush_period", flush_period, (int, float))
verify_type("proxies", proxies, (dict, type(None)))

# make mode proper Enum instead of string
mode = Mode(mode)
mode = Mode(mode or os.getenv(CONNECTION_MODE) or Mode.ASYNC.value)

if mode == Mode.OFFLINE:
raise NeptuneException("Model can't be initialized in OFFLINE mode")
Expand Down
9 changes: 6 additions & 3 deletions neptune/new/internal/init/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
import os
import threading
from typing import Optional

from neptune.new.envs import CONNECTION_MODE
from neptune.new.exceptions import NeptuneException
from neptune.new.internal import id_formats
from neptune.new.internal.backends.factory import get_backend
Expand All @@ -33,17 +35,18 @@ def init_project(
*,
name: Optional[str] = None,
api_token: Optional[str] = None,
mode: str = Mode.ASYNC.value,
mode: Optional[str] = None,
flush_period: float = DEFAULT_FLUSH_PERIOD,
proxies: Optional[dict] = None,
) -> Project:
verify_type("name", name, (str, type(None)))
verify_type("api_token", api_token, (str, type(None)))
verify_type("mode", mode, str)
verify_type("mode", mode, (str, type(None)))
verify_type("flush_period", flush_period, (int, float))
verify_type("proxies", proxies, (dict, type(None)))

# make mode proper Enum instead of string
mode = Mode(mode)
mode = Mode(mode or os.getenv(CONNECTION_MODE) or Mode.ASYNC.value)

if mode == Mode.OFFLINE:
raise NeptuneException("Project can't be initialized in OFFLINE mode")
Expand Down
12 changes: 7 additions & 5 deletions neptune/new/internal/init/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

from neptune.new.attributes import constants as attr_consts
from neptune.new.envs import (
CONNECTION_MODE,
CUSTOM_RUN_ID_ENV_NAME,
MONITORING_NAMESPACE,
NEPTUNE_NOTEBOOK_ID,
Expand Down Expand Up @@ -82,7 +83,7 @@ def init_run(
api_token: Optional[str] = None,
run: Optional[str] = None,
custom_run_id: Optional[str] = None,
mode: str = Mode.ASYNC.value,
mode: Optional[str] = None,
name: Optional[str] = None,
description: Optional[str] = None,
tags: Optional[Union[List[str], str]] = None,
Expand Down Expand Up @@ -113,7 +114,9 @@ def init_run(
custom_run_id (str, optional): A unique identifier to be used when running Neptune in pipelines.
Defaults to `None`.
Make sure you are using the same identifier throughout the whole pipeline execution.
mode (str, optional): Connection mode in which the tracking will work. Defaults to `'async'`.
mode (str, optional): Connection mode in which the tracking will work. Defaults to `None`.
If `None`, the value of `NEPTUNE_MODE` environment variable will be taken.
If no value was set for environment variable then `'async'` at default.
Possible values 'async', 'sync', 'offline', 'read-only' and 'debug'.
name (str, optional): Editable name of the run. Defaults to `'Untitled'`.
Name is displayed in the run's Details and in Runs table as a column.
Expand Down Expand Up @@ -197,7 +200,7 @@ def init_run(
verify_type("api_token", api_token, (str, type(None)))
verify_type("run", run, (str, type(None)))
verify_type("custom_run_id", custom_run_id, (str, type(None)))
verify_type("mode", mode, str)
verify_type("mode", mode, (str, type(None)))
verify_type("name", name, (str, type(None)))
verify_type("description", description, (str, type(None)))
verify_type("capture_stdout", capture_stdout, bool)
Expand All @@ -219,8 +222,7 @@ def init_run(
verify_collection_type("source_files", source_files, str)

# for backward compatibility imports
mode = Mode(mode)

mode = Mode(mode or os.getenv(CONNECTION_MODE) or Mode.ASYNC.value)
name = DEFAULT_NAME if run is None and name is None else name
description = "" if run is None and description is None else description
hostname = get_hostname() if run is None else None
Expand Down