Skip to content

Commit 7a42174

Browse files
committed
[dg] Rename PackageObject* -> PluginObject*
1 parent e88974e commit 7a42174

File tree

25 files changed

+180
-150
lines changed

25 files changed

+180
-150
lines changed
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
title: 'Configuring dg'
3+
sidebar_position: 500
4+
---
5+
6+
import Preview from '@site/docs/partials/\_Preview.md';
7+
8+
<Preview />
9+
10+
`dg` is primarily configured using
11+
12+
13+
14+
## Default `dg` behavior (`uv run`)
15+
16+
`dg` itself is installed globally and always executes in an isolated environment. However, many `dg` commands need to spawn subprocesses in environments scoped to specific projects. For example, when you run `dg list component-type` in a project directory, `dg` only lists the component types available in that project.
17+
18+
When using `dg` with default settings, the Python subprocess is spawned after detecting a virtual environment in the project directory. This means that, rather than finding the first `python` executable on your shell `PATH`, it will instead use the Python executable from a locally detected virtual environment even if that virtual environment is not currently activated.
19+
20+
By default, `dg` uses a special `uv` command called `uv run` for environment detection and command execution. `uv run` resolves a local virtual environment (`.venv` in an ancestor directory) before running a command, and additionally makes sure that the environment is up to date with the project's specified dependencies before running the command.
21+
22+
`dg`'s use of `uv run` means you don't need to manage global shell state by activating and deactivating virtual environments during development. Instead, `dg` expects (and will scaffold for you) a `.venv` directory in the root of each project, and will use that virtual environment when executing commands (such as `dg scaffold defs` or `dg list component-type`) against that project.
23+
24+
## Disabling use of `uv run`
25+
26+
You can disable `dg`'s use of `uv run` by passing the `--no-use-dg-managed-environment` flag to `dg` commands. This will cause `dg` to still try to resolve local virtual environments by looking up the ancestor tree for `.venv`, but instead launch Python processes directly rather than going through `uv run`.
27+
28+
If you want to opt out of virtual environment detection entirely and just use your ambient Python environment (system Python or an activated virtual env), you should also (a) set `--no-require-local-venv`, and (b) ensure there are no `.venv` directories in
29+
the ancestor tree of your project.
30+
31+
:::info
32+
33+
Disabling `uv` integration with `--no-use-dg-managed-environment` will
34+
currently disable the `dg cache`. This will make some operations noticeably slower.
35+
36+
:::

python_modules/dagster/dagster/components/cli/list.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from typing import Literal, Optional, Union
33

