Skip to content

Commit

Permalink
link_to_git
Browse files Browse the repository at this point in the history
  • Loading branch information
benpankow committed Jul 8, 2024
1 parent bcb6516 commit eb645c2
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 39 deletions.
Binary file modified docs/content/api/modules.json.gz
Binary file not shown.
Binary file modified docs/content/api/searchindex.json.gz
Binary file not shown.
Binary file modified docs/content/api/sections.json.gz
Binary file not shown.
61 changes: 24 additions & 37 deletions docs/content/guides/dagster/code-references.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,14 @@ If using Dagster Plus, you can use the <PyObject module="dagster_plus" object="d
import os
from pathlib import Path

from dagster_cloud.metadata.source_code import link_to_git_if_cloud
from dagster_cloud.metadata.source_code import link_code_references_to_git_if_cloud

from dagster import Definitions, asset
from dagster._core.definitions.metadata import with_source_code_references
from dagster import (
AnchorBasedFilePathMapping,
Definitions,
asset,
with_source_code_references,
)


@asset
Expand All @@ -143,45 +147,24 @@ def another_asset(): ...


defs = Definitions(
assets=link_to_git_if_cloud(
assets=link_code_references_to_git_if_cloud(
assets_defs=with_source_code_references([my_asset, another_asset]),
# Inferred from searching for .git directory in parent directories
# of the module containing this code - may also be set explicitly
repository_root_absolute_path=Path(__file__).parent,
file_path_mapping=AnchorBasedFilePathMapping(
local_file_anchor=Path(__file__),
file_anchor_path_in_repository="src/repo.py",
),
)
)
```

### In any Dagster environment

The <PyObject module="dagster" object="dagster._core.definitions.metadata.link_to_source_control"/> utility allows you to convert local file code references to source control links. You'll need to provide the base URL of your git repository, the branch or commit hash, and a path to the repository root locally.

```python file=/guides/dagster/code_references/link_to_source_control.py
from pathlib import Path

from dagster import Definitions, asset
from dagster._core.definitions.metadata import (
link_to_source_control,
with_source_code_references,
)


@asset
def my_asset(): ...
The <PyObject module="dagster" object="dagster._core.definitions.metadata.link_to_git"/> utility allows you to convert local file code references to source control links. You'll need to provide the base URL of your git repository, the branch or commit hash, and a path to the repository root locally.


@asset
def another_asset(): ...


defs = Definitions(
assets=link_to_source_control(
assets_defs=with_source_code_references([my_asset, another_asset]),
source_control_url="https://github.com/dagster-io/dagster",
source_control_branch="main",
repository_root_absolute_path=Path(__file__).parent,
)
)
```python file=/guides/dagster/code_references/link_to_git.py
ENOENT: no such file or directory, open '/Users/ben/repos/dagster/examples/docs_snippets/docs_snippets/guides/dagster/code_references/link_to_git.py'
```

You may choose to conditionally apply this transformation based on the environment in which your Dagster code is running. For example, you could use an environment variable to determine whether to link to local files or to a source control repository:
Expand All @@ -192,7 +175,8 @@ from pathlib import Path

from dagster import Definitions, asset
from dagster._core.definitions.metadata import (
link_to_source_control,
AnchorBasedFilePathMapping,
link_code_references_to_git,
with_source_code_references,
)

Expand All @@ -208,11 +192,14 @@ def another_asset(): ...
assets = with_source_code_references([my_asset, another_asset])

defs = Definitions(
assets=link_to_source_control(
assets=link_code_references_to_git(
assets_defs=assets,
source_control_url="https://github.com/dagster-io/dagster",
source_control_branch="main",
repository_root_absolute_path=Path(__file__).parent,
git_url="https://github.com/dagster-io/dagster",
git_branch="main",
file_path_mapping=AnchorBasedFilePathMapping(
local_file_anchor=Path(__file__),
file_anchor_path_in_repository="src/repo.py",
),
)
if bool(os.getenv("IS_PRODUCTION"))
else assets
Expand Down
Binary file modified docs/next/public/objects.inv
Binary file not shown.
2 changes: 0 additions & 2 deletions docs/sphinx/sections/api/apidocs/libraries/dagster-looker.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,4 @@ your other data assets, and how changes to other data assets might impact your L
Assets
======

.. autodecorator:: looker_assets

.. autoclass:: DagsterLookerTranslator

0 comments on commit eb645c2

Please sign in to comment.