44from __future__ import annotations
55
66import logging
7+ import os
78import threading
89import typing as t
910import weakref
@@ -123,6 +124,16 @@ def _monitor_loop(self) -> None:
123124
124125 _ = self ._stop_event .wait (self .check_interval )
125126
127+ def _all_profiles_yml_paths (self ) -> list [Path ]:
128+ """Return all potential profiles.yml paths in priority order."""
129+ paths = []
130+ env_dir = os .environ .get ("DBT_PROFILES_DIR" )
131+ if env_dir :
132+ paths .append (Path (env_dir ).expanduser ().resolve () / "profiles.yml" )
133+ paths .append (self ._project_or_raise .project_root / "profiles.yml" )
134+ paths .append (Path .home () / ".dbt" / "profiles.yml" )
135+ return paths
136+
126137 def _initialize_file_mtimes (self ) -> None :
127138 """Initialize the file modification time tracking."""
128139 for f_proxy in self ._project_or_raise .manifest .files .values ():
@@ -132,9 +143,8 @@ def _initialize_file_mtimes(self) -> None:
132143 self ._mtimes [self ._project_or_raise .dbt_project_yml ] = (
133144 self ._project_or_raise .dbt_project_yml .stat ().st_mtime
134145 )
135- self ._mtimes [self ._project_or_raise .profiles_yml ] = (
136- self ._project_or_raise .profiles_yml .stat ().st_mtime
137- )
146+ for path in self ._all_profiles_yml_paths ():
147+ self ._mtimes [path ] = path .stat ().st_mtime if path .exists () else 0.0
138148 logger .debug (f"Initialized tracking for { len (self ._mtimes )} files" )
139149
140150 def _check_for_changes (self ) -> int :
@@ -143,11 +153,12 @@ def _check_for_changes(self) -> int:
143153 A return value of 0 means no changes, 1 means files were added/removed, and 2 means
144154 a configuration file was modified (dbt_project.yml or profiles.yml).
145155 """
146- for path in (self ._project_or_raise .dbt_project_yml , self ._project_or_raise .profiles_yml ):
156+ config_paths = [self ._project_or_raise .dbt_project_yml , * self ._all_profiles_yml_paths ()]
157+ for path in config_paths :
147158 try :
148159 current_mtime = path .stat ().st_mtime if path .exists () else 0.0
149160 stamped_mtime = self ._mtimes .get (path )
150- if stamped_mtime is None or current_mtime > stamped_mtime :
161+ if stamped_mtime is None or current_mtime != stamped_mtime :
151162 self ._mtimes [path ] = current_mtime
152163 return 2
153164 except OSError as e :
0 commit comments