Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Split up write_node into "node_compiled_path" and "write_node" functions
so that we only store the relative path at node.compiled_path
  • Loading branch information
gshank committed May 25, 2023
commit db8cd1101396d3649b87d703055af8c7f15fc504
5 changes: 2 additions & 3 deletions core/dbt/compilation.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,9 +556,8 @@ def _write_node(self, node: ManifestSQLNode) -> ManifestSQLNode:
fire_event(WritingInjectedSQLForNode(node_info=get_node_info()))

if node.compiled_code:
node.compiled_path = node.write_node(
self.config.project_target_path, "compiled", node.compiled_code
)
node.compiled_path = node.get_compiled_path(self.config.target_path, "compiled")
node.write_node(self.config.project_root, node.compiled_path, node.compiled_code)
return node

def compile_node(
Expand Down
7 changes: 5 additions & 2 deletions core/dbt/config/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,5 +703,8 @@ def get_macro_search_order(self, macro_namespace: str):

@property
def project_target_path(self):
path = os.path.join(self.project_root, self.target_path)
return path
if os.path.isabs(self.target_path):
return self.target_path
else:
path = os.path.join(self.project_root, self.target_path)
return path
13 changes: 9 additions & 4 deletions core/dbt/contracts/graph/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,17 +345,22 @@ class ParsedNode(NodeInfoMixin, ParsedNodeMandatory, SerializableType):
relation_name: Optional[str] = None
raw_code: str = ""

def write_node(self, target_path: str, subdirectory: str, payload: str):
def get_compiled_path(self, target_path: str, subdirectory: str):
if os.path.basename(self.path) == os.path.basename(self.original_file_path):
# One-to-one relationship of nodes to files.
path = self.original_file_path
else:
# Many-to-one relationship of nodes to files.
path = os.path.join(self.original_file_path, self.path)
full_path = os.path.join(target_path, subdirectory, self.package_name, path)
compiled_path = os.path.join(target_path, subdirectory, self.package_name, path)
return compiled_path

write_file(full_path, payload)
return full_path
def write_node(self, project_root: str, compiled_path, compiled_code: str):
if os.path.isabs(compiled_path):
full_path = compiled_path
else:
full_path = os.path.join(project_root, compiled_path)
write_file(full_path, compiled_code)

def _serialize(self):
return self.to_dict()
Expand Down