Repository: dbt-labs/dbt-core

Issue:
Project dir argument not used when running debug
### Describe the bug
When running `dbt debug --project-dir=<some directory>` in another directory to that of your dbt project, the `dbt_project.yml` is not used.

### Steps To Reproduce
With an existing dbt project:

```bash
$ cd /tmp
$ dbt debug --project-dir=<path/to/project> --profiles-dir=$HOME/.dbt/
```

we get the following output:

```
Using profiles.yml file at /app/src/pipeline/profiles.yml

Configuration:
  profiles.yml file [OK found and valid]
  dbt_project.yml file [ERROR not found]
  profile: some-profile-name [OK found]
  target: production [OK found]
```

### Expected behavior
Would expect the output to be the following:

```
Using profiles.yml file at /app/src/pipeline/profiles.yml

Configuration:
  profiles.yml file [OK found and valid]
  dbt_project.yml file [OK found and valid]
  profile: some-profile-name [OK found]
  target: production [OK found]
```

### System information
**Which database are you using dbt with?**
- [ ] postgres
- [ ] redshift
- [x] bigquery
- [ ] snowflake
- [ ] other (specify: ____________)


**The output of `dbt --version`:**
```
installed version: 0.14.0
   latest version: 0.14.1
```

Also tried with version 0.14.1. and obtained the same behavior.

**The operating system you're using:**
Ubuntu 19.04

**The output of `python --version`:**
Python 3.7.4

### Additional context
After a brief debugging session, we found the `get_nearest_project_dir()` function in `dbt/core/dbt/task/base.py`. This function is called when running `dbt compile ` and `dbt run`, but not `dbt debug`.

Inspecting the parsed arguments shows the `project_dir` attribute is set correctly.

When running `dbt debug` in the actual project directory, dbt is able to pick up `dbt_project.yml` correctly.

Project dir argument not used when running debug
### Describe the bug
When running `dbt debug --project-dir=<some directory>` in another directory to that of your dbt project, the `dbt_project.yml` is not used.

### Steps To Reproduce
With an existing dbt project:

```bash
$ cd /tmp
$ dbt debug --project-dir=<path/to/project> --profiles-dir=$HOME/.dbt/
```

we get the following output:

```
Using profiles.yml file at /app/src/pipeline/profiles.yml

Configuration:
  profiles.yml file [OK found and valid]
  dbt_project.yml file [ERROR not found]
  profile: some-profile-name [OK found]
  target: production [OK found]
```

### Expected behavior
Would expect the output to be the following:

```
Using profiles.yml file at /app/src/pipeline/profiles.yml

Configuration:
  profiles.yml file [OK found and valid]
  dbt_project.yml file [OK found and valid]
  profile: some-profile-name [OK found]
  target: production [OK found]
```

### System information
**Which database are you using dbt with?**
- [ ] postgres
- [ ] redshift
- [x] bigquery
- [ ] snowflake
- [ ] other (specify: ____________)


**The output of `dbt --version`:**
```
installed version: 0.14.0
   latest version: 0.14.1
```

Also tried with version 0.14.1. and obtained the same behavior.

**The operating system you're using:**
Ubuntu 19.04

**The output of `python --version`:**
Python 3.7.4

### Additional context
After a brief debugging session, we found the `get_nearest_project_dir()` function in `dbt/core/dbt/task/base.py`. This function is called when running `dbt compile ` and `dbt run`, but not `dbt debug`.

Inspecting the parsed arguments shows the `project_dir` attribute is set correctly.

When running `dbt debug` in the actual project directory, dbt is able to pick up `dbt_project.yml` correctly.



Discussion:
Thanks for the report @gobbledygook88! Your diagnosis sounds spot-on to me
Thanks for the report @gobbledygook88! Your diagnosis sounds spot-on to me

Resolving patch:
diff --git a/core/dbt/task/debug.py b/core/dbt/task/debug.py
--- a/core/dbt/task/debug.py
+++ b/core/dbt/task/debug.py
@@ -69,7 +69,8 @@ def __init__(self, args, config):
         self.profiles_dir = getattr(self.args, 'profiles_dir',
                                     dbt.config.PROFILES_DIR)
         self.profile_path = os.path.join(self.profiles_dir, 'profiles.yml')
-        self.project_path = os.path.join(os.getcwd(), 'dbt_project.yml')
+        self.project_dir = args.project_dir or os.getcwd()
+        self.project_path = os.path.join(self.project_dir, 'dbt_project.yml')
         self.cli_vars = dbt.utils.parse_cli_vars(
             getattr(self.args, 'vars', '{}')
         )
@@ -125,7 +126,8 @@ def _load_project(self):
             return red('ERROR not found')
 
         try:
-            self.project = Project.from_current_directory(self.cli_vars)
+            self.project = Project.from_project_root(self.project_dir,
+                                                     self.cli_vars)
         except dbt.exceptions.DbtConfigError as exc:
             self.project_fail_details = str(exc)
             return red('ERROR invalid')


Test patch:
diff --git a/test/integration/049_dbt_debug_test/test_debug.py b/test/integration/049_dbt_debug_test/test_debug.py
--- a/test/integration/049_dbt_debug_test/test_debug.py
+++ b/test/integration/049_dbt_debug_test/test_debug.py
@@ -1,6 +1,7 @@
 from test.integration.base import DBTIntegrationTest,  use_profile
 import os
 import re
+import yaml
 
 import pytest
 
@@ -103,3 +104,26 @@ def test_postgres_badproject(self):
                 self.assertIn('ERROR invalid', line)
             elif line.strip().startswith('profiles.yml file'):
                 self.assertNotIn('ERROR invalid', line)
+
+    @use_profile('postgres')
+    def test_postgres_not_found_project_dir(self):
+        self.run_dbt(['debug', '--project-dir', 'nopass'])
+        splitout = self.capsys.readouterr().out.split('\n')
+        for line in splitout:
+            if line.strip().startswith('dbt_project.yml file'):
+                self.assertIn('ERROR not found', line)
+
+    @use_profile('postgres')
+    def test_postgres_invalid_project_outside_current_dir(self):
+        # create a dbt_project.yml
+        project_config = {
+            'invalid-key': 'not a valid key in this project'
+        }
+        os.makedirs('custom', exist_ok=True)
+        with open("custom/dbt_project.yml", 'w') as f:
+            yaml.safe_dump(project_config, f, default_flow_style=True)
+        self.run_dbt(['debug', '--project-dir', 'custom'])
+        splitout = self.capsys.readouterr().out.split('\n')
+        for line in splitout:
+            if line.strip().startswith('dbt_project.yml file'):
+                self.assertIn('ERROR invalid', line)