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

Feature: Block-level copying of Jinja content between split projects #192

Merged

Conversation

nicholasyager
Copy link
Collaborator

@nicholasyager nicholasyager commented Dec 29, 2023

Description and Motivation

There are two PRs related to copying Jinja blocks to split dbt projects. One has to do with block-level copying of macros, to prevent multiple macros in the same file being copyied to a split project, and the other has to do with doc blocks not being copied over due to an absence of references. This PR resolves both issues.

  1. This PR creates a new data structure for keeping track of JinjaBlocks at a character position level. This is accomplished by using docs and macros properties of a Manifest, coupled with some clever RegEx, to find where things start and end. Note that the RegEx may be brittle, so 👀
  2. Adds an append Operation to our file editors, allowing us to append-only edit files (like if we're moving a Jinja block from one place to another!).
  3. Adds reference tracking code to DbtSubProject so we know which doc blocks are being referenced in which code and patch files. This allows us to track which Doc blocks need to be copied, too!
  4. Add new tests and update existing tests!

Resolves: #142
Resolves: #158

@nicholasyager nicholasyager added bug Something isn't working enhancement New feature or request labels Dec 29, 2023
@nicholasyager nicholasyager self-assigned this Dec 29, 2023
@nicholasyager nicholasyager marked this pull request as ready for review December 29, 2023 02:37
Copy link
Collaborator

@dave-connors-3 dave-connors-3 left a comment

Choose a reason for hiding this comment

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

i dig it! nice work on this

dbt_meshify/storage/jinja_blocks.py Outdated Show resolved Hide resolved
dbt_meshify/dbt_projects.py Show resolved Hide resolved
if node is None:
continue

if hasattr(node, "raw_code"):
Copy link
Collaborator

Choose a reason for hiding this comment

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

forgetting which nodes have raw_code -- does this indicate we'd be searching the content of a model for docs blocks? are we looking for docs in the definition of YML only resources in this step?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think you've figured this out already, but yes. This checks raw_code, and the next check on line 482 checks wihtin the YAML file, too.

if hasattr(node, "raw_code"):
docs.update(find_doc_reference(node.raw_code))

if hasattr(node, "patch_path"):
Copy link
Collaborator

Choose a reason for hiding this comment

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

ah i think this answers my above question

@@ -53,7 +58,8 @@ models:
to: ref('stg_customers')
field: customer_id
- name: location_id
description: The foreign key relating to the location the order was placed
description:
Copy link
Collaborator

Choose a reason for hiding this comment

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

a note for future us -- we gotta see if ruamel can stop editing newlines 😅

@nicholasyager nicholasyager merged commit 207be4a into dbt-labs:main Jan 2, 2024
1 check passed
@nicholasyager nicholasyager deleted the feature/jinja_block_support branch January 2, 2024 19:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
2 participants