-
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
Feature request: Add a dbt flag to specify the working directory #1544
Comments
I took a quick crack at this implementation, and it's a pretty straightforward modification to main.py in the latest release (0.11.1). However, this change runs into major merge conflicts with 1a0df17?diff=split when merged to dev/wilt-chamberlain, so I'm going to abandon this change for now (until wilt-chamberlain is released). Also, I think a better flag name is --project-dir instead of --working-dir, since this is the directory for the project. |
Do you mean I am not really surprised by that, that was a heck of a merge. Fortunately, I think the place to do this is 1) off wilt-chamberlain (or louisa-may-alcott once I merge in the current state of wilt-chamberlain) 2) in the |
Yup! I meant 0.13.1. I'll take a quick look at |
Ok. it's possible I have overlooked something and the real place to do it is |
The change I was planning against 0.13.1's main.py looked basically like this: # (Define new flag named 'project-dir' and make it optional.)
def get_nearest_project_dir(parsed):
# If the user provides an explicit project directory, use that.
if parsed.project_dir:
project_file = os.path.join(parsed.project_dir, "dbt_project.yml")
if os.path.exists(project_file):
return parsed.project_dir
else:
return None
# Otherwise, use the current working directory and all its parents.
cwd = os.getcwd()
root_path = os.path.abspath(os.sep)
while cwd != root_path:
project_file = os.path.join(cwd, "dbt_project.yml")
if os.path.exists(project_file):
return cwd
cwd = os.path.dirname(cwd)
return None So, wherever the 'get_nearest_project_dir' moved to, that's where I was thinking it would go. I didn't see anything in the new main.py that did an |
Oh, I see! That's reasonable enough, I hadn't thought of that. It should now be in In that method, |
Good to know! That should make it a straightforward change then. |
Hi @beckjake, where should I put the unit test for this change? |
There's a set of tests in |
Hi @beckjake: Let me know if the unit test looks good. I couldn't get TestProjectFile and TestRuntimeConfigFiles to easily invoke the modified code, so I added a new test case called TestRunOperationTask to create a new RunOperationTask and make sure the os directory was appropriately changed. If the test looks good, this change is ready for merging. |
closed by #1549 |
Feature
Feature description
Add a new flag to dbt to allow specifying the directory of the dbt_project.yml file (which in turn defines the relative directories of the other project files). This would be analogous to the -C and --git-dir flags for the git command. This would also complement the existing --profiles-dir flag.
Suggested name: --working-dir
Who will this benefit?
It would make tooling easier if it wasn't necessary to change the working directory before running dbt. For example, this reference implementation that combines dbt with airflow needs to include a 'cd' command within each BashOperator: https://gist.github.com/adamhaney/916a21b0adcabef4038c38e3ac96a36f
With this change, it would be sufficient just to pass this flag each time.
Also see slack discussion: https://getdbt.slack.com/messages/CBSQTAPLG/convo/CBSQTAPLG-1560546908.162800/
The text was updated successfully, but these errors were encountered: