Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] CLI Parameter for packages-install-path #9933

Closed
wants to merge 2 commits into from
Closed
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
6 changes: 6 additions & 0 deletions .changes/unreleased/Features-20240413-093017.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Features
body: Add cli parameter for packages-install-path
time: 2024-04-13T09:30:17.83824+01:00
custom:
Author: stevenayers
Issue: "9932"
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
7 changes: 7 additions & 0 deletions core/dbt/cli/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,13 @@
type=click.Path(),
)

packages_install_path = click.option(
"--packages-install-path",
envvar="DBT_PACKAGES_INSTALL_PATH",
help="Configure the 'packages-install-path'. Only applies this setting for the current run. Overrides the 'DBT_PACKAGES_INSTALL_PATH' if it is set.",
type=click.Path(),
)

upgrade = click.option(
"--upgrade",
envvar=None,
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
1 change: 1 addition & 0 deletions core/dbt/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def get_flag_dict():
"cache_selected_only",
"introspect",
"target_path",
"packages_install_path",
"log_path",
"invocation_command",
}
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()