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

Redo: #1628 #1633

Merged
merged 6 commits into from
Jan 24, 2025
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
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20250124-140300.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: Fix `mf tutorial` experience.
time: 2025-01-24T14:03:00.410289-08:00
custom:
Author: plypaul
Issue: "1631"
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,37 @@
logger = logging.getLogger(__name__)


class CLIContext:
"""Context for MetricFlow CLI."""
class CLIConfiguration:
"""Configuration object used for the MetricFlow CLI."""

def __init__(self) -> None:
"""Initialize the CLI context for executing commands.

The dbt_artifacts construct must be loaded in order for logging configuration to work correctly.
"""
def __init__(self) -> None: # noqa: D107
self.verbose = False
self._dbt_project_metadata: dbtProjectMetadata = dbtProjectMetadata.load_from_project_path(pathlib.Path.cwd())
self._dbt_project_metadata: Optional[dbtProjectMetadata] = None
self._dbt_artifacts: Optional[dbtArtifacts] = None
self._mf: Optional[MetricFlowEngine] = None
self._sql_client: Optional[SqlClient] = None
self._semantic_manifest: Optional[SemanticManifest] = None
self._semantic_manifest_lookup: Optional[SemanticManifestLookup] = None

def setup(self) -> None:
"""Setup this configuration for executing commands.

The dbt_artifacts construct must be loaded in order for logging configuration to work correctly.
"""
dbt_project_path = pathlib.Path.cwd()
self._dbt_project_metadata = dbtProjectMetadata.load_from_project_path(dbt_project_path)

# self.log_file_path invokes the dbtRunner. If this is done after the configure_logging call all of the
# dbt CLI logging configuration could be overridden, resulting in lots of things printing to console
self._configure_logging(log_file_path=self.log_file_path)

def _get_dbt_project_metadata(self) -> dbtProjectMetadata:
if self._dbt_project_metadata is None:
raise RuntimeError(
f"{self.__class__.__name__}.setup() should have been called before accessing the configuration."
)
return self._dbt_project_metadata

def _configure_logging(self, log_file_path: pathlib.Path) -> None:
"""Initialize the logging spec for the CLI.

Expand Down Expand Up @@ -70,13 +82,13 @@ def _configure_logging(self, log_file_path: pathlib.Path) -> None:
@property
def dbt_project_metadata(self) -> dbtProjectMetadata:
"""Property accessor for dbt project metadata, useful in cases where the full manifest load is not needed."""
return self._dbt_project_metadata
return self._get_dbt_project_metadata()

@property
def dbt_artifacts(self) -> dbtArtifacts:
"""Property accessor for all dbt artifacts, used for powering the sql client (among other things)."""
if self._dbt_artifacts is None:
self._dbt_artifacts = dbtArtifacts.load_from_project_metadata(self._dbt_project_metadata)
self._dbt_artifacts = dbtArtifacts.load_from_project_metadata(self.dbt_project_metadata)
return self._dbt_artifacts

@property
Expand All @@ -85,7 +97,7 @@ def log_file_path(self) -> pathlib.Path:
# The dbt Project.log_path attribute is currently sourced from the final runtime config value accessible
# through the CLI state flags. As such, it will deviate from the default based on the DBT_LOG_PATH environment
# variable. Should this behavior change, we will need to update this call.
return pathlib.Path(self._dbt_project_metadata.project.log_path, "metricflow.log")
return pathlib.Path(self.dbt_project_metadata.project.log_path, "metricflow.log")

@property
def sql_client(self) -> SqlClient:
Expand Down
Loading
Loading