From 6e0a38720529360d061bd4e24e140f5ec55f8c15 Mon Sep 17 00:00:00 2001 From: Jeremy Cohen Date: Mon, 11 Dec 2023 19:11:12 +0100 Subject: [PATCH] Remove `--dry-run` flag from `dbt deps` (#9169) * Rm --dry-run flag for dbt deps * Add changelog entry * Update test * PR feedback --- .changes/unreleased/Breaking Changes-20231129-091921.yaml | 7 +++++++ core/dbt/cli/main.py | 7 ------- core/dbt/cli/params.py | 7 ------- core/dbt/task/deps.py | 5 +++-- tests/functional/dependencies/test_dependency_options.py | 4 ++-- 5 files changed, 12 insertions(+), 18 deletions(-) create mode 100644 .changes/unreleased/Breaking Changes-20231129-091921.yaml diff --git a/.changes/unreleased/Breaking Changes-20231129-091921.yaml b/.changes/unreleased/Breaking Changes-20231129-091921.yaml new file mode 100644 index 00000000000..c58c598a46e --- /dev/null +++ b/.changes/unreleased/Breaking Changes-20231129-091921.yaml @@ -0,0 +1,7 @@ +kind: Breaking Changes +body: Rm --dry-run flag from 'dbt deps --add-package', in favor of just 'dbt deps + --lock' +time: 2023-11-29T09:19:21.071212+01:00 +custom: + Author: jtcohen6 + Issue: "9100" diff --git a/core/dbt/cli/main.py b/core/dbt/cli/main.py index 2454a15a564..61ff8d03773 100644 --- a/core/dbt/cli/main.py +++ b/core/dbt/cli/main.py @@ -457,7 +457,6 @@ def debug(ctx, **kwargs): @p.target @p.vars @p.source -@p.dry_run @p.lock @p.upgrade @p.add_package @@ -483,12 +482,6 @@ def deps(ctx, **kwargs): message=f"Version is required in --add-package when a package when source is {flags.SOURCE}", option_name="--add-package", ) - else: - if flags.DRY_RUN: - raise BadOptionUsage( - message="Invalid flag `--dry-run` when not using `--add-package`.", - option_name="--dry-run", - ) task = DepsTask(flags, ctx.obj["project"]) results = task.run() success = task.interpret_results(results) diff --git a/core/dbt/cli/params.py b/core/dbt/cli/params.py index 907f485f3b3..3e03376f890 100644 --- a/core/dbt/cli/params.py +++ b/core/dbt/cli/params.py @@ -83,13 +83,6 @@ hidden=True, ) -dry_run = click.option( - "--dry-run", - envvar=None, - help="Option to run `dbt deps --add-package` without updating package-lock.yml file.", - is_flag=True, -) - empty = click.option( "--empty/--no-empty", envvar="DBT_EMPTY", diff --git a/core/dbt/task/deps.py b/core/dbt/task/deps.py index a694f78dac5..54ec0db4e1f 100644 --- a/core/dbt/task/deps.py +++ b/core/dbt/task/deps.py @@ -220,8 +220,9 @@ def run(self) -> None: if previous_hash != current_hash: self.lock() - # Early return when dry run or lock only. - if self.args.dry_run or self.args.lock: + # Early return when 'dbt deps --lock' + # Just resolve packages and write lock file, don't actually install packages + if self.args.lock: return if system.path_exists(self.project.packages_install_path): diff --git a/tests/functional/dependencies/test_dependency_options.py b/tests/functional/dependencies/test_dependency_options.py index 5ddc243bf37..a6a200bf3d5 100644 --- a/tests/functional/dependencies/test_dependency_options.py +++ b/tests/functional/dependencies/test_dependency_options.py @@ -75,14 +75,14 @@ def test_deps_add(self, clean_start): ) assert len(os.listdir("dbt_packages")) == 3 - def test_deps_add_dry_run(self, clean_start): + def test_deps_add_without_install(self, clean_start): os.rename("packages.yml", "dependencies.yml") run_dbt( [ "deps", "--add-package", "dbt-labs/audit_helper@0.9.0", - "--dry-run", + "--lock", ] ) assert not os.path.exists("dbt_packages")