Skip to content

Commit

Permalink
[Feature] CLI Parameter for packages-install-path
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenayers committed Apr 14, 2024
1 parent a4081e1 commit 76cc80d
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 2 deletions.
1 change: 1 addition & 0 deletions core/dbt/cli/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
FLAGS_DEFAULTS = {
"INDIRECT_SELECTION": "eager",
"TARGET_PATH": None,
"PACKAGES_INSTALL_PATH": None,
"DEFER_STATE": None, # necessary because of retry construction of flags
"WARN_ERROR": None,
# Cli args without project_flags or env var option.
Expand Down
17 changes: 17 additions & 0 deletions core/dbt/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ def cli(ctx, **kwargs):
@p.show
@p.store_failures
@p.target_path
@p.packages_install_path
@p.threads
@p.vars
@requires.postflight
Expand Down Expand Up @@ -214,6 +215,7 @@ def build(ctx, **kwargs):
@p.profiles_dir
@p.project_dir
@p.target_path
@p.packages_install_path
@p.vars
@requires.postflight
@requires.preflight
Expand Down Expand Up @@ -251,6 +253,7 @@ def docs(ctx, **kwargs):
@p.empty_catalog
@p.static
@p.target_path
@p.packages_install_path
@p.threads
@p.vars
@requires.postflight
Expand Down Expand Up @@ -283,6 +286,7 @@ def docs_generate(ctx, **kwargs):
@p.profiles_dir
@p.project_dir
@p.target_path
@p.packages_install_path
@p.vars
@requires.postflight
@requires.preflight
Expand Down Expand Up @@ -319,6 +323,7 @@ def docs_serve(ctx, **kwargs):
@p.inline
@p.compile_inject_ephemeral_ctes
@p.target_path
@p.packages_install_path
@p.threads
@p.vars
@requires.postflight
Expand Down Expand Up @@ -358,6 +363,7 @@ def compile(ctx, **kwargs):
@p.selector
@p.inline
@p.target_path
@p.packages_install_path
@p.threads
@p.vars
@requires.postflight
Expand Down Expand Up @@ -417,6 +423,7 @@ def debug(ctx, **kwargs):
@p.lock
@p.upgrade
@p.add_package
@p.packages_install_path
@requires.postflight
@requires.preflight
@requires.unset_profile
Expand Down Expand Up @@ -485,6 +492,7 @@ def init(ctx, **kwargs):
@p.raw_select
@p.selector
@p.target_path
@p.packages_install_path
@p.vars
@requires.postflight
@requires.preflight
Expand Down Expand Up @@ -520,6 +528,7 @@ def list(ctx, **kwargs):
@p.profiles_dir
@p.project_dir
@p.target_path
@p.packages_install_path
@p.threads
@p.vars
@requires.postflight
Expand All @@ -546,6 +555,7 @@ def parse(ctx, **kwargs):
@p.select
@p.selector
@p.target_path
@p.packages_install_path
@p.threads
@p.vars
@requires.postflight
Expand Down Expand Up @@ -577,6 +587,7 @@ def run(ctx, **kwargs):
@p.profiles_dir
@p.vars
@p.target_path
@p.packages_install_path
@p.threads
@p.full_refresh
@requires.postflight
Expand Down Expand Up @@ -612,6 +623,7 @@ def retry(ctx, **kwargs):
@p.select
@p.selector
@p.target_path
@p.packages_install_path
@p.threads
@p.vars
@requires.preflight
Expand Down Expand Up @@ -644,6 +656,7 @@ def clone(ctx, **kwargs):
@p.profiles_dir
@p.project_dir
@p.target_path
@p.packages_install_path
@p.threads
@p.vars
@requires.postflight
Expand Down Expand Up @@ -679,6 +692,7 @@ def run_operation(ctx, **kwargs):
@p.selector
@p.show
@p.target_path
@p.packages_install_path
@p.threads
@p.vars
@requires.postflight
Expand Down Expand Up @@ -711,6 +725,7 @@ def seed(ctx, **kwargs):
@p.select
@p.selector
@p.target_path
@p.packages_install_path
@p.threads
@p.vars
@requires.postflight
Expand Down Expand Up @@ -753,6 +768,7 @@ def source(ctx, **kwargs):
@p.select
@p.selector
@p.target_path
@p.packages_install_path
@p.threads
@p.vars
@requires.postflight
Expand Down Expand Up @@ -793,6 +809,7 @@ def freshness(ctx, **kwargs):
@p.selector
@p.store_failures
@p.target_path
@p.packages_install_path
@p.threads
@p.vars
@requires.postflight
Expand Down
8 changes: 7 additions & 1 deletion core/dbt/config/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,13 @@ def create_project(self, rendered: RenderComponents) -> "Project":
log_path: str = str(global_flags.LOG_PATH)

clean_targets: List[str] = value_or(cfg.clean_targets, [target_path])
packages_install_path: str = value_or(cfg.packages_install_path, "dbt_packages")

flag_packages_install_path = (
str(global_flags.PACKAGES_INSTALL_PATH) if global_flags.PACKAGES_INSTALL_PATH else None
)
packages_install_path: str = flag_or(
flag_packages_install_path, cfg.packages_install_path, "dbt_packages"
)
# in the default case we'll populate this once we know the adapter type
# It would be nice to just pass along a Quoting here, but that would
# break many things
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def get_flag_dict():
"cache_selected_only",
"introspect",
"target_path",
"log_path",
"packages_install_path" "log_path",
"invocation_command",
}
return {key: getattr(GLOBAL_FLAGS, key.upper(), None) for key in flag_attr}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from pathlib import Path

import pytest

from dbt.tests.util import run_dbt


class TestPackagesInstallPathConfig:
@pytest.fixture(scope="class")
def packages(self):
return {
"packages": [
{
"package": "fivetran/fivetran_utils",
"version": "0.4.7",
},
]
}

@pytest.fixture(scope="class")
def project_config_update(self):
return {"config-version": 2, "packages-install-path": "project_dbt_packages"}

def test_packages_install_path(self, project):
run_dbt(["deps"])
assert Path("project_dbt_packages").is_dir()
assert not Path("dbt_packages").is_dir()


class TestPackagesInstallPathEnvVar:
def test_packages_install_path(self, project, monkeypatch):
monkeypatch.setenv("DBT_PACKAGES_INSTALL_PATH", "env_dbt_packages")
run_dbt(["deps"])
assert Path("env_dbt_packages").is_dir()
assert not Path("project_dbt_packages").is_dir()
assert not Path("dbt_packages").is_dir()


class TestPackagesInstallPathCliArg:
def test_packages_install_path(self, project, monkeypatch):
monkeypatch.setenv("DBT_PACKAGES_INSTALL_PATH", "env_dbt_packages")
run_dbt(["deps", "--packages-install-path", "cli_dbt_packages"])
assert Path("cli_dbt_packages").is_dir()
assert not Path("env_dbt_packages").is_dir()
assert not Path("project_dbt_packages").is_dir()
assert not Path("dbt_packages").is_dir()

0 comments on commit 76cc80d

Please sign in to comment.