Skip to content

Commit

Permalink
Merge pull request #458 from DataRecce/feature/drc-721-feature-suppor…
Browse files Browse the repository at this point in the history
…t-a-different-path-for-the-production-manifest

[Feature] Allow custom target path and target base path for recce server
  • Loading branch information
wcchang1115 authored Oct 22, 2024
2 parents bfea880 + 86005ea commit 8ff1462
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
24 changes: 14 additions & 10 deletions recce/adapter/dbt_adapter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ def load(cls,
**kwargs):

target = kwargs.get('target')
target_path = kwargs.get('target_path', 'target')
target_base_path = kwargs.get('target_base_path', 'target-base')

profile_name = kwargs.get('profile')
project_dir = kwargs.get('project_dir')
profiles_dir = kwargs.get('profiles_dir')
Expand All @@ -199,7 +202,7 @@ def load(cls,
args = DbtArgs(
threads=1,
target=target,
target_path='target',
target_path=target_path,
project_dir=project_dir,
profiles_dir=profiles_dir,
profile=profile_name,
Expand Down Expand Up @@ -234,17 +237,18 @@ def load(cls,
runtime_config=runtime_config,
adapter=adapter,
review_mode=review,
base_path=target_base_path
)
except DbtProjectError as e:
raise e

# Load the artifacts from the state file or `target` and `target-base` directory
# Load the artifacts from the state file or dbt target and dbt base directory
if not no_artifacts and not review:
dbt_adapter.load_artifacts()
if not dbt_adapter.curr_manifest:
raise Exception('Cannot load "target/manifest.json"')
raise Exception(f'Cannot load "{runtime_config.target_path}/manifest.json"')
if not dbt_adapter.base_manifest:
raise Exception('Cannot load "target-base/manifest.json"')
raise Exception(f'Cannot load "{target_base_path}/manifest.json"')
return dbt_adapter

def print_lineage_info(self):
Expand Down Expand Up @@ -328,7 +332,7 @@ def load_artifacts(self):

project_root = self.runtime_config.project_root
target_path = self.runtime_config.target_path
target_base_path = 'target-base'
target_base_path = self.base_path
self.target_path = os.path.join(project_root, target_path)
self.base_path = os.path.join(project_root, target_base_path)

Expand All @@ -354,7 +358,7 @@ def load_artifacts(self):
# set the manifest
self.manifest = as_manifest(curr_manifest)
self.previous_state = previous_state(
Path('target-base'),
Path(target_base_path),
Path(self.runtime_config.target_path),
Path(self.runtime_config.project_root),
)
Expand Down Expand Up @@ -605,7 +609,7 @@ def set_artifacts(self,
self.base_manifest = base_manifest
self.manifest = manifest
self.previous_state = previous_state(
Path('target-base'),
Path(self.base_path),
Path(self.runtime_config.target_path),
Path(self.runtime_config.project_root)
)
Expand Down Expand Up @@ -704,11 +708,11 @@ def _load_artifact(artifact):

def export_artifacts_from_file(self) -> ArtifactsRoot:
'''
Export the artifacts from the state file. This is the old impolementation
Export the artifacts from the state file. This is the old implementation
'''
artifacts = ArtifactsRoot()
target_path = self.runtime_config.target_path
target_base_path = 'target-base'
target_base_path = self.base_path

def _load_artifact(path):
if not os.path.isfile(path):
Expand Down Expand Up @@ -751,7 +755,7 @@ def _select_artifact(

self.manifest = as_manifest(self.curr_manifest)
self.previous_state = previous_state(
Path('target-base'),
Path(self.base_path),
Path(self.runtime_config.target_path),
Path(self.runtime_config.project_root)
)
Expand Down
9 changes: 9 additions & 0 deletions recce/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ def _add_options(func):
envvar='RECCE_STATE_PASSWORD'),
]

recce_dbt_artifact_dir_options = [
click.option('--target-path', help='dbt artifacts directory for your development branch.',
type=click.STRING, default='target'),
click.option('--target-base-path', help='dbt artifacts directory to be used as the base for the comparison.',
type=click.STRING, default='target-base'),
]


def _execute_sql(context, sql_template, base=False):
try:
Expand Down Expand Up @@ -186,6 +193,7 @@ def diff(sql, primary_keys: List[str] = None, keep_shape: bool = False, keep_equ
@add_options(dbt_related_options)
@add_options(sqlmesh_related_options)
@add_options(recce_options)
@add_options(recce_dbt_artifact_dir_options)
@add_options(recce_cloud_options)
def server(host, port, state_file=None, **kwargs):
"""
Expand Down Expand Up @@ -271,6 +279,7 @@ def server(host, port, state_file=None, **kwargs):
@add_options(dbt_related_options)
@add_options(sqlmesh_related_options)
@add_options(recce_options)
@add_options(recce_dbt_artifact_dir_options)
@add_options(recce_cloud_options)
def run(output, **kwargs):
"""
Expand Down

0 comments on commit 8ff1462

Please sign in to comment.