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

[CT-1357] [Feature] DBT_PROJECT_DIR env var #6078

Closed
3 tasks done
jtcohen6 opened this issue Oct 17, 2022 · 4 comments · Fixed by #6659
Closed
3 tasks done

[CT-1357] [Feature] DBT_PROJECT_DIR env var #6078

jtcohen6 opened this issue Oct 17, 2022 · 4 comments · Fixed by #6659
Labels
enhancement New feature or request help_wanted Trickier changes, with a clear starting point, good for previous/experienced contributors

Comments

@jtcohen6
Copy link
Contributor

Is this your first time submitting a feature request?

  • I have read the expectations for open source contributors
  • I have searched the existing issues, and I could not find an existing issue for this feature
  • I am requesting a straightforward extension of existing dbt functionality, rather than a Big Idea better suited to a discussion

Describe the feature

First proposed in #5411. Not included in initial implementation from #5717

It should be possible to set the --project-dir CLI flag via env var instead: DBT_PROJECT_DIR

It's very easy to do this using the new CLI framework:

profiles_dir = click.option(
"--profiles-dir",
envvar="DBT_PROFILES_DIR",
help="Which directory to look in for the profiles.yml file. If not set, dbt will look in the current working directory first, then HOME/.dbt/",
default=default_profiles_dir(),
type=click.Path(exists=True),
)
project_dir = click.option(
"--project-dir",
envvar=None,
help="Which directory to look in for the dbt_project.yml file. Default is the current working directory and its parents.",
default=default_project_dir(),
type=click.Path(exists=True),
)

It's a bit trickier for the old framework. See prior art from --profiles-dir:

dbt-core/core/dbt/main.py

Lines 1189 to 1201 in 73aebd8

# profiles_dir is set before subcommands and after, so normalize
if hasattr(parsed, "sub_profiles_dir"):
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"):
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

We could consider waiting until we've cut over to the new CLI. (planned for v1.4 or v1.5)

Describe alternatives you've considered

Not doing this. It's a convenience (and consistency) thing. Given some recent comments on #5411, it sounds like this would help some people

Who will this benefit?

People who want to deploy dbt projects nested in subdirectories of larger repos, and want to set an env var once, rather than passing the --project-dir flag into every command

Are you interested in contributing this feature?

I think this could be a good second issue for a motivated community contributor!

Anything else?

No response

@jtcohen6 jtcohen6 added enhancement New feature or request help_wanted Trickier changes, with a clear starting point, good for previous/experienced contributors Team:Execution labels Oct 17, 2022
@github-actions github-actions bot changed the title [Feature] DBT_PROJECT_DIR env var [CT-1357] [Feature] DBT_PROJECT_DIR env var Oct 17, 2022
@dbeatty10
Copy link
Contributor

It's very easy to do this using the new CLI framework:

Yeah! Hip, hip, hooray for the new CLI framework! Nothing better than a one-liner 💪

We could consider waiting until we've cut over to the new CLI. (planned for v1.4 or v1.5)

Agreed that this would be a good second issue for a motivated community contributor. I would affirm the option to wait until we've cut over to the new CLI If such a person doesn't emerge.

@aaronsteers
Copy link
Contributor

Hi, @dbeatty10, @jtcohen6 - is it correct that it's not possible to use the extension today if dbt_project.yml is not in the root directory?

I've tried numerous workarounds with no luck as of yet. Then I found this issue. 😄

Thanks!

@dbeatty10
Copy link
Contributor

Yep, that sounds right @aaronsteers

Let's say you have an environment variable named DBT_PROJECT_DIR.

Then here's a couple options using zsh/bash:

  1. dbt build --project-dir $DBT_PROJECT_DIR
  2. (cd $DBT_PROJECT_DIR && dbt build)

Once this issue is resolved and included in a release, then you'd be able to do the following, no matter the current working directory:

dbt build

leo-schick added a commit to leo-schick/dbt-core that referenced this issue Jan 19, 2023
leo-schick added a commit to leo-schick/dbt-core that referenced this issue Jan 19, 2023
@leo-schick
Copy link
Contributor

@dbeatty10 @jtcohen6 I created a PR for this. Can someone do a review on it?

leo-schick pushed a commit to leo-schick/dbt-core that referenced this issue Feb 18, 2023
leo-schick pushed a commit to leo-schick/dbt-core that referenced this issue Feb 18, 2023
leo-schick pushed a commit to leo-schick/dbt-core that referenced this issue Feb 18, 2023
ChenyuLInx pushed a commit that referenced this issue Mar 9, 2023
peterallenwebb pushed a commit that referenced this issue Mar 14, 2023
peterallenwebb added a commit that referenced this issue Mar 22, 2023
* ct-2198: clean up some type names and uses

* CT-2198: Unify constraints and constraints_check properties on columns

* Make mypy version consistently 0.981 (#7134)

* CT 1808 diff based partial parsing (#6873)

* model contracts on models materialized as views (#7120)

* first pass

* rename tests

* fix failing test

* changelog

* fix functional test

* Update core/dbt/parser/base.py

* Update core/dbt/parser/schemas.py

* Create method for env var deprecation (#7086)

* update to allow adapters to change model name resolution in py models (#7115)

* update to allow adapters to change model name resolution in py models

* add changie

* fix newline adds

* move quoting into macro

* use single quotes

* add env DBT_PROJECT_DIR support #6078 (#6659)

Co-authored-by: Jeremy Cohen <[email protected]>

* Add new index.html and changelog yaml files from dbt-docs (#7141)

* Make version configs optional (#7060)

* [CT-1584] New top level commands: interactive compile (#7008)

Co-authored-by: Github Build Bot <[email protected]>

* CT-2198: Add changelog entry

* CT-2198: Fix tests which broke after merge

* CT-2198: Add explicit validation of constraint types w/ unit test

* CT-2198: Move access property, per code review

* CT-2198: Remove a redundant macro

* CT-1298: Rework constraints to be adapter-generated in Python code

* CT-2198: Clarify function name per review

---------

Co-authored-by: Gerda Shank <[email protected]>
Co-authored-by: Emily Rockman <[email protected]>
Co-authored-by: Stu Kilgore <[email protected]>
Co-authored-by: colin-rogers-dbt <[email protected]>
Co-authored-by: Leo Schick <[email protected]>
Co-authored-by: Jeremy Cohen <[email protected]>
Co-authored-by: FishtownBuildBot <[email protected]>
Co-authored-by: dave-connors-3 <[email protected]>
Co-authored-by: Kshitij Aranke <[email protected]>
Co-authored-by: Github Build Bot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help_wanted Trickier changes, with a clear starting point, good for previous/experienced contributors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants