Skip to content

Commit

Permalink
Make a docs-paths, if unset it defaults to source-paths
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob Beck committed Aug 2, 2018
1 parent 777510e commit 9f9baf2
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dbt/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def load_project(cls, root_project, all_projects, project, project_name,
root_project=root_project,
all_projects=all_projects,
root_dir=project.get('project-root'),
relative_dirs=project.get('source-paths', []))
relative_dirs=project.get('docs-paths', []))

# node loaders
GraphLoader.register(ModelLoader)
Expand Down
2 changes: 1 addition & 1 deletion dbt/parser/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ def parse_model(cls, model, package_name, root_dir, path, root_project,
yield 'test', node

context = {'doc': dbt.context.parser.docs(model, docrefs)}
description = model.get('description')
description = model.get('description', '')
dbt.clients.jinja.get_rendered(description, context)

patch = ParsedNodePatch(
Expand Down
3 changes: 3 additions & 0 deletions dbt/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ def __init__(self, cfg, profiles, profiles_dir, profile_to_load=None,

self.cfg = default_project_cfg.copy()
self.cfg.update(cfg)
# docs paths defaults to the exact value of source-paths
if 'docs-paths' not in self.cfg:
self.cfg['docs-paths'] = self.cfg['source-paths'].copy()
self.profiles = default_profiles.copy()
self.profiles.update(profiles)
self.profiles_dir = profiles_dir
Expand Down
17 changes: 17 additions & 0 deletions test/integration/035_docs_blocks/docs/docs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% docs my_model_doc %}
Alt text about the model
{% enddocs %}

{% docs my_model_doc__id %}
The user ID number with alternative text
{% enddocs %}

The following doc is never used, which should be fine.
{% docs my_model_doc__first_name %}
The user's first name - don't show this text!
{% enddocs %}

This doc is referenced by its full name
{% docs my_model_doc__last_name %}
The user's last name in this other file
{% enddocs %}
2 changes: 1 addition & 1 deletion test/integration/035_docs_blocks/models/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The user ID number

The following doc is never used, which should be fine.
{% docs my_model_doc__first_name %}
The user's first name
The user's first name (should not be shown!)
{% enddocs %}

This doc is referenced by its full name
Expand Down
48 changes: 47 additions & 1 deletion test/integration/035_docs_blocks/test_docs_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,50 @@ def test_valid_doc_ref(self):
)
self.assertEqual(len(model_data['columns']), 3)

@use_profile('postgres')
def test_alternative_docs_path(self):
self.use_default_project({"docs-paths": [self.dir("docs")]})
self.assertEqual(len(self.run_dbt()), 1)

self.assertTrue(os.path.exists('./target/manifest.json'))

with open('./target/manifest.json') as fp:
manifest = json.load(fp)

model_data = manifest['nodes']['model.test.model']
self.assertEqual(
model_data['description'],
'Alt text about the model'
)
self.assertIn(
{
'name': 'id',
'description': 'The user ID number with alternative text'
},
model_data['columns']
)
self.assertIn(
{
'name': 'first_name',
'description': "The user's first name",
},
model_data['columns']
)

self.assertIn(
{
'name': 'last_name',
'description': "The user's last name in this other file",
},
model_data['columns']
)
self.assertEqual(len(model_data['columns']), 3)

@use_profile('postgres')
def test_alternative_docs_path_missing(self):
self.use_default_project({"docs-paths": [self.dir("not-docs")]})
with self.assertRaises(dbt.exceptions.CompilationException):
self.run_dbt()

class TestMissingDocsBlocks(DBTIntegrationTest):
@property
Expand All @@ -80,7 +124,7 @@ def models(self):
def test_missing_doc_ref(self):
# The run should fail since we could not find the docs reference.
with self.assertRaises(dbt.exceptions.CompilationException):
self.run_dbt(expect_pass=False)
self.run_dbt()

class TestBadDocsBlocks(DBTIntegrationTest):
@property
Expand All @@ -102,3 +146,5 @@ def test_invalid_doc_ref(self):
# The run should fail since we could not find the docs reference.
with self.assertRaises(dbt.exceptions.CompilationException):
self.run_dbt(expect_pass=False)


0 comments on commit 9f9baf2

Please sign in to comment.