-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Fix windows long paths #2566
Fix windows long paths #2566
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,15 +2,19 @@ | |
import json | ||
import os | ||
import random | ||
import shutil | ||
import tempfile | ||
import time | ||
from datetime import datetime | ||
from unittest.mock import ANY, patch | ||
|
||
from pytest import mark | ||
from test.integration.base import DBTIntegrationTest, use_profile, AnyFloat, \ | ||
AnyString, AnyStringWith, normalize, Normalized | ||
|
||
from dbt.exceptions import CompilationException | ||
|
||
|
||
def _read_file(path): | ||
with open(path, 'r') as fp: | ||
return fp.read().replace('\r', '').replace('\\r', '') | ||
|
@@ -3180,3 +3184,65 @@ def test_postgres_override_used(self): | |
self.run_dbt(['docs', 'generate']) | ||
|
||
self.assertIn('rejected: no catalogs for you', str(exc.exception)) | ||
|
||
|
||
@mark.skipif(os.name != 'nt', reason='This is only relevant on windows') | ||
class TestDocsGenerateLongWindowsPaths(DBTIntegrationTest): | ||
def _generate_test_root_dir(self): | ||
assert os.name == 'nt' | ||
magic_prefix = '\\\\?\\' | ||
|
||
# tempfile.mkdtemp doesn't use `\\?\` by default so we have to | ||
# get a tiny bit creative. | ||
temp_dir = tempfile.gettempdir() | ||
if not temp_dir.startswith(magic_prefix): | ||
temp_dir = magic_prefix + temp_dir | ||
outer = tempfile.mkdtemp(prefix='dbt-int-test-', dir=temp_dir) | ||
# then inside _that_ directory make a new one that gets us to just | ||
# barely 260 total. I picked 250 to account for the '\' and anything | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there a reason we want to just barely eclipse 260 chars instead of going for, say, 300 chars? I just want to make sure I understand the logic behind this test. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah! We have to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks, i hate it |
||
# else. The key is that len(inner) + len('target\\compiled\\...') will | ||
# be >260 chars | ||
new_length = 250 - len(outer) | ||
inner = os.path.join(outer, 'a'*new_length) | ||
os.mkdir(inner) | ||
return normalize(inner) | ||
|
||
def _symlink_test_folders(self): | ||
# dbt's normal symlink behavior breaks this test, so special-case it | ||
for entry in os.listdir(self.test_original_source_path): | ||
src = os.path.join(self.test_original_source_path, entry) | ||
tst = os.path.join(self.test_root_dir, entry) | ||
if entry == 'trivial_models': | ||
shutil.copytree(src, tst) | ||
elif entry == 'local_dependency': | ||
continue | ||
elif os.path.isdir(entry) or entry.endswith('.sql'): | ||
os.symlink(src, tst) | ||
|
||
@property | ||
def schema(self): | ||
return 'docs_generate_029' | ||
|
||
@staticmethod | ||
def dir(path): | ||
return normalize(path) | ||
|
||
@property | ||
def models(self): | ||
return self.dir("trivial_models") | ||
|
||
def run_and_generate(self): | ||
self.assertEqual(len(self.run_dbt(['run'])), 1) | ||
os.remove(normalize('target/manifest.json')) | ||
os.remove(normalize('target/run_results.json')) | ||
self.run_dbt(['docs', 'generate']) | ||
|
||
@use_profile('postgres') | ||
def test_postgres_long_paths(self): | ||
self.run_and_generate() | ||
# this doesn't use abspath, so all should be well here | ||
manifest = _read_json('./target/manifest.json') | ||
self.assertIn('nodes', manifest) | ||
assert os.path.exists('./target/run/test/trivial_models/model.sql') | ||
self.run_dbt(['clean']) | ||
assert not os.path.exists('./target/run') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