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

Deps lock by justbldwn #8408

Merged
merged 31 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
5261bfe
:sparkles: adding installed_packages.json functionality
justbldwn Jan 25, 2023
5507a0e
:white_check_mark: update test_simple_dependency_deps test
justbldwn Jan 25, 2023
f0cf216
:memo: adding changelog for deps feature via changie
justbldwn Jan 25, 2023
8ae24e4
:sparkles: restructure deps command, include lock/add
justbldwn Feb 10, 2023
94d208f
:white_check_mark: add new deps event types to sample_values
justbldwn Feb 10, 2023
948d400
:white_check_mark: fix test_simple_dependency_deps test
justbldwn Feb 10, 2023
93f72f4
:twisted_rightwards_arrows: merging changes with latest on main
justbldwn Feb 10, 2023
a3df280
:bug: attempting to fix cli commands
justbldwn Feb 10, 2023
0e01c2e
:bug: convert dbt deps to dbt deps install
justbldwn Feb 10, 2023
9995193
:white_check_mark: update test_command_mutually_exclusive_option
justbldwn Feb 10, 2023
e182821
:white_check_mark: update functional tests from deps > deps install
justbldwn Feb 10, 2023
5615910
:white_check_mark: change missing deps to deps install
justbldwn Feb 10, 2023
5eb279f
:white_check_mark: convert adapter tests to deps install from deps
justbldwn Feb 10, 2023
e608586
add proto def
ChenyuLInx Aug 14, 2023
23959f4
move back to deps and merge more with main
ChenyuLInx Aug 15, 2023
f46aaef
fix-unittest
ChenyuLInx Aug 16, 2023
56fc2d3
add hash
ChenyuLInx Aug 16, 2023
7cc1d46
foramt yml and update command structure
ChenyuLInx Aug 18, 2023
96ba8ef
nits
ChenyuLInx Aug 21, 2023
f1da3e6
add new param
ChenyuLInx Aug 21, 2023
9e5017f
nits
ChenyuLInx Aug 21, 2023
3d9ae41
nits
ChenyuLInx Aug 22, 2023
80e1837
nits
ChenyuLInx Aug 22, 2023
ae8ad1f
Merge branch 'main' into deps_lock_by_justbldwn
ChenyuLInx Oct 4, 2023
cc5611a
fix_tests
ChenyuLInx Oct 4, 2023
4a5c15f
pr_feedback
ChenyuLInx Oct 9, 2023
d312b09
nits
ChenyuLInx Oct 9, 2023
0ebb1ac
nits
ChenyuLInx Oct 9, 2023
22f917d
move_check
ChenyuLInx Oct 9, 2023
ee1abb2
Merge branch 'main' into deps_lock_by_justbldwn
ChenyuLInx Oct 9, 2023
5676771
Update Features-20230125-165933.yaml
ChenyuLInx Oct 10, 2023
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-20230125-165933.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Features
body: add log file of installed packages via dbt deps
time: 2023-01-25T16:59:33.786304-05:00
custom:
Author: jusbaldw
Issue: "6643"
17 changes: 15 additions & 2 deletions core/dbt/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,12 +453,26 @@ def debug(ctx, **kwargs):
@p.project_dir
@p.target
@p.vars
@p.source
@p.dry_run
@p.lock
@p.upgrade
@p.add_package
@requires.postflight
@requires.preflight
@requires.unset_profile
@requires.project
def deps(ctx, **kwargs):
"""Pull the most recent version of the dependencies listed in packages.yml"""
"""Install dbt packages specified.
In the following case, a new `package-lock.yml` will be generated and the packages are installed:
- user updated the packages.yml
- user specify the flag --update, which means for packages that are specified as a
range, dbt-core will try to install the newer version
Otherwise, deps will use `package-lock.yml` as source of truth to install packages.

There is a way to add new packages by providing an `--add-package` flag to deps command
which will allow user to specify a package they want to add in the format of packagename@version.
"""
task = DepsTask(ctx.obj["flags"], ctx.obj["project"])
results = task.run()
success = task.interpret_results(results)
Expand Down Expand Up @@ -554,7 +568,6 @@ def list(ctx, **kwargs):
def parse(ctx, **kwargs):
"""Parses the project and provides information on performance"""
# manifest generation and writing happens in @requires.manifest