44
import click
5-
from dagster_shared.serdes.objects import PackageObjectKey
5+
from dagster_shared.serdes.objects import PluginObjectKey
66
from dagster_shared.serdes.objects.definition_metadata import (
77
DgAssetCheckMetadata,
88
DgAssetMetadata,
@@ -160,7 +160,7 @@ def list_definitions_command(
160160

161161
def _load_library_objects(
162162
entry_points: bool, extra_modules: tuple[str, ...]
163-
) -> dict[PackageObjectKey, object]:
163+
) -> dict[PluginObjectKey, object]:
164164
objects = {}
165165
if entry_points:
166166
objects.update(discover_entry_point_package_objects())
@@ -171,7 +171,7 @@ def _load_library_objects(
171171

172172
def _load_component_types(
173173
entry_points: bool, extra_modules: tuple[str, ...]
174-
) -> dict[PackageObjectKey, type[Component]]:
174+
) -> dict[PluginObjectKey, type[Component]]:
175175
return {
176176
key: obj
177177
for key, obj in _load_library_objects(entry_points, extra_modules).items()

python_modules/dagster/dagster/components/cli/scaffold.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from typing import Optional
33

44
import click
5-
from dagster_shared.serdes.objects import PackageObjectKey
5+
from dagster_shared.serdes.objects import PluginObjectKey
66
from pydantic import TypeAdapter
77

88
from dagster.components.component_scaffolding import scaffold_object
@@ -30,7 +30,7 @@ def scaffold_object_command(
3030
json_params: Optional[str],
3131
scaffold_format: str,
3232
) -> None:
33-
key = PackageObjectKey.from_typename(typename)
33+
key = PluginObjectKey.from_typename(typename)
3434
obj = load_package_object(key)
3535

3636
if json_params:

python_modules/dagster/dagster/components/core/defs_module.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from pathlib import Path
66
from typing import Any, Optional, TypeVar
77

8-
from dagster_shared.serdes.objects import PackageObjectKey
8+
from dagster_shared.serdes.objects import PluginObjectKey
99
from dagster_shared.yaml_utils import parse_yaml_with_source_positions
1010
from pydantic import BaseModel, ConfigDict, TypeAdapter
1111

@@ -245,7 +245,7 @@ def get_component(cls, context: ComponentLoadContext) -> Component:
245245

246246
# find the component type
247247
type_str = context.normalize_component_type_str(component_file_model.type)
248-
key = PackageObjectKey.from_typename(type_str)
248+
key = PluginObjectKey.from_typename(type_str)
249249
obj = load_package_object(key)
250250
if not isinstance(obj, type) or not issubclass(obj, Component):
251251
raise DagsterInvalidDefinitionError(

python_modules/dagster/dagster/components/core/package_entry.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from collections.abc import Iterable, Sequence
66
from types import ModuleType
77

8-
from dagster_shared.serdes.objects import PackageObjectKey
8+
from dagster_shared.serdes.objects import PluginObjectKey
99

1010
from dagster._core.errors import DagsterError
1111
from dagster.components.utils import format_error_message
@@ -25,7 +25,7 @@ def get_entry_points_from_python_environment(group: str) -> Sequence[importlib.m
2525
return importlib.metadata.entry_points().get(group, [])
2626

2727

28-
def discover_entry_point_package_objects() -> dict[PackageObjectKey, object]:
28+
def discover_entry_point_package_objects() -> dict[PluginObjectKey, object]:
2929
"""Discover package entries registered in the Python environment via the
3030
`dg_library` entry point group.
3131
@@ -34,7 +34,7 @@ def discover_entry_point_package_objects() -> dict[PackageObjectKey, object]:
3434
component types and is loaded by default. Other entry points resolve to various sets of test
3535
component types. This method will only ever load one builtin package.
3636
"""
37-
objects: dict[PackageObjectKey, object] = {}
37+
objects: dict[PluginObjectKey, object] = {}
3838
entry_points = get_entry_points_from_python_environment(DG_LIBRARY_ENTRY_POINT_GROUP)
3939

4040
for entry_point in entry_points:
@@ -54,16 +54,16 @@ def discover_entry_point_package_objects() -> dict[PackageObjectKey, object]:
5454
f"Value expected to be a module, got {root_module}."
5555
)
5656
for name, obj in get_package_objects_in_module(root_module):
57-
key = PackageObjectKey(name=name, namespace=entry_point.value)
57+
key = PluginObjectKey(name=name, namespace=entry_point.value)
5858
objects[key] = obj
5959
return objects
6060

6161

62-
def discover_package_objects(modules: Sequence[str]) -> dict[PackageObjectKey, object]:
63-
objects: dict[PackageObjectKey, object] = {}
62+
def discover_package_objects(modules: Sequence[str]) -> dict[PluginObjectKey, object]:
63+
objects: dict[PluginObjectKey, object] = {}
6464
for extra_module in modules:
6565
for name, obj in get_package_objects_in_module(importlib.import_module(extra_module)):
66-
key = PackageObjectKey(name=name, namespace=extra_module)
66+
key = PluginObjectKey(name=name, namespace=extra_module)
6767
objects[key] = obj
6868
return objects
6969

@@ -77,7 +77,7 @@ def get_package_objects_in_module(
7777
yield attr, value
7878

7979

80-
def load_package_object(key: PackageObjectKey) -> object:
80+
def load_package_object(key: PluginObjectKey) -> object:
8181
module_name, attr = key.namespace, key.name
8282
try:
8383
module = importlib.import_module(module_name)

python_modules/dagster/dagster/components/core/snapshot.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
from dagster_shared.serdes.objects.package_entry import (
55
ComponentFeatureData,
6-
PackageObjectKey,
7-
PackageObjectSnap,
6+
PluginObjectKey,
7+
PluginObjectSnap,
88
ScaffoldTargetTypeData,
99
)
1010

@@ -43,7 +43,7 @@ def _get_scaffold_target_type_data(scaffolder: Scaffolder) -> ScaffoldTargetType
4343
)
4444

4545

46-
def get_package_entry_snap(key: PackageObjectKey, obj: object) -> PackageObjectSnap:
46+
def get_package_entry_snap(key: PluginObjectKey, obj: object) -> PluginObjectSnap:
4747
type_data = []
4848
owners = []
4949
tags = []
@@ -56,7 +56,7 @@ def get_package_entry_snap(key: PackageObjectKey, obj: object) -> PackageObjectS
5656
if isinstance(scaffolder, Scaffolder):
5757
type_data.append(_get_scaffold_target_type_data(scaffolder))
5858
summary, description = _get_summary_and_description(obj)
59-
return PackageObjectSnap(
59+
return PluginObjectSnap(
6060
key=key,
6161
summary=summary,
6262
owners=owners,

python_modules/dagster/dagster_tests/components_tests/cli_tests/test_commands.py

+8-10
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
from dagster_shared import check
99
from dagster_shared.serdes.objects import (
1010
ComponentFeatureData,
11-
PackageObjectKey,
12-
PackageObjectSnap,
11+
PluginObjectKey,
12+
PluginObjectSnap,
1313
ScaffoldTargetTypeData,
1414
)
1515
from dagster_shared.serdes.serdes import deserialize_value
@@ -40,7 +40,7 @@ def test_list_library_objects_from_module():
4040
# Now check what we get when we load directly from the test library. This has stable results.
4141
result = runner.invoke(cli, ["list", "library", "--no-entry-points", "dagster_test.components"])
4242
assert result.exit_code == 0
43-
result = check.is_list(deserialize_value(result.output), PackageObjectSnap)
43+
result = check.is_list(deserialize_value(result.output), PluginObjectSnap)
4444
assert len(result) > 1
4545

4646
assert [obj.key.to_typename() for obj in result] == [
@@ -50,8 +50,8 @@ def test_list_library_objects_from_module():
5050
"dagster_test.components.SimplePipesScriptComponent",
5151
]
5252

53-
assert result[2] == PackageObjectSnap(
54-
key=PackageObjectKey(namespace="dagster_test.components", name="SimpleAssetComponent"),
53+
assert result[2] == PluginObjectSnap(
54+
key=PluginObjectKey(namespace="dagster_test.components", name="SimpleAssetComponent"),
5555
description="A simple asset that returns a constant string value.",
5656
summary="A simple asset that returns a constant string value.",
5757
@@ -94,10 +94,8 @@ def test_list_library_objects_from_module():
9494
"type": "object",
9595
}
9696

97-
assert result[3] == PackageObjectSnap(
98-
key=PackageObjectKey(
99-
namespace="dagster_test.components", name="SimplePipesScriptComponent"
100-
),
97+
assert result[3] == PluginObjectSnap(
98+
key=PluginObjectKey(namespace="dagster_test.components", name="SimplePipesScriptComponent"),
10199
description="A simple asset that runs a Python script with the Pipes subprocess client.\n\nBecause it is a pipes asset, no value is returned.",
102100
summary="A simple asset that runs a Python script with the Pipes subprocess client.",
103101
owners=[],
@@ -134,7 +132,7 @@ def test_list_library_objects_from_project() -> None:
134132

135133
result = deserialize_value(result.output, list)
136134
assert len(result) == 1
137-
assert result[0].key == PackageObjectKey(
135+
assert result[0].key == PluginObjectKey(
138136
namespace=f"{location_name}.defs.local_component_sample",
139137
name="MyComponent",
140138
)

python_modules/dagster/dagster_tests/components_tests/registry_tests/test_registry.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from dagster.components.core.package_entry import discover_entry_point_package_objects
1414
from dagster.components.core.snapshot import get_package_entry_snap
1515
from dagster_dg.utils import get_venv_executable
16-
from dagster_shared.serdes.objects import PackageObjectKey
16+
from dagster_shared.serdes.objects import PluginObjectKey
1717
from dagster_shared.serdes.serdes import deserialize_value
1818

1919
ensure_dagster_tests_import()
@@ -130,7 +130,7 @@ def test_all_components_have_defined_summary():
130130
for component_name, component_type in registry.items():
131131
if isinstance(component_type, type) and issubclass(component_type, Component):
132132
assert get_package_entry_snap(
133-
PackageObjectKey("a", "a"), component_type
133+
PluginObjectKey("a", "a"), component_type
134134
).summary, f"Component {component_name} has no summary defined"
135135

136136

Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
from pathlib import Path
22

33
import pytest
4-
from dagster_shared.serdes.objects import PackageObjectKey
4+
from dagster_shared.serdes.objects import PluginObjectKey
55

66
dirpath = Path(".")
77

88

99
@pytest.mark.parametrize(
1010
["typename", "key"],
1111
[
12-
("foo.bar", PackageObjectKey("foo", "bar")),
13-
("foo.Bar", PackageObjectKey("foo", "Bar")),
14-
("foo.bar.baz", PackageObjectKey("foo.bar", "baz")),
12+
("foo.bar", PluginObjectKey("foo", "bar")),
13+
("foo.Bar", PluginObjectKey("foo", "Bar")),
14+
("foo.bar.baz", PluginObjectKey("foo.bar", "baz")),
1515
],
1616
)
17-
def test_valid_keys(typename: str, key: PackageObjectKey) -> None:
18-
assert PackageObjectKey.from_typename(typename) == key
17+
def test_valid_keys(typename: str, key: PluginObjectKey) -> None:
18+
assert PluginObjectKey.from_typename(typename) == key
1919

2020

2121
@pytest.mark.parametrize(
@@ -28,4 +28,4 @@ def test_valid_keys(typename: str, key: PackageObjectKey) -> None:
2828
)
2929
def test_invalid_keys(typename: str) -> None:
3030
with pytest.raises(ValueError):
31-
PackageObjectKey.from_typename(typename)
31+
PluginObjectKey.from_typename(typename)

python_modules/libraries/dagster-components/dagster_components/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
ScaffoldRequest as ScaffoldRequest,
3535
)
3636
from dagster_shared.libraries import DagsterLibraryRegistry
37-
from dagster_shared.serdes.objects import PackageObjectKey as PackageObjectKey
37+
from dagster_shared.serdes.objects import PluginObjectKey as PluginObjectKey
3838

3939
from dagster_components.version import __version__ as __version__
4040

python_modules/libraries/dagster-dg/dagster_dg/check.py

+6-10
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import Any, NamedTuple, Optional
44

55
import click
6-
from dagster_shared.serdes.objects import PackageObjectKey
6+
from dagster_shared.serdes.objects import PluginObjectKey
77
from dagster_shared.yaml_utils import parse_yaml_with_source_positions
88
from dagster_shared.yaml_utils.source_position import (
99
LineCol,
@@ -15,11 +15,7 @@
1515
from yaml.scanner import ScannerError
1616

1717
from dagster_dg.cli.check_utils import error_dict_to_formatted_error
18-
from dagster_dg.component import (
19-
RemotePackageRegistry,
20-
get_specified_env_var_deps,
21-
get_used_env_vars,
22-
)
18+
from dagster_dg.component import RemotePluginRegistry, get_specified_env_var_deps, get_used_env_vars
2319
from dagster_dg.context import DgContext
2420

2521
COMPONENT_FILE_SCHEMA = {
@@ -52,7 +48,7 @@ def _scaffold_value_and_source_position_tree(
5248

5349

5450
class ErrorInput(NamedTuple):
55-
object_key: Optional[PackageObjectKey]
51+
object_key: Optional[PluginObjectKey]
5652
error: ValidationError
5753
source_position_tree: ValueAndSourcePositionTree
5854

@@ -67,7 +63,7 @@ def check_yaml(
6763
validation_errors: list[ErrorInput] = []
6864
all_specified_env_var_deps = set()
6965

70-
component_contents_by_key: dict[PackageObjectKey, Any] = {}
66+
component_contents_by_key: dict[PluginObjectKey, Any] = {}
7167
modules_to_fetch = set()
7268
for component_dir in dg_context.defs_path.rglob("*"):
7369
if resolved_paths and not any(
@@ -136,7 +132,7 @@ def check_yaml(
136132
qualified_key = (
137133
f"{component_instance_module}{raw_key}" if raw_key.startswith(".") else raw_key
138134
)
139-
key = PackageObjectKey.from_typename(qualified_key)
135+
key = PluginObjectKey.from_typename(qualified_key)
140136
component_contents_by_key[key] = component_doc_tree
141137

142138
# We need to fetch components from any modules local to the project because these are
@@ -145,7 +141,7 @@ def check_yaml(
145141
modules_to_fetch.add(key.namespace)
146142

147143
# Fetch the local component types, if we need any local components
148-
component_registry = RemotePackageRegistry.from_dg_context(
144+
component_registry = RemotePluginRegistry.from_dg_context(
149145
dg_context, extra_modules=list(modules_to_fetch)
150146
)
151147
for key, component_doc_tree in component_contents_by_key.items():

python_modules/libraries/dagster-dg/dagster_dg/cli/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from dagster_dg.cli.scaffold import scaffold_group
1515
from dagster_dg.cli.shared_options import dg_global_options
1616
from dagster_dg.cli.utils import utils_group
17-
from dagster_dg.component import RemotePackageRegistry
17+
from dagster_dg.component import RemotePluginRegistry
1818
from dagster_dg.config import normalize_cli_config
1919
from dagster_dg.context import DgContext
2020
from dagster_dg.utils import DgClickGroup, exit_with_error
@@ -119,7 +119,7 @@ def _rebuild_component_registry(dg_context: DgContext):
119119
key = dg_context.get_cache_key("component_registry_data")
120120
dg_context.cache.clear_key(key)
121121
# This will trigger a rebuild of the component registry
122-
RemotePackageRegistry.from_dg_context(dg_context)
122+
RemotePluginRegistry.from_dg_context(dg_context)
123123

124124

125125
ENV_PREFIX = "DAGSTER_DG"

python_modules/libraries/dagster-dg/dagster_dg/cli/check_utils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import click
66
import typer
7-
from dagster_shared.serdes.objects import PackageObjectKey
7+
from dagster_shared.serdes.objects import PluginObjectKey
88
from dagster_shared.yaml_utils.source_position import SourcePositionTree
99
from jsonschema import ValidationError
1010

@@ -39,7 +39,7 @@ def augment_error_path(error_details: ValidationError) -> Sequence[Union[str, in
3939

4040

4141
def error_dict_to_formatted_error(
42-
key: Optional[PackageObjectKey],
42+
key: Optional[PluginObjectKey],
4343
error_details: ValidationError,
4444
source_position_tree: SourcePositionTree,
4545
prefix: Sequence[str] = (),

0 commit comments

Comments
 (0)