Skip to content

Commit

Permalink
🎨 [pre-commit.ci] Auto format from pre-commit.com hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci[bot] committed Oct 18, 2023
1 parent 7ae8fd9 commit 64c4b93
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion cosmos/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ class ExecutionConfig:
available on the path.
:param virtualenv_dir: Directory path to locate the (cached) virtual env that should be used for execution when execution mode is set to `ExecutionMode.VIRTUALENV`
"""

execution_mode: ExecutionMode = ExecutionMode.LOCAL
dbt_executable_path: str | Path = get_system_dbt()
virtualenv_dir: str | Path | None = None

10 changes: 6 additions & 4 deletions cosmos/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,10 @@ def __init__(
dbt_executable_path = execution_config.dbt_executable_path
node_converters = render_config.node_converters

if (execution_mode != ExecutionMode.VIRTUALENV and execution_config.virtualenv_dir is not None):
logger.warning("`ExecutionConfig.virtualenv_dir` is only supported when ExecutionConfig.execution_mode is set to ExecutionMode.VIRTUALENV.")
if execution_mode != ExecutionMode.VIRTUALENV and execution_config.virtualenv_dir is not None:
logger.warning(
"`ExecutionConfig.virtualenv_dir` is only supported when ExecutionConfig.execution_mode is set to ExecutionMode.VIRTUALENV."
)

profile_args = {}
if profile_config.profile_mapping:
Expand Down Expand Up @@ -159,9 +161,9 @@ def __init__(
"emit_datasets": emit_datasets,
}

if (execution_mode == ExecutionMode.VIRTUALENV and execution_config.virtualenv_dir is not None):
if execution_mode == ExecutionMode.VIRTUALENV and execution_config.virtualenv_dir is not None:
task_args["virtualenv_dir"] = execution_config.virtualenv_dir

if dbt_executable_path:
task_args["dbt_executable_path"] = dbt_executable_path

Expand Down
7 changes: 3 additions & 4 deletions cosmos/operators/virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,14 @@ def _get_or_create_venv_py_interpreter(self) -> str:

self.log.info(f"Checking for venv interpreter: {py_interpreter_path} : {py_interpreter_path.is_file()}")
if py_interpreter_path.is_file():

self.log.info(f"Found Python interpreter in cached virtualenv: `{str(py_interpreter_path)}`")
return str(py_interpreter_path)

self.log.info(f"Creating virtualenv at `{self._venv_dir}")
venv_directory = self._venv_dir

else:
self.log.info(f"Creating temporary virtualenv")
self.log.info("Creating temporary virtualenv")
self._venv_tmp_dir = TemporaryDirectory(prefix="cosmos-venv")
venv_directory = self._venv_tmp_dir.name

Expand Down
5 changes: 2 additions & 3 deletions dev/dags/example_virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import os
from datetime import datetime
from pathlib import Path
from airflow.configuration import get_airflow_home

from cosmos import DbtDag, ExecutionMode, ExecutionConfig, ProjectConfig, ProfileConfig
from cosmos.profiles import PostgresUserPasswordProfileMapping
Expand All @@ -31,9 +30,9 @@
profile_config=profile_config,
execution_config=ExecutionConfig(
execution_mode=ExecutionMode.VIRTUALENV,
# We can enable this flag if we want Airflow to create one virtualenv
# We can enable this flag if we want Airflow to create one virtualenv
# and re-use that within the whole DAG.
# virtualenv_dir=f"{get_airflow_home()}/persistent-venv",
# virtualenv_dir=f"{get_airflow_home()}/persistent-venv",
),
operator_args={
"py_system_site_packages": False,
Expand Down

0 comments on commit 64c4b93

Please sign in to comment.