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

Avoid recursing when installing a project to a subproject via copytree #9734

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

djbelknap
Copy link

resolves #9719

Problem

When installing a local package that contains the current project as a subfolder (like the integration_tests project in dbt-utils), if the symlink fails the copytree recursively copies the current project repeatedly until the path length limit is reached.

Solution

Use the ignore parameter of copytree to ignore the current project's packages directory to avoid repeated recursion.

Checklist

  • I have read the contributing guide and understand what's expected of me
  • I have run this code in development and it appears to resolve the stated issue
  • This PR includes tests, or tests are not required/relevant for this PR (Let me know if you'd like a test specific to this fix)
  • This PR has no interface changes (e.g. macros, cli, logs, json artifacts, config files, adapter interface, etc) or this PR has already received feedback and approval from Product or DX
  • This PR includes type annotations for new and modified functions

@djbelknap djbelknap requested a review from a team as a code owner March 7, 2024 14:51
Copy link

cla-bot bot commented Mar 7, 2024

Thanks for your pull request, and welcome to our community! We require contributors to sign our Contributor License Agreement and we don't seem to have your signature on file. Check out this article for more information on why we have a CLA.

In order for us to review and merge your code, please submit the Individual Contributor License Agreement form attached above above. If you have questions about the CLA, or if you believe you've received this message in error, please reach out through a comment on this PR.

CLA has not been signed by users: @djbelknap

Copy link
Contributor

github-actions bot commented Mar 7, 2024

Thank you for your pull request! We could not find a changelog entry for this change. For details on how to document a change, see the contributing guide.

@cla-bot cla-bot bot added the cla:yes label Mar 7, 2024
@dbeatty10 dbeatty10 added the community This PR is from a community member label Mar 22, 2024
@graciegoheen graciegoheen added the ready_for_review Externally contributed PR has functional approval, ready for code review from Core engineering label Jun 17, 2024
@graciegoheen graciegoheen assigned dbeatty10 and unassigned dbeatty10 Jun 17, 2024
@emmyoop emmyoop closed this Jul 16, 2024
@emmyoop emmyoop reopened this Jul 16, 2024
Copy link

codecov bot commented Jul 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.84%. Comparing base (33161a3) to head (e10b698).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9734      +/-   ##
==========================================
+ Coverage   88.82%   88.84%   +0.01%     
==========================================
  Files         180      180              
  Lines       22584    22584              
==========================================
+ Hits        20060    20064       +4     
+ Misses       2524     2520       -4     
Flag Coverage Δ
integration 86.13% <0.00%> (+<0.01%) ⬆️
unit 62.15% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
Unit Tests 62.15% <100.00%> (ø)
Integration Tests 86.13% <0.00%> (+<0.01%) ⬆️

Comment on lines +70 to +76
shutil.copytree(
src_path,
dest_path,
ignore=lambda directory, contents: project.packages_install_path
if directory == project.project_root
else [],
)
Copy link
Contributor

@dbeatty10 dbeatty10 Jul 16, 2024

Choose a reason for hiding this comment

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

What

"Don't install yourself into your own dbt_packages folder."

How

shutil.copytree recursively copies an entire directory tree rooted at src to a directory named dst.

The new ignore parameter introduces a base case under which this recursion should stop. It essentially says:

"No dbt project ever needs to install itself within its own packages_install_path folder 😄. So when the current directory being processed is the same as this dbt project, then do not recursively copy the configured packages_install_path directory because it's already covered. Just ignore it!"

Why

The ignore parameter is being added here to prevent a dbt project from installing itself via dbt deps. As mentioned in #9719, this can happen if:

  1. a dbt project is a subfolder of a local dependency listed within packages.yml, and
  2. the host operating system doesn't support symlinks.

The 1st item is common for CI testing for packages like dbt_utils, and the 2nd is most common in legacy versions of Windows.

Copy link
Contributor

Choose a reason for hiding this comment

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

Windows 10 users can possibly avoid this code path by turning on Developer Mode (which may allow creating Symbolic Links without requiring admin privileges) [1].

But this PR is specifically intended to cover the case where the user's system doesn't allow symlinks for whatever reason. So Developer Mode for Windows 10 is not a sufficient workaround for all cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla:yes community This PR is from a community member ready_for_review Externally contributed PR has functional approval, ready for code review from Core engineering
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] dbt deps automatically recognizes projects in subdirectories
4 participants