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

Implement --version in click #6760

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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/Under the Hood-20230126-143102.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Under the Hood
body: Implement --version for click cli
time: 2023-01-26T14:31:02.740282-06:00
custom:
Author: stu-k
Issue: "6757"
4 changes: 1 addition & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ jobs:
mypy --version
python -m pip install -r requirements.txt
python -m pip install -r dev-requirements.txt
# Running version disabled temporarily because version isn't implemented on this branch
# Please un-comment it when GH #6757 / CT-1926 is complete
#dbt --version
dbt --version

- name: Run pre-commit hooks
run: pre-commit run --all-files --show-diff-on-failure
Expand Down
4 changes: 0 additions & 4 deletions core/dbt/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,6 @@ def cli(ctx, **kwargs):
"""An ELT tool for managing your SQL transformations and data models.
For more documentation on these commands, visit: docs.getdbt.com
"""
# Version info
if ctx.params["version"]:
click.echo(f"`version` called\n ctx.params: {pf(ctx.params)}")
return


# dbt build
Expand Down
11 changes: 11 additions & 0 deletions core/dbt/cli/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from dbt.cli.options import MultiOption
from dbt.cli.option_types import YAML, ChoiceTuple, WarnErrorOptionsType
from dbt.cli.resolvers import default_project_dir, default_profiles_dir
from dbt.version import get_version_information


# TODO: The name (reflected in flags) is a correction!
Expand Down Expand Up @@ -373,10 +374,20 @@
default="{}",
)


def version_callback(ctx, param, value):
stu-k marked this conversation as resolved.
Show resolved Hide resolved
if not value or ctx.resilient_parsing:
return
click.echo(get_version_information())
ctx.exit()


version = click.option(
"--version",
callback=version_callback,
envvar=None,
help="Show version information",
is_eager=True,
is_flag=True,
)

Expand Down
Binary file modified core/dbt/docs/build/doctrees/environment.pickle
Binary file not shown.
Binary file modified core/dbt/docs/build/doctrees/index.doctree
Binary file not shown.
10 changes: 5 additions & 5 deletions core/dbt/docs/build/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ <h4>full_refresh<a class="headerlink" href="#build|full_refresh" title="Permalin
</section>
<section id="build|indirect_selection">
<h4>indirect_selection<a class="headerlink" href="#build|indirect_selection" title="Permalink to this heading">¶</a></h4>
<p>Type: choice: [‘eager’, ‘cautious’]</p>
<p>Type: choice: [‘eager’, ‘cautious’, ‘buildable’]</p>
<p>Select all tests that are adjacent to selected resources, even if they those resources have been explicitly selected.</p>
</section>
<section id="build|profile">
Expand Down Expand Up @@ -349,7 +349,7 @@ <h4>project_dir<a class="headerlink" href="#init|project_dir" title="Permalink t
<section id="init|skip_profile_setup">
<h4>skip_profile_setup<a class="headerlink" href="#init|skip_profile_setup" title="Permalink to this heading">¶</a></h4>
<p>Type: boolean</p>
<p>Skip interative profile setup.</p>
<p>Skip interactive profile setup.</p>
</section>
<section id="init|target">
<h4>target<a class="headerlink" href="#init|target" title="Permalink to this heading">¶</a></h4>
Expand All @@ -369,7 +369,7 @@ <h4>exclude<a class="headerlink" href="#list|exclude" title="Permalink to this h
</section>
<section id="list|indirect_selection">
<h4>indirect_selection<a class="headerlink" href="#list|indirect_selection" title="Permalink to this heading">¶</a></h4>
<p>Type: choice: [‘eager’, ‘cautious’]</p>
<p>Type: choice: [‘eager’, ‘cautious’, ‘buildable’]</p>
<p>Select all tests that are adjacent to selected resources, even if they those resources have been explicitly selected.</p>
</section>
<section id="list|models">
Expand Down Expand Up @@ -440,7 +440,7 @@ <h4>exclude<a class="headerlink" href="#list|exclude" title="Permalink to this h
</section>
<section id="list|indirect_selection">
<h4>indirect_selection<a class="headerlink" href="#list|indirect_selection" title="Permalink to this heading">¶</a></h4>
<p>Type: choice: [‘eager’, ‘cautious’]</p>
<p>Type: choice: [‘eager’, ‘cautious’, ‘buildable’]</p>
<p>Select all tests that are adjacent to selected resources, even if they those resources have been explicitly selected.</p>
</section>
<section id="list|models">
Expand Down Expand Up @@ -826,7 +826,7 @@ <h4>fail_fast<a class="headerlink" href="#test|fail_fast" title="Permalink to th
</section>
<section id="test|indirect_selection">
<h4>indirect_selection<a class="headerlink" href="#test|indirect_selection" title="Permalink to this heading">¶</a></h4>
<p>Type: choice: [‘eager’, ‘cautious’]</p>
<p>Type: choice: [‘eager’, ‘cautious’, ‘buildable’]</p>
<p>Select all tests that are adjacent to selected resources, even if they those resources have been explicitly selected.</p>
</section>
<section id="test|models">
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/docs/build/html/searchindex.js

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion tests/unit/test_dbt_runner.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import pytest

import click.exceptions

from dbt.cli.main import dbtRunner, dbtUsageException


Expand All @@ -21,4 +23,8 @@ def test_invalid_command(self, dbt: dbtRunner) -> None:
dbt.invoke(["invalid-command"])

def test_invoke_version(self, dbt: dbtRunner) -> None:
dbt.invoke(["--version"])
try:
dbt.invoke(["--version"])
stu-k marked this conversation as resolved.
Show resolved Hide resolved
# click exits early for version, this is intended
except click.exceptions.Exit:
return
stu-k marked this conversation as resolved.
Show resolved Hide resolved