Skip to content

Commit

Permalink
respond to review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
benpankow committed May 22, 2024
1 parent b543870 commit 739c3fa
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 46 deletions.
38 changes: 13 additions & 25 deletions docs/content/guides/dagster/code-references.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ title: Linking to assets' code with code references | Dagster Docs
development. This guide will be updated as we roll out new features.
</Note>

Attaching code reference metadata to your Dagster assets allows you to easily view those assets' source code from the Dagster UI:
Attaching code reference metadata to your Dagster asset definitions allows you to easily view those assets' source code from the Dagster UI:

- **In local development**, navigate directly to the code backing an asset in your editor
- **In Dagster+**, link to source code in your source control repository to see the full change history for an asset
- **In your production environment**, link to source code in your source control repository to see the full change history for an asset

In this guide, we'll show you how to automatically and manually attach code references to your Dagster assets.

Expand All @@ -22,7 +22,7 @@ In this guide, we'll show you how to automatically and manually attach code refe

To complete the steps in this guide, you'll need:

- A Dagster repository with assets that you want to link to code
- A set of Dagster asset definitions that you want to link to code
- Dagster version `1.7.6` or newer

---
Expand All @@ -44,14 +44,7 @@ def my_asset(): ...
def another_asset(): ...


defs = Definitions(
assets=with_source_code_references(
[
my_asset,
another_asset,
]
)
)
defs = Definitions(assets=with_source_code_references([my_asset, another_asset]))
```

A link to the asset's source in `with_source_code_references.py` will then be visible in the **Asset Catalog** view in the Dagster UI:
Expand All @@ -71,14 +64,13 @@ A link to the asset's source in `with_source_code_references.py` will then be vi

In some cases, you may want to manually attach code references to your asset definitions. Some assets may have a more complex source structure, such as an asset whose definition is spread across multiple Python source files or an asset which is partially defined with a `.sql` model file.

To manually attach code references to an asset definition, use an instance of `dagster._core.definitions.metadata.CodeReferencesMetadataSet`. You can then choose to augment these manual references with `with_source_code_references`:
To manually attach code references to an asset definition, use `CodeReferencesMetadataValue`. You can then choose to augment these manual references with `with_source_code_references`:

```python file=/guides/dagster/code_references/manual_references.py
import os

from dagster import Definitions, asset
from dagster._core.definitions.metadata import (
CodeReferencesMetadataSet,
CodeReferencesMetadataValue,
LocalFileCodeReference,
with_source_code_references,
Expand All @@ -87,18 +79,14 @@ from dagster._core.definitions.metadata import (

@asset(
metadata={
**CodeReferencesMetadataSet(
code_references=CodeReferencesMetadataValue(
code_references=[
LocalFileCodeReference(
file_path=os.path.join(
os.path.dirname(__file__), "source.yaml"
),
line_number=1,
label="Model YAML",
)
]
)
"dagster/code_references": CodeReferencesMetadataValue(
code_references=[
LocalFileCodeReference(
file_path=os.path.join(os.path.dirname(__file__), "source.yaml"),
line_number=1,
label="Model YAML",
)
]
)
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from dagster import Definitions, asset
from dagster._core.definitions.metadata import (
CodeReferencesMetadataSet,
CodeReferencesMetadataValue,
LocalFileCodeReference,
with_source_code_references,
Expand All @@ -11,18 +10,14 @@

@asset(
metadata={
**CodeReferencesMetadataSet(
code_references=CodeReferencesMetadataValue(
code_references=[
LocalFileCodeReference(
file_path=os.path.join(
os.path.dirname(__file__), "source.yaml"
),
line_number=1,
label="Model YAML",
)
]
)
"dagster/code_references": CodeReferencesMetadataValue(
code_references=[
LocalFileCodeReference(
file_path=os.path.join(os.path.dirname(__file__), "source.yaml"),
line_number=1,
label="Model YAML",
)
]
)
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,4 @@ def my_asset(): ...
def another_asset(): ...


defs = Definitions(
assets=with_source_code_references(
[
my_asset,
another_asset,
]
)
)
defs = Definitions(assets=with_source_code_references([my_asset, another_asset]))

0 comments on commit 739c3fa

Please sign in to comment.