Skip to content

Commit

Permalink
/* PR_START p--release-setup 06 */ Redo: #1628 (#1633)
Browse files Browse the repository at this point in the history
This is a redo of #1628 as I needed to change the commit order and add a
change log entry.
  • Loading branch information
plypaul committed Jan 28, 2025
1 parent 2ec9368 commit 1679164
Show file tree
Hide file tree
Showing 10 changed files with 248 additions and 78 deletions.
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 the 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

0 comments on commit 1679164

Please sign in to comment.