Skip to content

Commit

Permalink
Merge pull request #2920 from joellabes/2913-docs-block-exposures
Browse files Browse the repository at this point in the history
Render docs blocks in exposures
  • Loading branch information
jtcohen6 authored Dec 13, 2020
2 parents 886b574 + cd3583c commit cd149b6
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
- Increased the supported relation name length in postgres from 29 to 51 ([#2850](https:/fishtown-analytics/dbt/pull/2850))
- dbt list command always return 0 as exit code ([#2886](https:/fishtown-analytics/dbt/issues/2886), [#2892](https:/fishtown-analytics/dbt/issues/2892))
- Set default `materialized` for test node configs to `test` ([#2806](https:/fishtown-analytics/dbt/issues/2806), [#2902](https:/fishtown-analytics/dbt/pull/2902))
- Allow docs blocks in exposure descriptions ([#2913](https:/fishtown-analytics/dbt/issues/2913), [#2920](https:/fishtown-analytics/dbt/pull/2920))
- Use original file path instead of absolute path as checksum for big seeds ([#2927](https:/fishtown-analytics/dbt/issues/2927), [#2939](https:/fishtown-analytics/dbt/pull/2939))

### Under the hood
Expand All @@ -33,6 +34,7 @@ Contributors:
- [@franloza](https:/franloza) ([#2837](https:/fishtown-analytics/dbt/pull/2837))
- [@max-sixty](https:/max-sixty) ([#2877](https:/fishtown-analytics/dbt/pull/2877), [#2908](https:/fishtown-analytics/dbt/pull/2908))
- [@rsella](https:/rsella) ([#2892](https:/fishtown-analytics/dbt/issues/2892))
- [@joellabes](https:/joellabes) ([#2913](https:/fishtown-analytics/dbt/issues/2913))
- [@plotneishestvo](https:/plotneishestvo) ([#2896](https:/fishtown-analytics/dbt/issues/2896))
- [@db-magnus](https:/db-magnus) ([#2892](https:/fishtown-analytics/dbt/issues/2892))

Expand Down
2 changes: 1 addition & 1 deletion core/dbt/contracts/graph/parsed.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,9 +654,9 @@ class ParsedExposure(UnparsedBaseNode, HasUniqueID, HasFqn):
type: ExposureType
owner: ExposureOwner
resource_type: NodeType = NodeType.Exposure
description: str = ''
maturity: Optional[MaturityType] = None
url: Optional[str] = None
description: Optional[str] = None
depends_on: DependsOn = field(default_factory=DependsOn)
refs: List[List[str]] = field(default_factory=list)
sources: List[List[str]] = field(default_factory=list)
Expand Down
4 changes: 2 additions & 2 deletions core/dbt/contracts/graph/unparsed.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,11 +411,11 @@ class ExposureOwner(JsonSchemaMixin, Replaceable):


@dataclass
class UnparsedExposure(JsonSchemaMixin, Replaceable):
class UnparsedExposure(HasYamlMetadata, Replaceable):
name: str
type: ExposureType
owner: ExposureOwner
description: str = ''
maturity: Optional[MaturityType] = None
url: Optional[str] = None
description: Optional[str] = None
depends_on: List[str] = field(default_factory=list)
1 change: 1 addition & 0 deletions core/dbt/node_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def documentable(cls) -> List['NodeType']:
cls.Source,
cls.Macro,
cls.Analysis,
cls.Exposure
]

def pluralize(self) -> str:
Expand Down
14 changes: 14 additions & 0 deletions core/dbt/parser/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,12 @@ def _process_docs_for_macro(
arg.description = get_rendered(arg.description, context)


def _process_docs_for_exposure(
context: Dict[str, Any], exposure: ParsedExposure
) -> None:
exposure.description = get_rendered(exposure.description, context)


def process_docs(manifest: Manifest, config: RuntimeConfig):
for node in manifest.nodes.values():
ctx = generate_runtime_docs(
Expand All @@ -647,6 +653,14 @@ def process_docs(manifest: Manifest, config: RuntimeConfig):
config.project_name,
)
_process_docs_for_macro(ctx, macro)
for exposure in manifest.exposures.values():
ctx = generate_runtime_docs(
config,
exposure,
manifest,
config.project_name,
)
_process_docs_for_exposure(ctx, exposure)


def _process_refs_for_exposure(
Expand Down
4 changes: 4 additions & 0 deletions test/integration/029_docs_generate_tests/ref_models/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ My table
{% docs column_info %}
An ID field
{% enddocs %}

{% docs notebook_info %}
A description of the complex exposure
{% enddocs %}
12 changes: 12 additions & 0 deletions test/integration/029_docs_generate_tests/ref_models/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,15 @@ sources:
columns:
- name: id
description: "{{ doc('column_info') }}"

exposures:
- name: notebook_exposure
type: notebook
depends_on:
- ref('view_summary')
owner:
email: [email protected]
name: Some name
description: "{{ doc('notebook_info') }}"
maturity: medium
url: http://example.com/notebook/1
44 changes: 40 additions & 4 deletions test/integration/029_docs_generate_tests/test_docs_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -1567,7 +1567,7 @@ def expected_seeded_manifest(self, model_database=None, quote_model=False):
'macros': [],
'nodes': ['model.test.model', 'model.test.second_model']
},
'description': 'A description of the complex exposure',
'description': 'A description of the complex exposure\n',
'fqn': ['test', 'notebook_exposure'],
'maturity': 'medium',
'name': 'notebook_exposure',
Expand All @@ -1594,7 +1594,7 @@ def expected_seeded_manifest(self, model_database=None, quote_model=False):
'model.test.model'
],
},
'description': None,
'description': '',
'fqn': ['test', 'simple_exposure'],
'name': 'simple_exposure',
'original_file_path': self.dir('models/schema.yml'),
Expand Down Expand Up @@ -1992,7 +1992,32 @@ def expected_postgres_references_manifest(self, model_database=None):
'unrendered_config': {}
},
},
'exposures': {},
'exposures': {
'exposure.test.notebook_exposure': {
'depends_on': {
'macros': [],
'nodes': ['model.test.view_summary']
},
'description': 'A description of the complex exposure',
'fqn': ['test', 'notebook_exposure'],
'maturity': 'medium',
'name': 'notebook_exposure',
'original_file_path': self.dir('ref_models/schema.yml'),
'owner': {
'email': '[email protected]',
'name': 'Some name'
},
'package_name': 'test',
'path': 'schema.yml',
'refs': [['view_summary']],
'resource_type': 'exposure',
'root_path': self.test_root_realpath,
'sources': [],
'type': 'notebook',
'unique_id': 'exposure.test.notebook_exposure',
'url': 'http://example.com/notebook/1'
},
},
'selectors': {},
'docs': {
'dbt.__overview__': ANY,
Expand Down Expand Up @@ -2073,6 +2098,15 @@ def expected_postgres_references_manifest(self, model_database=None):
'root_path': self.test_root_realpath,
'unique_id': 'test.macro_info',
},
'test.notebook_info': {
'block_contents': 'A description of the complex exposure',
'name': 'notebook_info',
'original_file_path': docs_path,
'package_name': 'test',
'path': 'docs.md',
'root_path': self.test_root_realpath,
'unique_id': 'test.notebook_info'
},
'test.macro_arg_info': {
'block_contents': 'The model for my custom test',
'name': 'macro_arg_info',
Expand All @@ -2085,8 +2119,9 @@ def expected_postgres_references_manifest(self, model_database=None):
},
'child_map': {
'model.test.ephemeral_copy': ['model.test.ephemeral_summary'],
'exposure.test.notebook_exposure': [],
'model.test.ephemeral_summary': ['model.test.view_summary'],
'model.test.view_summary': [],
'model.test.view_summary': ['exposure.test.notebook_exposure'],
'seed.test.seed': ['snapshot.test.snapshot_seed'],
'snapshot.test.snapshot_seed': [],
'source.test.my_source.my_table': ['model.test.ephemeral_copy'],
Expand All @@ -2095,6 +2130,7 @@ def expected_postgres_references_manifest(self, model_database=None):
'model.test.ephemeral_copy': ['source.test.my_source.my_table'],
'model.test.ephemeral_summary': ['model.test.ephemeral_copy'],
'model.test.view_summary': ['model.test.ephemeral_summary'],
'exposure.test.notebook_exposure': ['model.test.view_summary'],
'seed.test.seed': [],
'snapshot.test.snapshot_seed': ['seed.test.seed'],
'source.test.my_source.my_table': [],
Expand Down
3 changes: 3 additions & 0 deletions test/unit/test_contracts_graph_parsed.py
Original file line number Diff line number Diff line change
Expand Up @@ -2017,6 +2017,7 @@ def minimal_parsed_exposure_dict():
'path': 'models/something.yml',
'root_path': '/usr/src/app',
'original_file_path': 'models/something.yml',
'description': ''
}


Expand All @@ -2041,6 +2042,7 @@ def basic_parsed_exposure_dict():
'path': 'models/something.yml',
'root_path': '/usr/src/app',
'original_file_path': 'models/something.yml',
'description': ''
}


Expand All @@ -2056,6 +2058,7 @@ def basic_parsed_exposure_object():
root_path='/usr/src/app',
original_file_path='models/something.yml',
owner=ExposureOwner(email='[email protected]'),
description=''
)


Expand Down
8 changes: 7 additions & 1 deletion test/unit/test_contracts_graph_unparsed.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,7 @@ class TestUnparsedExposure(ContractTestCase):

def get_ok_dict(self):
return {
'yaml_key': 'exposures',
'name': 'my_exposure',
'type': 'dashboard',
'owner': {
Expand All @@ -587,18 +588,23 @@ def get_ok_dict(self):
'depends_on': [
'ref("my_model")',
'source("raw", "source_table")',
]
],
'original_file_path': '/some/fake/path',
'package_name': 'test'
}

def test_ok(self):
exposure = self.ContractType(
yaml_key='exposures',
name='my_exposure',
type=ExposureType.Dashboard,
owner=ExposureOwner(email='[email protected]'),
maturity=MaturityType.Medium,
url='https://example.com/dashboards/1',
description='A exposure',
depends_on=['ref("my_model")', 'source("raw", "source_table")'],
original_file_path='/some/fake/path',
package_name='test'
)
dct = self.get_ok_dict()
self.assert_symmetric(exposure, dct)
Expand Down

0 comments on commit cd149b6

Please sign in to comment.