From 05f6305b679fc00781e45e4449452adf6df90c36 Mon Sep 17 00:00:00 2001 From: Daniel Radetsky Date: Sat, 7 Dec 2024 15:18:38 -0800 Subject: [PATCH 1/5] use xdg (and fix circular dep) --- core/dbt/cli/__init__.py | 1 - core/dbt/cli/resolvers.py | 7 ++++++- core/dbt/config/profile.py | 10 +--------- core/setup.py | 1 + dev-requirements.txt | 2 ++ 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/core/dbt/cli/__init__.py b/core/dbt/cli/__init__.py index 8dc5c408aa2..e69de29bb2d 100644 --- a/core/dbt/cli/__init__.py +++ b/core/dbt/cli/__init__.py @@ -1 +0,0 @@ -from .main import cli as dbt_cli # noqa diff --git a/core/dbt/cli/resolvers.py b/core/dbt/cli/resolvers.py index 6d495501c39..5ec6988dd19 100644 --- a/core/dbt/cli/resolvers.py +++ b/core/dbt/cli/resolvers.py @@ -3,6 +3,8 @@ from dbt.config.project import PartialProject from dbt.exceptions import DbtProjectError +from appdirs import user_config_dir + def default_project_dir() -> Path: paths = list(Path.cwd().parents) @@ -11,7 +13,10 @@ def default_project_dir() -> Path: def default_profiles_dir() -> Path: - return Path.cwd() if (Path.cwd() / "profiles.yml").exists() else Path.home() / ".dbt" + if (Path.cwd() / "profiles.yml").exists(): + return Path.cwd() + else: + return user_config_dir() / Path("dbt") def default_log_path(project_dir: Path, verify_version: bool = False) -> Path: diff --git a/core/dbt/config/profile.py b/core/dbt/config/profile.py index ada7f30711c..f4bee703154 100644 --- a/core/dbt/config/profile.py +++ b/core/dbt/config/profile.py @@ -3,6 +3,7 @@ from typing import Any, Dict, Optional, Tuple from dbt.adapters.contracts.connection import Credentials, HasCredentials +from dbt.cli.resolvers import default_profiles_dir from dbt.clients.yaml_helper import load_yaml_text from dbt.contracts.project import ProfileConfig from dbt.events.types import MissingProfileTarget @@ -164,15 +165,6 @@ def pick_profile_name( args_profile_name: Optional[str], project_profile_name: Optional[str] = None, ) -> str: - # TODO: Duplicating this method as direct copy of the implementation in dbt.cli.resolvers - # dbt.cli.resolvers implementation can't be used because it causes a circular dependency. - # This should be removed and use a safe default access on the Flags module when - # https://github.com/dbt-labs/dbt-core/issues/6259 is closed. - def default_profiles_dir(): - from pathlib import Path - - return Path.cwd() if (Path.cwd() / "profiles.yml").exists() else Path.home() / ".dbt" - profile_name = project_profile_name if args_profile_name is not None: profile_name = args_profile_name diff --git a/core/setup.py b/core/setup.py index be77d1ba73b..174f3f2a8f6 100644 --- a/core/setup.py +++ b/core/setup.py @@ -46,6 +46,7 @@ "console_scripts": ["dbt = dbt.cli.main:cli"], }, install_requires=[ + "appdirs>=1.4.4", # ---- # dbt-core uses these packages deeply, throughout the codebase, and there have been breaking changes in past patch releases (even though these are major-version-one). # Pin to the patch or minor version, and bump in each new minor version of dbt-core. diff --git a/dev-requirements.txt b/dev-requirements.txt index 5f393349744..d41bd32e5eb 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -2,6 +2,7 @@ git+https://github.com/dbt-labs/dbt-adapters.git@main git+https://github.com/dbt-labs/dbt-adapters.git@main#subdirectory=dbt-tests-adapter git+https://github.com/dbt-labs/dbt-common.git@main git+https://github.com/dbt-labs/dbt-postgres.git@main +appdirs # black must match what's in .pre-commit-config.yaml to be sure local env matches CI black==24.3.0 bumpversion @@ -29,6 +30,7 @@ pytest-split pytest-xdist sphinx tox>=3.13 +types-appdirs types-docutils types-PyYAML types-Jinja2 From 09da2cec9100e4571ce4725304c619c8decb70b9 Mon Sep 17 00:00:00 2001 From: Daniel Radetsky Date: Sat, 7 Dec 2024 15:19:58 -0800 Subject: [PATCH 2/5] oops --- core/dbt/cli/resolvers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/dbt/cli/resolvers.py b/core/dbt/cli/resolvers.py index 5ec6988dd19..2a414c6f466 100644 --- a/core/dbt/cli/resolvers.py +++ b/core/dbt/cli/resolvers.py @@ -1,10 +1,10 @@ from pathlib import Path +from appdirs import user_config_dir + from dbt.config.project import PartialProject from dbt.exceptions import DbtProjectError -from appdirs import user_config_dir - def default_project_dir() -> Path: paths = list(Path.cwd().parents) From 0eee2a9a5f47fbabed58990803e64cda40728350 Mon Sep 17 00:00:00 2001 From: Daniel Radetsky Date: Sat, 7 Dec 2024 15:28:53 -0800 Subject: [PATCH 3/5] use params for more compat --- core/dbt/cli/resolvers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/dbt/cli/resolvers.py b/core/dbt/cli/resolvers.py index 2a414c6f466..98c1c90a4d5 100644 --- a/core/dbt/cli/resolvers.py +++ b/core/dbt/cli/resolvers.py @@ -16,7 +16,7 @@ def default_profiles_dir() -> Path: if (Path.cwd() / "profiles.yml").exists(): return Path.cwd() else: - return user_config_dir() / Path("dbt") + return user_config_dir(appname="dbt", appauthor="dbt-labs") def default_log_path(project_dir: Path, verify_version: bool = False) -> Path: From 7341cf13b6701bd8392b1c942cdfd46b27599b34 Mon Sep 17 00:00:00 2001 From: Daniel Radetsky Date: Sat, 7 Dec 2024 15:45:44 -0800 Subject: [PATCH 4/5] type fix --- core/dbt/cli/resolvers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/dbt/cli/resolvers.py b/core/dbt/cli/resolvers.py index 98c1c90a4d5..d376f0b5afa 100644 --- a/core/dbt/cli/resolvers.py +++ b/core/dbt/cli/resolvers.py @@ -16,7 +16,7 @@ def default_profiles_dir() -> Path: if (Path.cwd() / "profiles.yml").exists(): return Path.cwd() else: - return user_config_dir(appname="dbt", appauthor="dbt-labs") + return Path(user_config_dir(appname="dbt", appauthor="dbt-labs")) def default_log_path(project_dir: Path, verify_version: bool = False) -> Path: From fbfc2f5d5e0ae361a6a0be9040ece81ccd72f78b Mon Sep 17 00:00:00 2001 From: Daniel Radetsky Date: Sat, 7 Dec 2024 16:00:40 -0800 Subject: [PATCH 5/5] is this how you changelog? --- .changes/unreleased/Fixes-20241207-155958.yaml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changes/unreleased/Fixes-20241207-155958.yaml diff --git a/.changes/unreleased/Fixes-20241207-155958.yaml b/.changes/unreleased/Fixes-20241207-155958.yaml new file mode 100644 index 00000000000..03d961164e3 --- /dev/null +++ b/.changes/unreleased/Fixes-20241207-155958.yaml @@ -0,0 +1,6 @@ +kind: Fixes +body: Use xdg and also fix circular dep +time: 2024-12-07T15:59:58.137140008-08:00 +custom: + Author: dradetsky + Issue: "2515"