Skip to content
Open
Show file tree
Hide file tree
Changes from all 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: 1 addition & 1 deletion .github/workflows/tests-dbt-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
pip install -q coverage pylint
pip install -q dbt-core==${{ inputs.dbt-version }}.* dbt-duckdb==${{ inputs.dbt-version }}.* --force-reinstall --upgrade
# FIX for protobuf issue: https://github.com/dbt-labs/dbt-core/issues/9759
pip install -q "apache-airflow<3.0.0" "protobuf>=4.25.3,<5.0.0" "opentelemetry-proto<1.28.0" --prefer-binary
pip install -q "apache-airflow<3.0.0" "opentelemetry-proto<1.28.0" --prefer-binary
pip install -q .[test] --prefer-binary
pip install -q dbt-core==${{ inputs.dbt-version }}.* dbt-duckdb==${{ inputs.dbt-version }}.* --force-reinstall --upgrade
python --version
Expand Down
20 changes: 20 additions & 0 deletions opendbt/__main__.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,39 @@
import argparse
import os
from pathlib import Path

from opendbt import OpenDbtCli, default_project_dir, default_profiles_dir


class EnvDefault(argparse.Action):
def __init__(
self, option_strings, dest, envvar, required=True, default=None, **kwargs
):
default = os.environ.get(envvar, default)
if required and default:
required = False
super().__init__(
option_strings, dest, default=default, required=required, **kwargs
)

def __call__(self, parser, namespace, values, option_string=None):
setattr(namespace, self.dest, values)


def main():
parser = argparse.ArgumentParser(description="OpenDBT CLI")
parser.add_argument(
"--project-dir",
default=None,
action=EnvDefault,
envvar="DBT_PROJECT_DIR",
help="Path to the dbt project directory. Defaults to the DBT_PROJECT_DIR environment variable or the current working directory.",
)
parser.add_argument(
"--profiles-dir",
default=None,
action=EnvDefault,
envvar="DBT_PROFILES_DIR",
help="Path to the dbt profiles directory. Defaults to the DBT_PROFILES_DIR environment variable.",
)
ns, args = parser.parse_known_args()
Copy link
Member

Choose a reason for hiding this comment

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

Thank you @anentropic adding it, would it be simpler to add if else block instead? what do you think?

if ns.project_dir:
    project_dir = Path(ns.project_dir)
elif os.getenv("DBT_PROJECT_DIR"):
    project_dir = Path(os.getenv("DBT_PROJECT_DIR"))
else:
    project_dir = default_project_dir()

Expand Down