Skip to content

Commit

Permalink
[#3940] Use flags.PROFILES_DIR in a few more places
Browse files Browse the repository at this point in the history
  • Loading branch information
gshank committed Sep 23, 2021
1 parent 9316e47 commit 2664d9e
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 10 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## dbt 1.00.0 (Release TBD)

### Features
- Normalize global CLI arguments/flags ([#2990](https://github.com/dbt-labs/dbt/issues/2990), [#3839](https://github.com/dbt-labs/dbt/pull/3839))

## dbt 0.21.0 (Release TBD)

## dbt 0.21.0rc1 (September 20, 2021)
Expand All @@ -16,7 +21,6 @@
- Added timing and thread information to sources.json artifact ([#3804](https://github.com/dbt-labs/dbt/issues/3804), [#3894](https://github.com/dbt-labs/dbt/pull/3894))
- Update cli and rpc flags for the `build` task to align with other commands (`--resource-type`, `--store-failures`) ([#3596](https://github.com/dbt-labs/dbt/issues/3596), [#3884](https://github.com/dbt-labs/dbt/pull/3884))
- Log tests that are not indirectly selected. Add `--greedy` flag to `test`, `list`, `build` and `greedy` property in yaml selectors ([#3723](https://github.com/dbt-labs/dbt/pull/3723), [#3833](https://github.com/dbt-labs/dbt/pull/3833))
- Normalize global CLI arguments/flags ([#2990](https://github.com/dbt-labs/dbt/issues/2990), [#3839](https://github.com/dbt-labs/dbt/pull/3839))

### Fixes

Expand Down
3 changes: 2 additions & 1 deletion core/dbt/config/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from dbt.dataclass_schema import ValidationError

from dbt import flags
from dbt.clients.system import load_file_contents
from dbt.clients.yaml_helper import load_yaml_text
from dbt.contracts.connection import Credentials, HasCredentials
Expand Down Expand Up @@ -433,7 +434,7 @@ def render_from_args(
"""
threads_override = getattr(args, 'threads', None)
target_override = getattr(args, 'target', None)
raw_profiles = read_profile(args.profiles_dir)
raw_profiles = read_profile(flags.PROFILES_DIR)
profile_name = cls.pick_profile_name(getattr(args, 'profile', None),
project_profile_name)
return cls.from_raw_profiles(
Expand Down
15 changes: 9 additions & 6 deletions core/dbt/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def handle_and_check(args):
parsed = parse_args(args)

# Set flags from args, user config, and env vars
user_config = read_user_config(parsed.profiles_dir) # This is read again later
user_config = read_user_config(flags.PROFILES_DIR) # This is read again later
flags.set_from_args(parsed, user_config)
dbt.tracking.initialize_from_flags()
# Set log_format from flags
Expand Down Expand Up @@ -1160,11 +1160,14 @@ def parse_args(args, cls=DBTArgumentParser):
if parsed.sub_profiles_dir is not None:
parsed.profiles_dir = parsed.sub_profiles_dir
delattr(parsed, 'sub_profiles_dir')
if hasattr(parsed, 'profiles_dir') and parsed.profiles_dir is not None:
parsed.profiles_dir = os.path.abspath(parsed.profiles_dir)
# needs to be set before the other flags, because it's needed to
# read the profile that contains them
flags.PROFILES_DIR = parsed.profiles_dir
if hasattr(parsed, 'profiles_dir'):
if parsed.profiles_dir is None:
parsed.profiles_dir = flags.PROFILES_DIR
else:
parsed.profiles_dir = os.path.abspath(parsed.profiles_dir)
# needs to be set before the other flags, because it's needed to
# read the profile that contains them
flags.PROFILES_DIR = parsed.profiles_dir

# version_check is set before subcommands and after, so normalize
if hasattr(parsed, 'sub_version_check'):
Expand Down
2 changes: 1 addition & 1 deletion core/dbt/parser/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ def build_manifest_state_check(self):
])
)

profile_path = os.path.join(config.args.profiles_dir, 'profiles.yml')
profile_path = os.path.join(flags.PROFILES_DIR, 'profiles.yml')
with open(profile_path) as fp:
profile_hash = FileHash.from_contents(fp.read())

Expand Down
2 changes: 1 addition & 1 deletion core/dbt/task/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def from_args(cls, args):
logger.error("Encountered an error while reading profiles:")
logger.error(" ERROR {}".format(str(exc)))

all_profiles = read_profiles(args.profiles_dir).keys()
all_profiles = read_profiles(flags.PROFILES_DIR).keys()

if len(all_profiles) > 0:
logger.info("Defined profiles:")
Expand Down
1 change: 1 addition & 0 deletions test/integration/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ def use_profile(self, adapter_type):
if not os.path.exists(self.test_root_dir):
os.makedirs(self.test_root_dir)

flags.PROFILES_DIR = self.test_root_dir
profiles_path = os.path.join(self.test_root_dir, 'profiles.yml')
with open(profiles_path, 'w') as f:
yaml.safe_dump(profile_config, f, default_flow_style=True)
Expand Down
2 changes: 2 additions & 0 deletions test/rpc/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import yaml

from dbt import flags

def pytest_addoption(parser):
parser.addoption(
Expand Down Expand Up @@ -145,6 +146,7 @@ def dbt_profile_data(unique_schema, pytestconfig):

@pytest.fixture
def dbt_profile(profiles_root, dbt_profile_data) -> Dict[str, Any]:
flags.PROFILES_DIR = profiles_root
path = os.path.join(profiles_root, 'profiles.yml')
with open(path, 'w') as fp:
fp.write(yaml.safe_dump(dbt_profile_data))
Expand Down
1 change: 1 addition & 0 deletions test/rpc/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def __init__(
'--port', str(self.port),
'--profiles-dir', profiles_dir
]
dbt.flags.PROFILES_DIR = profiles_dir
if cli_vars:
handle_and_check_args.extend(['--vars', cli_vars])
if target is not None:
Expand Down
2 changes: 2 additions & 0 deletions test/unit/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import dbt.config
import dbt.exceptions
from dbt import flags
from dbt.adapters.factory import load_plugin
from dbt.adapters.postgres import PostgresCredentials
from dbt.adapters.redshift import RedshiftCredentials
Expand Down Expand Up @@ -93,6 +94,7 @@ def __init__(self, profiles_dir=None, threads=None, profile=None,
self.threads = threads
if profiles_dir is not None:
self.profiles_dir = profiles_dir
flags.PROFILES_DIR = profiles_dir
if cli_vars is not None:
self.vars = cli_vars
if version_check is not None:
Expand Down

0 comments on commit 2664d9e

Please sign in to comment.