return ctx.obj["manifest"], True


Expand Down
20 changes: 20 additions & 0 deletions core/dbt/cli/option_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,26 @@ def convert(self, value, param, ctx):
self.fail(f"String '{value}' is not valid YAML", param, ctx)


class Package(ParamType):
"""The Click STRING type. Converts string into dict with package name and version.
Example package:
package-name@1.0.0
package-name
"""

name = "NewPackage"

def convert(self, value, param, ctx):
# assume non-string values are a problem
if not isinstance(value, str):
self.fail(f"Cannot load Package from type {type(value)}", param, ctx)
try:
package_name, package_version = value.split("@")
return {"name": package_name, "version": package_version}
except ValueError:
return {"name": value, "version": None}


class WarnErrorOptionsType(YAML):
"""The Click WarnErrorOptions type. Converts YAML strings into objects."""

Expand Down
39 changes: 38 additions & 1 deletion core/dbt/cli/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@

import click
from dbt.cli.options import MultiOption
from dbt.cli.option_types import YAML, ChoiceTuple, WarnErrorOptionsType
from dbt.cli.option_types import YAML, ChoiceTuple, WarnErrorOptionsType, Package
from dbt.cli.resolvers import default_project_dir, default_profiles_dir
from dbt.version import get_version_information

add_package = click.option(
"--add-package",
help="Add a package to current package spec, specify it as package-name@version. Change the source with --source flag.",
envvar=None,
type=Package(),
)
args = click.option(
"--args",
envvar=None,
Expand Down Expand Up @@ -77,6 +83,14 @@
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,
)


enable_legacy_logger = click.option(
"--enable-legacy-logger/--no-enable-legacy-logger",
envvar="DBT_ENABLE_LEGACY_LOGGER",
Expand Down Expand Up @@ -127,6 +141,13 @@
default="eager",
)

lock = click.option(
"--lock",
envvar=None,
help="Generate the package-lock.yml file without install the packages.",
is_flag=True,
)

log_cache_events = click.option(
"--log-cache-events/--no-log-cache-events",
help="Enable verbose logging for relational cache events to help when debugging.",
Expand Down Expand Up @@ -465,6 +486,15 @@
is_flag=True,
)

source = click.option(
"--source",
envvar=None,
help="Source to download page from, must be one of hub, git, or local. Defaults to hub.",
type=click.Choice(["hub", "git", "local"], case_sensitive=True),
default="hub",
)


state = click.option(
"--state",
envvar="DBT_STATE",
Expand Down Expand Up @@ -533,6 +563,13 @@
type=click.Path(),
)

upgrade = click.option(
"--upgrade",
envvar=None,
help="Upgrade packages to the latest version.",
is_flag=True,
)

