Skip to content

Commit

Permalink
WIP: Compile assets as part of docs generate
Browse files Browse the repository at this point in the history
  • Loading branch information
clrcrl committed Jul 12, 2020
1 parent 7bd18ef commit 17acc68
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/dbt/compilation.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,5 +263,6 @@ def compile_node(adapter, config, node, manifest, extra_context, write=True):
'compiled',
node.injected_sql
)
# import ipdb; ipdb.set_trace()

return node
4 changes: 4 additions & 0 deletions core/dbt/config/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ class Project:
test_paths: List[str]
analysis_paths: List[str]
docs_paths: List[str]
asset_paths: List[str]
target_path: str
snapshot_paths: List[str]
clean_targets: List[str]
Expand Down Expand Up @@ -401,6 +402,7 @@ def from_project_config(
)

docs_paths: List[str] = value_or(cfg.docs_paths, all_source_paths)
asset_paths: List[str] = value_or(cfg.asset_paths, ['static'])
target_path: str = value_or(cfg.target_path, 'target')
clean_targets: List[str] = value_or(cfg.clean_targets, [target_path])
log_path: str = value_or(cfg.log_path, 'logs')
Expand Down Expand Up @@ -475,6 +477,7 @@ def from_project_config(
test_paths=test_paths,
analysis_paths=analysis_paths,
docs_paths=docs_paths,
asset_paths=asset_paths,
target_path=target_path,
snapshot_paths=snapshot_paths,
clean_targets=clean_targets,
Expand Down Expand Up @@ -527,6 +530,7 @@ def to_project_config(self, with_packages=False):
'test-paths': self.test_paths,
'analysis-paths': self.analysis_paths,
'docs-paths': self.docs_paths,
'asset-paths': self.asset_paths,
'target-path': self.target_path,
'snapshot-paths': self.snapshot_paths,
'clean-targets': self.clean_targets,
Expand Down
2 changes: 2 additions & 0 deletions core/dbt/config/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def from_parts(
test_paths=project.test_paths,
analysis_paths=project.analysis_paths,
docs_paths=project.docs_paths,
asset_paths=project.asset_paths,
target_path=project.target_path,
snapshot_paths=project.snapshot_paths,
clean_targets=project.clean_targets,
Expand Down Expand Up @@ -488,6 +489,7 @@ def from_parts(
test_paths=project.test_paths,
analysis_paths=project.analysis_paths,
docs_paths=project.docs_paths,
asset_paths=project.asset_paths,
target_path=project.target_path,
snapshot_paths=project.snapshot_paths,
clean_targets=project.clean_targets,
Expand Down
2 changes: 2 additions & 0 deletions core/dbt/contracts/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ class ProjectV1(HyphenatedJsonSchemaMixin, Replaceable):
test_paths: Optional[List[str]] = None
analysis_paths: Optional[List[str]] = None
docs_paths: Optional[List[str]] = None
asset_paths: Optional[List[str]] = None
target_path: Optional[str] = None
snapshot_paths: Optional[List[str]] = None
clean_targets: Optional[List[str]] = None
Expand Down Expand Up @@ -204,6 +205,7 @@ class ProjectV2(HyphenatedJsonSchemaMixin, Replaceable):
test_paths: Optional[List[str]] = None
analysis_paths: Optional[List[str]] = None
docs_paths: Optional[List[str]] = None
asset_paths: Optional[List[str]] = None
target_path: Optional[str] = None
snapshot_paths: Optional[List[str]] = None
clean_targets: Optional[List[str]] = None
Expand Down
1 change: 1 addition & 0 deletions core/dbt/task/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def after_execute(self, result):
def execute(self, compiled_node, manifest):
return RunModelResult(compiled_node)

# maybe
def compile(self, manifest):
return compile_node(self.adapter, self.config, self.node, manifest, {})

Expand Down
10 changes: 10 additions & 0 deletions core/dbt/task/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,16 @@ def run(self) -> CatalogResults:
DOCS_INDEX_FILE_PATH,
os.path.join(self.config.target_path, 'index.html'))

for asset_path in self.config.asset_paths:
to_asset_path=os.path.join(self.config.target_path, asset_path)

if os.path.exists(to_asset_path):
shutil.rmtree(to_asset_path)

shutil.copytree(
asset_path,
to_asset_path)

if self.manifest is None:
raise InternalException(
'self.manifest was None in run!'
Expand Down
4 changes: 4 additions & 0 deletions test/unit/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,7 @@ def test_defaults(self):
self.assertEqual(project.test_paths, ['test'])
self.assertEqual(project.analysis_paths, [])
self.assertEqual(project.docs_paths, ['models', 'data', 'snapshots', 'macros'])
self.assertEqual(project.asset_paths), ['static'])
self.assertEqual(project.target_path, 'target')
self.assertEqual(project.clean_targets, ['target'])
self.assertEqual(project.log_path, 'logs')
Expand Down Expand Up @@ -636,6 +637,7 @@ def test_all_overrides(self):
'test-paths': ['other-test'],
'analysis-paths': ['analysis'],
'docs-paths': ['docs'],
'asset-paths': ['assets'],
'target-path': 'other-target',
'clean-targets': ['another-target'],
'log-path': 'other-logs',
Expand Down Expand Up @@ -700,6 +702,7 @@ def test_all_overrides(self):
self.assertEqual(project.test_paths, ['other-test'])
self.assertEqual(project.analysis_paths, ['analysis'])
self.assertEqual(project.docs_paths, ['docs'])
self.assertEqual(project.asset_paths, ['assets'])
self.assertEqual(project.target_path, 'other-target')
self.assertEqual(project.clean_targets, ['another-target'])
self.assertEqual(project.log_path, 'other-logs')
Expand Down Expand Up @@ -1186,6 +1189,7 @@ def test_from_args(self):
self.assertEqual(config.test_paths, ['test'])
self.assertEqual(config.analysis_paths, [])
self.assertEqual(config.docs_paths, ['models', 'data', 'snapshots', 'macros'])
self.assertEqual(config.asset_paths, ['static'])
self.assertEqual(config.target_path, 'target')
self.assertEqual(config.clean_targets, ['target'])
self.assertEqual(config.log_path, 'logs')
Expand Down

0 comments on commit 17acc68

Please sign in to comment.