Skip to content

Commit

Permalink
Port updates from 0.207.1 (#1645)
Browse files Browse the repository at this point in the history
A number of changes were committed to the `release-0.207.1` to fix
issues that were blocking the release. Since those changes got merged
into the release branch, this PR is a port / "backport" of those changes
to the `main` branch.
  • Loading branch information
plypaul authored Jan 28, 2025
1 parent 2ec9368 commit df57b4e
Show file tree
Hide file tree
Showing 31 changed files with 899 additions and 103 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"
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20250124-181618.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: Compatibility Issue with dbt-core 1.9.0 and dbt-metricflow 0.7.1.
time: 2025-01-24T18:16:18.536201-08:00
custom:
Author: plypaul
Issue: "1589"
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20250124-181706.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: dbt-core dependency issue with metricflow==0.207.0.
time: 2025-01-24T18:17:06.936807-08:00
custom:
Author: plypaul
Issue: "1632"
2 changes: 1 addition & 1 deletion .github/actions/setup-python-env/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ inputs:
python-version:
description: "Version of Python to use for testing"
required: false
default: "3.8"
default: "3.9"
hatch-environment-cache-config-json:
description: "Configuration JSON to be passed into the script to install `hatch` environments for caching."
required: false
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cd-push-dbt-metricflow-to-pypi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
- "dbt-metricflow/v[0-9]+.[0-9]+.[0-9]+*"

env:
PYTHON_VERSION: "3.8"
PYTHON_VERSION: "3.9"

jobs:
pypi-publish:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cd-push-metricflow-to-pypi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
- "v[0-9]+.[0-9]+.[0-9]+*"

env:
PYTHON_VERSION: "3.8"
PYTHON_VERSION: "3.9"

jobs:
pypi-publish:
Expand Down
2 changes: 1 addition & 1 deletion dbt-metricflow/dbt_metricflow/__about__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from __future__ import annotations

__version__ = "0.7.0"
__version__ = "0.8.0"
2 changes: 1 addition & 1 deletion dbt-metricflow/dbt_metricflow/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from __future__ import annotations

PACKAGE_NAME = "metricflow"
PACKAGE_NAME = "dbt-metricflow"
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from metricflow_semantics.mf_logging.lazy_formattable import LazyFormat
from metricflow_semantics.model.semantic_manifest_lookup import SemanticManifestLookup

from dbt_metricflow.cli import PACKAGE_NAME
from dbt_metricflow.cli.dbt_connectors.adapter_backed_client import AdapterBackedSqlClient
from dbt_metricflow.cli.dbt_connectors.dbt_config_accessor import dbtArtifacts, dbtProjectMetadata
from metricflow.engine.metricflow_engine import MetricFlowEngine
Expand All @@ -17,24 +18,47 @@
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
# 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 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()
try:
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)
except Exception as e:
exception_message = str(e)
if exception_message.find("Could not find adapter type") != -1:
raise RuntimeError(
f"Got an error during setup, potentially due to a missing adapter package. Has the appropriate "
f"adapter package (`{PACKAGE_NAME}[dbt-*]`) for the dbt project {str(dbt_project_path)!r} been "
f"installed? If not please install it (e.g. `pip install '{PACKAGE_NAME}[dbt-duckdb]')."
) from e
else:
raise e

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 +94,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 +109,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 df57b4e

Please sign in to comment.