debug_connection = click.option(
"--connection",
envvar=None,
Expand Down
28 changes: 18 additions & 10 deletions core/dbt/config/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@

from dbt.flags import get_flags
from dbt import deprecations
from dbt.constants import DEPENDENCIES_FILE_NAME, PACKAGES_FILE_NAME
from dbt.clients.system import path_exists, resolve_path_from_base, load_file_contents
from dbt.constants import (
DEPENDENCIES_FILE_NAME,
PACKAGES_FILE_NAME,
PACKAGE_LOCK_HASH_KEY,
)
from dbt.clients.system import path_exists, load_file_contents
from dbt.clients.yaml_helper import load_yaml_text
from dbt.contracts.connection import QueryComment
from dbt.exceptions import (
Expand Down Expand Up @@ -94,16 +98,17 @@ def _load_yaml(path):
return load_yaml_text(contents)


def load_yml_dict(file_path):
ret = {}
if path_exists(file_path):
ret = _load_yaml(file_path) or {}
return ret


def package_and_project_data_from_root(project_root):
package_filepath = resolve_path_from_base(PACKAGES_FILE_NAME, project_root)
dependencies_filepath = resolve_path_from_base(DEPENDENCIES_FILE_NAME, project_root)

packages_yml_dict = {}
dependencies_yml_dict = {}
if path_exists(package_filepath):
packages_yml_dict = _load_yaml(package_filepath) or {}
if path_exists(dependencies_filepath):
dependencies_yml_dict = _load_yaml(dependencies_filepath) or {}
packages_yml_dict = load_yml_dict(f"{project_root}/{PACKAGES_FILE_NAME}")
dependencies_yml_dict = load_yml_dict(f"{project_root}/{DEPENDENCIES_FILE_NAME}")

if "packages" in packages_yml_dict and "packages" in dependencies_yml_dict:
msg = "The 'packages' key cannot be specified in both packages.yml and dependencies.yml"
Expand All @@ -127,6 +132,8 @@ def package_config_from_data(packages_data: Dict[str, Any]) -> PackageConfig:
if not packages_data:
packages_data = {"packages": []}

if PACKAGE_LOCK_HASH_KEY in packages_data:
packages_data.pop(PACKAGE_LOCK_HASH_KEY)
try:
PackageConfig.validate(packages_data)
packages = PackageConfig.from_dict(packages_data)
Expand Down Expand Up @@ -548,6 +555,7 @@ def from_project_root(
packages_specified_path,
) = package_and_project_data_from_root(project_root)
selectors_dict = selector_data_from_root(project_root)

return cls.from_dicts(
project_root=project_root,
project_dict=project_dict,
Expand Down
2 changes: 2 additions & 0 deletions core/dbt/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
DBT_PROJECT_FILE_NAME = "dbt_project.yml"
PACKAGES_FILE_NAME = "packages.yml"
DEPENDENCIES_FILE_NAME = "dependencies.yml"
PACKAGE_LOCK_FILE_NAME = "package-lock.yml"
MANIFEST_FILE_NAME = "manifest.json"
SEMANTIC_MANIFEST_FILE_NAME = "semantic_manifest.json"
PARTIAL_PARSE_FILE_NAME = "partial_parse.msgpack"
PACKAGE_LOCK_HASH_KEY = "sha1_hash"
12 changes: 12 additions & 0 deletions core/dbt/deps/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,15 @@ def resolve_packages(
resolved = final.resolved()
_check_for_duplicate_project_names(resolved, project, renderer)
return resolved


def resolve_lock_packages(packages: List[PackageContract]) -> List[PinnedPackage]:
lock_packages = PackageListing.from_contracts(packages)
final = PackageListing()

for package in lock_packages:
final.incorporate(package)

resolved = final.resolved()

return resolved
42 changes: 42 additions & 0 deletions core/dbt/events/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1586,6 +1586,48 @@ message NoNodesForSelectionCriteriaMsg {
NoNodesForSelectionCriteria data = 2;
}

// M031
message DepsLockUpdating{
string lock_filepath = 1;
}

message DepsLockUpdatingMsg{
EventInfo info = 1;
DepsLockUpdating data = 2;
}

// M032
message DepsAddPackage{
string package_name = 1;
string version = 2;
string packages_filepath = 3;
}

message DepsAddPackageMsg{
EventInfo info = 1;
DepsAddPackage data = 2;
}

//M033
message DepsFoundDuplicatePackage{
map<string, string> removed_package = 1;
}

message DepsFoundDuplicatePackageMsg{
EventInfo info = 1;
DepsFoundDuplicatePackage data = 2;
}

//M034
message DepsVersionMissing{
string source = 1;
}

message DepsVersionMissingMsg{
EventInfo info = 1;
DepsVersionMissing data = 2;
}

// Q - Node execution

// Q001
Expand Down
24 changes: 24 additions & 0 deletions core/dbt/events/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1504,6 +1504,30 @@ def message(self) -> str:
return f"The selection criterion '{self.spec_raw}' does not match any nodes"


class DepsLockUpdating(InfoLevel):
def code(self):
return "M031"

def message(self) -> str:
return f"Updating lock file in file path: {self.lock_filepath}"


class DepsAddPackage(InfoLevel):
def code(self):
return "M032"

def message(self) -> str:
return f"Added new package {self.package_name}@{self.version} to {self.packages_filepath}"


class DepsFoundDuplicatePackage(InfoLevel):
def code(self):
return "M033"

def message(self) -> str:
return f"Found duplicate package in packages.yml, removing: {self.removed_package}"


# =======================================================
# Q - Node execution
# =======================================================
Expand Down
1,781 changes: 901 additions & 880 deletions core/dbt/events/types_pb2.py

Large diffs are not rendered by default.

Loading