-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
consolidate flags #6788
Merged
Merged
consolidate flags #6788
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
0a27d1e
remove global WIP
ChenyuLInx b1e8bf6
flags mostly working, missing dir set from previous
ChenyuLInx 8ed644f
more work on flags
ChenyuLInx 2662ed7
29 tests failing
ChenyuLInx 8127f18
flags mostly working
ChenyuLInx 52124e0
remove test/integration
ChenyuLInx c332835
more flag fix
ChenyuLInx 28b088e
remove running integration test
ChenyuLInx 0e6a888
remove one global
ChenyuLInx 196efac
set_args in deprecation unit test + use renamed flags as globals
MichelleArk f31f611
fix manifest unit test, s/DUPLICATE_PARAMS/EXPECTED_DUPLICATE_PARAMS,…
MichelleArk ed1b5d4
fix --version
MichelleArk e11602e
test_config mostly passing
MichelleArk 00da2a1
load log-path from dbt_project.yml
MichelleArk 9cbe68c
try/except dbtProjectError when loading log-path from dbt_project.yml
MichelleArk 9b9c908
update default log_path
ChenyuLInx 89ff58a
Add generated CLI API docs
FishtownBuildBot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
|
||
from dbt.dataclass_schema import ValidationError | ||
|
||
from dbt import flags | ||
from dbt.flags import get_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 | ||
|
@@ -32,22 +32,6 @@ | |
""" | ||
|
||
|
||
NO_SUPPLIED_PROFILE_ERROR = """\ | ||
dbt cannot run because no profile was specified for this dbt project. | ||
To specify a profile for this project, add a line like the this to | ||
your dbt_project.yml file: | ||
|
||
profile: [profile name] | ||
|
||
Here, [profile name] should be replaced with a profile name | ||
defined in your profiles.yml file. You can find profiles.yml here: | ||
|
||
{profiles_file}/profiles.yml | ||
""".format( | ||
profiles_file=flags.DEFAULT_PROFILES_DIR | ||
) | ||
|
||
|
||
def read_profile(profiles_dir: str) -> Dict[str, Any]: | ||
path = os.path.join(profiles_dir, "profiles.yml") | ||
|
||
|
@@ -197,10 +181,33 @@ 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(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TODO: add comment + link issue for default lookup in Flags |
||
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 | ||
if profile_name is None: | ||
NO_SUPPLIED_PROFILE_ERROR = """\ | ||
dbt cannot run because no profile was specified for this dbt project. | ||
To specify a profile for this project, add a line like the this to | ||
your dbt_project.yml file: | ||
|
||
profile: [profile name] | ||
|
||
Here, [profile name] should be replaced with a profile name | ||
defined in your profiles.yml file. You can find profiles.yml here: | ||
|
||
{profiles_file}/profiles.yml | ||
""".format( | ||
profiles_file=default_profiles_dir() | ||
) | ||
raise DbtProjectError(NO_SUPPLIED_PROFILE_ERROR) | ||
return profile_name | ||
|
||
|
@@ -423,7 +430,7 @@ def render( | |
target could not be found. | ||
:returns Profile: The new Profile object. | ||
""" | ||
|
||
flags = get_flags() | ||
raw_profiles = read_profile(flags.PROFILES_DIR) | ||
profile_name = cls.pick_profile_name(profile_name_override, project_profile_name) | ||
return cls.from_raw_profiles( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not directly related to this changeset, so feel free to ignore this comment.
I think this flags code would be simpler and more readable if we added _get_flag() and _set_flag() functions which handled the casing concerns and the use of the setattr/getattr functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I was chatting with @MichelleArk about similar thing also. @iknox-fa might have something around it, but we are gonna defer that to work later on instead of in this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't do that the first time around because I wanted to keep things as immutable as python allows so adding even a "private" method to do that seemed like a recipe for mutated flags in the codebase in a few months.
Maybe as a compromise for readability we just make nested
get
andset
functions in init? That way no-one uses them unless they're directly editing the flags? We can discuss it further but given how much of a tangled mess the flags are currently I think we're going to get a lot of mileage out of having reasonable assurance of immutability and I don't want to jeopardize that.