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

Render docs blocks in exposures #2920

Merged
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
- Widen supported Google Cloud libraries dependencies ([#2794](https:/fishtown-analytics/dbt/pull/2794), [#2877](https:/fishtown-analytics/dbt/pull/2877)).
- 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))

### Under the hood
- Bump hologram version to 0.0.11. Add scripts/dtr.py ([#2888](https:/fishtown-analytics/dbt/issues/2840),[#2889](https:/fishtown-analytics/dbt/pull/2889))
Expand All @@ -30,6 +31,7 @@ Contributors:
- [@franloza](https:/franloza) ([#2837](https:/fishtown-analytics/dbt/pull/2837))
- [@max-sixty](https:/max-sixty) ([#2877](https:/fishtown-analytics/dbt/pull/2877))
- [@rsella](https:/rsella) ([#2892](https:/fishtown-analytics/dbt/issues/2892))
- [@joellabes](https:/joellabes) ([#2913](https:/fishtown-analytics/dbt/issues/2913))
- [@db-magnus](https:/db-magnus) ([#2892](https:/fishtown-analytics/dbt/issues/2892))

## dbt 0.19.0b1 (October 21, 2020)
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)
joellabes marked this conversation as resolved.
Show resolved Hide resolved


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
31 changes: 28 additions & 3 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',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I feel like I saw a way to add an ignore-whitespace instruction somewhere, but am doing this for now

'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
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