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

Profiling and Adapter management work with Click #5892

Merged
merged 27 commits into from
Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
ef914a0
CLI modeling RAT, commands and global params
iknox-fa Jul 15, 2022
4476158
pretty output
iknox-fa Jul 15, 2022
3d36e8a
updates
iknox-fa Jul 19, 2022
03af445
added multi-flag example and a custom type
iknox-fa Jul 19, 2022
8279d5a
Merge branch 'main' into iknox-CT-295-cli-modeling-RAT
iknox-fa Aug 3, 2022
b04021d
Merge branch 'main' into iknox-CT-295-cli-modeling-RAT
iknox-fa Aug 4, 2022
83f84ef
feature complete
iknox-fa Aug 11, 2022
61650ca
consolidate params
iknox-fa Aug 11, 2022
4214726
tests
iknox-fa Aug 11, 2022
95e36c3
Auto-env-var approach
iknox-fa Aug 23, 2022
cac3e24
mostly complete
iknox-fa Sep 7, 2022
1571a43
more tests, alpha-order params
iknox-fa Sep 7, 2022
562cf41
nm about that alias... nothing to see here
iknox-fa Sep 7, 2022
5fe9390
removed un-needed defaults
iknox-fa Sep 7, 2022
baf4e4a
fixed WHICH flag, updated bad or un-needed defaults
iknox-fa Sep 7, 2022
a4efd79
changelog
iknox-fa Sep 8, 2022
ee4dd24
PR feedback
iknox-fa Sep 8, 2022
9bc6cc1
PR feedback
iknox-fa Sep 8, 2022
a73d274
updates for aliasing ls
iknox-fa Sep 9, 2022
899712e
made module runnable, removed entrypoint for now
iknox-fa Sep 9, 2022
1bee3a8
PR feedback
iknox-fa Sep 9, 2022
a61fa68
PR feedback
iknox-fa Sep 9, 2022
ce203be
removed ls TODO
iknox-fa Sep 9, 2022
ec69846
profiling and adapter management
iknox-fa Sep 20, 2022
2db5ff9
Merge branch 'main' into iknox/CT-907-profiling-works-with-click
iknox-fa Sep 20, 2022
339c079
changelog
iknox-fa Sep 20, 2022
623ba63
Update help text
iknox-fa Sep 20, 2022
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
7 changes: 7 additions & 0 deletions .changes/unreleased/Under the Hood-20220920-144842.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: Under the Hood
body: Profiling and Adapter Management work with Click CLI
time: 2022-09-20T14:48:42.070256-05:00
custom:
Author: iknox-fa
Issue: "5531"
PR: "5892"
33 changes: 18 additions & 15 deletions core/dbt/adapters/factory.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
import threading
from pathlib import Path
from contextlib import contextmanager
Copy link
Contributor Author

@iknox-fa iknox-fa Sep 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only new import. All of the rest of the changes are from using isort to correctly sort the imports which wasn't done before.

#leaveitbetter

from importlib import import_module
from typing import Type, Dict, Any, List, Optional, Set
from pathlib import Path
from typing import Any, Dict, List, Optional, Set, Type

from dbt.exceptions import RuntimeException, InternalException
from dbt.include.global_project import (
PACKAGE_PATH as GLOBAL_PROJECT_PATH,
PROJECT_NAME as GLOBAL_PROJECT_NAME,
)
from dbt.adapters.base.plugin import AdapterPlugin
from dbt.adapters.protocol import AdapterConfig, AdapterProtocol, RelationProtocol
from dbt.contracts.connection import AdapterRequiredConfig, Credentials
from dbt.events.functions import fire_event
from dbt.events.types import AdapterImportError, PluginLoadError
from dbt.contracts.connection import Credentials, AdapterRequiredConfig
from dbt.adapters.protocol import (
AdapterProtocol,
AdapterConfig,
RelationProtocol,
)
from dbt.adapters.base.plugin import AdapterPlugin

from dbt.exceptions import InternalException, RuntimeException
from dbt.include.global_project import PACKAGE_PATH as GLOBAL_PROJECT_PATH
from dbt.include.global_project import PROJECT_NAME as GLOBAL_PROJECT_NAME

Adapter = AdapterProtocol

Expand Down Expand Up @@ -217,3 +211,12 @@ def get_adapter_package_names(name: Optional[str]) -> List[str]:

def get_adapter_type_names(name: Optional[str]) -> List[str]:
return FACTORY.get_adapter_type_names(name)


@contextmanager
def adapter_management():
reset_adapters()
try:
yield
finally:
cleanup_connections()
17 changes: 14 additions & 3 deletions core/dbt/cli/main.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import inspect # This is temporary for RAT-ing
import sys
from copy import copy
from pprint import pformat as pf # This is temporary for RAT-ing

import click
from dbt.adapters.factory import adapter_management
from dbt.cli import params as p
from dbt.cli.flags import Flags
from dbt.profiler import profiler


def cli_runner():
Expand Down Expand Up @@ -51,9 +52,19 @@ 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
"""
if kwargs.get("version", False):
incomplete_flags = Flags()

# Profiling
if incomplete_flags.RECORD_TIMING_INFO:
ctx.with_resource(profiler(enable=True, outfile=incomplete_flags.RECORD_TIMING_INFO))

# Adapter management
ctx.with_resource(adapter_management())

# Version info
if incomplete_flags.VERSION:
click.echo(f"`version` called\n ctx.params: {pf(ctx.params)}")
sys.exit()
return
else:
del ctx.params["version"]

Expand Down
12 changes: 7 additions & 5 deletions core/dbt/cli/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,16 +218,18 @@
"--profiles-dir",
envvar="DBT_PROFILES_DIR",
help="Which directory to look in for the profiles.yml file. If not set, dbt will look in the current working directory first, then HOME/.dbt/",
default=None,
type=click.Path(),
default=PurePath.joinpath(Path.home(), ".dbt"),
type=click.Path(
exists=True,
),
)

project_dir = click.option(
"--project-dir",
envvar=None,
help="Which directory to look in for the dbt_project.yml file. Default is the current working directory and its parents.",
default=None,
type=click.Path(),
default=Path.cwd(),
type=click.Path(exists=True),
)

quiet = click.option(
Expand All @@ -241,7 +243,7 @@
"-r",
envvar=None,
help="When this option is passed, dbt will output low-level timing stats to the specified file. Example: `--record-timing-info output.profile`",
is_flag=True,
type=click.Path(exists=False),
)

resource_type = click.option(
Expand Down