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

Update UnsetProfileConfig.from_args to use args.project_dir if passed #2339

Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
- Return error message when profile is empty in profiles.yml. ([#2292](https://github.com/fishtown-analytics/dbt/issues/2292), [#2297](https://github.com/fishtown-analytics/dbt/pull/2297))
- Fix skipped node count in stdout at the end of a run ([#2095](https://github.com/fishtown-analytics/dbt/issues/2095), [#2310](https://github.com/fishtown-analytics/dbt/pull/2310))
- Fix an issue where BigQuery incorrectly used a relation's quote policy as the basis for the information schema's include policy, instead of the relation's include policy. ([#2188](https://github.com/fishtown-analytics/dbt/issues/2188), [#2325](https://github.com/fishtown-analytics/dbt/pull/2325))
- Fix "dbt deps" command so it respects the "--project-dir" arg if specified. ([#2338](https://github.com/fishtown-analytics/dbt/issues/2338), [#2339](https://github.com/fishtown-analytics/dbt/issues/2339))

### Under the hood
- Added more tests for source inheritance ([#2264](https://github.com/fishtown-analytics/dbt/issues/2264), [#2291](https://github.com/fishtown-analytics/dbt/pull/2291))
Expand All @@ -33,6 +34,7 @@ Contributors:
- [@jeremyyeo](https://github.com/jeremyyeo) [#2259](https://github.com/fishtown-analytics/dbt/pull/2259)
- [@rodrigodelmonte](https://github.com/rodrigodelmonte) [#2298](https://github.com/fishtown-analytics/dbt/pull/2298)
- [@sumanau7](https://github.com/sumanau7) ([#2279](https://github.com/fishtown-analytics/dbt/pull/2279), [#2263](https://github.com/fishtown-analytics/dbt/pull/2263), [#2297](https://github.com/fishtown-analytics/dbt/pull/2297))
- [@nickwu241](https://github.com/nickwu241) [#2339](https://github.com/fishtown-analytics/dbt/issues/2339)

## dbt 0.16.1 (April 14, 2020)

Expand Down
9 changes: 5 additions & 4 deletions core/dbt/config/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,17 +297,18 @@ def from_parts(

@classmethod
def from_args(cls: Type[RuntimeConfig], args: Any) -> 'RuntimeConfig':
"""Given arguments, read in dbt_project.yml from the current directory,
read in packages.yml if it exists, and use them to find the profile to
load.
"""Given arguments, read in dbt_project.yml from the arg --project-dir
or current directory if not provided, read in packages.yml if it
exists, and use them to find the profile to load.

:param args: The arguments as parsed from the cli.
:raises DbtProjectError: If the project is invalid or missing.
:raises DbtProfileError: If the profile is invalid or missing.
:raises ValidationException: If the cli variables are invalid.
"""
# profile_name from the project
partial = Project.partial_load(os.getcwd())
project_root = args.project_dir if args.project_dir else os.getcwd()
partial = Project.partial_load(project_root)

# build the profile using the base renderer and the one fact we know
cli_vars: Dict[str, Any] = parse_cli_vars(getattr(args, 'vars', '{}'))
Expand Down
29 changes: 29 additions & 0 deletions test/integration/015_cli_invocation_tests/test_cli_invocation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from test.integration.base import DBTIntegrationTest, use_profile
import os
import shutil
import tempfile
import yaml


Expand Down Expand Up @@ -111,3 +112,31 @@ def test_postgres_toplevel_dbt_run_with_profile_dir_arg(self):
# make sure the test runs against `custom_schema`
for test_result in res:
self.assertTrue(self.custom_schema, test_result.node.injected_sql)


class TestCLIInvocationWithProjectDir(ModelCopyingIntegrationTest):

@property
def schema(self):
return "test_cli_invocation_015"

@property
def models(self):
return "models"

@use_profile('postgres')
def test_postgres_dbt_commands_with_cwd_as_project_dir(self):
self._run_simple_dbt_commands(os.getcwd())

@use_profile('postgres')
def test_postgres_dbt_commands_with_randomdir_as_project_dir(self):
workdir = os.getcwd()
with tempfile.TemporaryDirectory() as tmpdir:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What!? How did I not know about this context manager? This is awesome!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha I found out about it today!

os.chdir(tmpdir)
self._run_simple_dbt_commands(workdir)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we will need an os.chdir(workdir) after this line for Windows tests. While linux/osx will happily rm -r the directory you're in for the most part, Windows gets cranky about it.

Copy link
Contributor Author

@nickwu241 nickwu241 Apr 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense, changes done.

and also curious: would this be caught in tests (i.e. does dbt run tests w/ windows)?

Copy link
Contributor

@beckjake beckjake Apr 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup! I'm about to kick them off now, I just didn't want to run the full test suite and then have to re-run later. Running tests for external contributors isn't quite as friction-free as we'd like yet.

https://dev.azure.com/fishtown-analytics/dbt/_build/results?buildId=1798&view=results - it's the blue rocket ship link in the "checks" section

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see HAHA, that's awesome, I assume it's a lot of resources to use to run all these tests 😛 Appreciate it.


def _run_simple_dbt_commands(self, project_dir):
self.run_dbt(['deps', '--project-dir', project_dir])
self.run_dbt(['seed', '--project-dir', project_dir])
self.run_dbt(['run', '--project-dir', project_dir])
self.run_dbt(['test', '--project-dir', project_dir])