Skip to content
Draft
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
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
metricflow==0.209.0
# Using the root so tests in `dbt-metricflow` run using the current code in `metricflow`.
# This ensures that breaking changes are resolved in the PR that makes the breaking change.
# This should be updated to the correct version before release.
metricflow @ {root:parent:uri}
15 changes: 15 additions & 0 deletions scripts/ci_tests/dbt_metricflow_package_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from pathlib import Path
from typing import Optional

from dbt_metricflow.cli.cli_configuration import CLIConfiguration


def _run_shell_command(command: str, cwd: Optional[Path] = None) -> None:
if cwd is None:
Expand Down Expand Up @@ -37,3 +39,16 @@ def _run_shell_command(command: str, cwd: Optional[Path] = None) -> None:
"mf query --metrics transactions --group-by metric_time --order metric_time",
cwd=tutorial_directory,
)

# Check that log messages are written as spected to the log file.
log_file_path = tutorial_directory.joinpath("logs", CLIConfiguration.LOG_FILE_NAME)
assert log_file_path.exists(), f"Log file not present at expected location: {str(log_file_path)}"

with open(tutorial_directory.joinpath("logs", CLIConfiguration.LOG_FILE_NAME)) as fp:
log_file_contents = fp.read()

assert CLIConfiguration.LOG_FILE_NAME in log_file_contents, (
f"Log file ({log_file_path}) is missing message indicating logging has been set up."
f"\nLog file contents:"
f"\n{textwrap.indent(log_file_contents, prefix=' ')}"
)
63 changes: 37 additions & 26 deletions scripts/ci_tests/run_package_build_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,24 @@
logger = logging.getLogger(__name__)


def _run_package_build_test(
package_directory: Path, package_test_script: Path, optional_package_dependencies_to_install: Sequence[str] = ()
def _run_package_test(
package_directory: Path,
package_test_script: Path,
build_wheel: bool,
optional_package_dependencies_to_install: Sequence[str] = (),
) -> None:
"""Run a test to verify that a package is built properly.
"""Run tests to verify a package.

Given the directory where the package is located, this will build the package using `hatch build` and install the
created Python-wheel files into a clean virtual environment. Finally, the given test script will be run using the
virtual environment.
Given the directory where the package is located, install the package by using a wheel built from the package or an
use editable installation. Once installed, run the package test script.

Args:
package_directory: Root directory where the package is located.
package_test_script: The path to the script that should be run.
optional_package_dependencies_to_install: If the given package defines optional dependencies that can be
installed, install these. e.g. for `dbt-metricflow[dbt-duckdb]`, specify `dbt-duckdb`.
build_wheel: If set, build a wheel from the package and install the wheel in the virtual environment. Otherwise,
use an editable installation.
Returns: None
Raises: Exception on test failure.
"""
Expand All @@ -46,21 +50,25 @@ def _run_package_build_test(
venv.create(venv_directory, with_pip=True)
pip_executable = Path(venv_directory, "bin/pip").as_posix()

logger.info(f"Building package at {package_directory_str!r}")
MetricFlowScriptHelper.run_command(["hatch", "clean"], working_directory=package_directory)
MetricFlowScriptHelper.run_command(["hatch", "build"], working_directory=package_directory)
logger.info(f"Using package at {package_directory_str!r}")

logger.info("Installing package in venv using generated wheels")
paths_to_wheels = _get_wheels_in_directory(package_directory.joinpath("dist"))
if len(paths_to_wheels) != 1:
raise RuntimeError(f"Expected exactly one wheel but got {paths_to_wheels}")
if build_wheel:
MetricFlowScriptHelper.run_command(["hatch", "clean"], working_directory=package_directory)
MetricFlowScriptHelper.run_command(["hatch", "build"], working_directory=package_directory)

path_to_wheel = paths_to_wheels[0]
MetricFlowScriptHelper.run_command([pip_executable, "install", path_to_wheel.as_posix()])
for optional_package_dependency in optional_package_dependencies_to_install:
MetricFlowScriptHelper.run_command(
[pip_executable, "install", f"{path_to_wheel.as_posix()}[{optional_package_dependency}]"]
)
logger.info("Installing package in venv using generated wheels")
paths_to_wheels = _get_wheels_in_directory(package_directory.joinpath("dist"))
if len(paths_to_wheels) != 1:
raise RuntimeError(f"Expected exactly one wheel but got {paths_to_wheels}")

path_to_wheel = paths_to_wheels[0]
MetricFlowScriptHelper.run_command([pip_executable, "install", path_to_wheel.as_posix()])
for optional_package_dependency in optional_package_dependencies_to_install:
MetricFlowScriptHelper.run_command(
[pip_executable, "install", f"{path_to_wheel.as_posix()}[{optional_package_dependency}]"]
)
else:
MetricFlowScriptHelper.run_command([pip_executable, "install", "-e", package_directory_str])

logger.info("Running test using venv")
venv_activate = venv_directory.joinpath("bin", "activate").as_posix()
Expand All @@ -72,7 +80,7 @@ def _run_package_build_test(
logger.info(f"Test passed {package_test_script_str!r}")
except Exception as e:
raise PackageBuildTestFailureException(
f"Package build test failed for {package_directory_str!r} using {package_test_script_str!r}"
f"Package test failed for {package_directory_str!r} using {package_test_script_str!r}"
) from e


Expand All @@ -99,21 +107,24 @@ class PackageBuildTestFailureException(Exception): # noqa: D101

logger.info(f"Using {metricflow_repo_directory=}")

# Test building the `metricflow` package.
_run_package_build_test(
# Test the `metricflow` package.
_run_package_test(
package_directory=metricflow_repo_directory,
package_test_script=metricflow_repo_directory.joinpath("scripts/ci_tests/metricflow_package_test.py"),
build_wheel=True,
)

# Test building the `metricflow-semantics` package.
_run_package_build_test(
# Test the `metricflow-semantics` package.
_run_package_test(
package_directory=metricflow_repo_directory.joinpath("metricflow-semantics"),
package_test_script=metricflow_repo_directory.joinpath("scripts/ci_tests/metricflow_semantics_package_test.py"),
build_wheel=True,
)

# Test building the `dbt-metricflow` package.
_run_package_build_test(
# Test the `dbt-metricflow` package.
_run_package_test(
package_directory=metricflow_repo_directory.joinpath("dbt-metricflow"),
package_test_script=metricflow_repo_directory.joinpath("scripts/ci_tests/dbt_metricflow_package_test.py"),
optional_package_dependencies_to_install=("dbt-duckdb",),
build_wheel=False,
)
Loading