Skip to content

Commit

Permalink
Remove EnvironmentVariable helper class
Browse files Browse the repository at this point in the history
This class is doing a whole lot to accomplish very little. In
updating the sql engine url environment variable access I noticed
the old EnvironmentVariable helper was hardly being used at all
anymore. Since most of its usage has disappeared into the sands
of time, we remove the last remaining calls - and the class
itself - here.
  • Loading branch information
tlento committed Aug 15, 2023
1 parent 76d4aeb commit b8f190a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 102 deletions.
Empty file.
93 changes: 0 additions & 93 deletions metricflow/configuration/env_var.py

This file was deleted.

12 changes: 9 additions & 3 deletions metricflow/test/fixtures/setup_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from _pytest.fixtures import FixtureRequest
from sqlalchemy.engine import make_url

from metricflow.configuration.env_var import EnvironmentVariable
from metricflow.random_id import random_id
from metricflow.test.fixtures.sql_clients.common_client import SqlDialect
from metricflow.test.table_snapshot.table_snapshots import SqlTableSnapshotHash, SqlTableSnapshotRepository
Expand Down Expand Up @@ -154,8 +153,15 @@ def warn_user_about_slow_tests_without_parallelism( # noqa: D
request: FixtureRequest,
mf_test_session_state: MetricFlowTestSessionState,
) -> None:
worker_count_env_var = EnvironmentVariable("PYTEST_XDIST_WORKER_COUNT", "1")
num_workers = worker_count_env_var.get_int()
worker_count_env_var = os.environ.get("PYTEST_XDIST_WORKER_COUNT", "1")
try:
num_workers = int(worker_count_env_var)
except ValueError as e:
raise ValueError(
f"Could not convert environment variable PYTEST_XDIST_WORKER_COUNT to int! "
f"Value in environ was: {worker_count_env_var}"
) from e

num_items = len(request.session.items)
dialect = dialect_from_url(mf_test_session_state.sql_engine_url)

Expand Down
10 changes: 4 additions & 6 deletions metricflow/test/generate_snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
from dbt_semantic_interfaces.implementations.base import FrozenBaseModel
from dbt_semantic_interfaces.pretty_print import pformat_big_objects

from metricflow.configuration.env_var import EnvironmentVariable
from metricflow.protocols.sql_client import SqlEngine

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -162,15 +161,14 @@ def run_cli() -> None: # noqa: D
dev_format = "%(asctime)s %(levelname)s %(filename)s:%(lineno)d [%(threadName)s] - %(message)s"
logging.basicConfig(level=logging.INFO, format=dev_format)

credential_sets_json_env_var = EnvironmentVariable("MF_TEST_ENGINE_CREDENTIAL_SETS")
if credential_sets_json_env_var.get_optional() is None:
credential_sets_json_str = os.environ.get("MF_TEST_ENGINE_CREDENTIAL_SETS")
if credential_sets_json_str is None:
raise ValueError(
f"Environment variable: {credential_sets_json_env_var.name} has not been set. Please see the comment in "
f"Environment variable: MF_TEST_ENGINE_CREDENTIAL_SETS has not been set. Please see the comment in "
f"{__file__} for details on how to set it."
)

credentials_sets_json_str = credential_sets_json_env_var.get()
credential_sets = MetricFlowTestCredentialSetForAllEngines.parse_raw(credentials_sets_json_str)
credential_sets = MetricFlowTestCredentialSetForAllEngines.parse_raw(credential_sets_json_str)

logger.info(
f"Running the following tests to generate snapshots:\n{pformat_big_objects(SNAPSHOT_GENERATING_TEST_FILES)}"
Expand Down

0 comments on commit b8f190a

Please sign in to comment.