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

[MAINTENANCE] Make mode arg to get_context take precedence #8990

Merged
merged 3 commits into from
Nov 29, 2023
Merged
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
15 changes: 11 additions & 4 deletions great_expectations/data_context/data_context/context_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from pathlib import Path
from typing import (
TYPE_CHECKING,
Callable,
Literal,
Mapping,
Type,
Expand Down Expand Up @@ -189,14 +190,12 @@ def get_context( # noqa: PLR0913
"ephemeral": dict(
project_config=project_config,
runtime_environment=runtime_environment,
cloud_mode=False,
),
"file": dict(
project_config=project_config,
context_root_dir=context_root_dir,
project_root_dir=project_root_dir or Path.cwd(),
runtime_environment=runtime_environment,
cloud_mode=False,
),
"cloud": dict(
project_config=project_config,
Expand All @@ -206,7 +205,6 @@ def get_context( # noqa: PLR0913
cloud_base_url=cloud_base_url,
cloud_access_token=cloud_access_token,
cloud_organization_id=cloud_organization_id,
cloud_mode=True,
),
None: dict(
project_config=project_config,
Expand Down Expand Up @@ -245,7 +243,16 @@ def get_context( # noqa: PLR0913
"cloud": CloudDataContext,
None: AbstractDataContext,
}
context = _get_context(**kwargs)

context_fn_map: dict[ContextModes | None, Callable] = {
"ephemeral": _get_ephemeral_context,
"file": _get_file_context,
"cloud": _get_cloud_context,
None: _get_context,
}

context_fn = context_fn_map[mode]
context = context_fn(**kwargs)

expected_type = expected_ctx_types[mode]
if not isinstance(context, expected_type):
Expand Down
Loading