Skip to content

Commit a4185dc

Browse files
benpankowLoHertel
authored andcommitted
[dg cli] More clearly error if module name doesn't match what we expect (dagster-io#27662)
## Summary Ran into this in the new `product-operations` purina code location, which didn't have the same python module name as the code location name. The error message gave me the runaround. ## Test Plan New unit test.
1 parent ff7a6cc commit a4185dc

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

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

+8
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,10 @@ def components_path(self) -> Path:
228228
if not self.is_code_location:
229229
raise DgError("`components_path` is only available in a code location context")
230230
with ensure_loadable_path(self.root_path):
231+
if not is_package_installed(self.root_package_name):
232+
raise DgError(
233+
f"Could not find expected package `{self.root_package_name}` in the current environment. Components expects the package name to match the directory name of the code location."
234+
)
231235
if not is_package_installed(self.components_package_name):
232236
raise DgError(
233237
f"Components package `{self.components_package_name}` is not installed in the current environment."
@@ -279,6 +283,10 @@ def components_lib_path(self) -> Path:
279283
if not self.is_component_library:
280284
raise DgError("`components_lib_path` is only available in a component library context")
281285
with ensure_loadable_path(self.root_path):
286+
if not is_package_installed(self.root_package_name):
287+
raise DgError(
288+
f"Could not find expected package `{self.root_package_name}` in the current environment. Components expects the package name to match the directory name of the code location."
289+
)
282290
if not is_package_installed(self.components_lib_package_name):
283291
raise DgError(
284292
f"Components lib package `{self.components_lib_package_name}` is not installed in the current environment."

python_modules/libraries/dagster-dg/dagster_dg_tests/cli_tests/component_command_tests/test_component_commands.py

+17-1
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,27 @@ def test_component_scaffold_undefined_component_type_fails() -> None:
135135

136136
def test_component_scaffold_outside_code_location_fails() -> None:
137137
with ProxyRunner.test() as runner, isolated_example_deployment_foo(runner):
138-
result = runner.invoke("component", "scaffold", "bar.baz", "qux")
138+
result = runner.invoke("component", "scaffold", "bar@baz", "qux")
139139
assert_runner_result(result, exit_0=False)
140140
assert "must be run inside a Dagster code location directory" in result.output
141141

142142

143+
def test_scaffold_component_command_with_non_matching_package_name():
144+
with ProxyRunner.test() as runner, isolated_example_code_location_foo_bar(runner):
145+
# move the module from foo_bar to module_not_same_as_code_location
146+
python_module = Path("foo_bar")
147+
python_module.rename("module_not_same_as_code_location")
148+
149+
result = runner.invoke(
150+
"component", "scaffold", "all_metadata_empty_asset@dagster_components.test", "qux"
151+
)
152+
assert_runner_result(result, exit_0=False)
153+
assert (
154+
"Could not find expected package `foo_bar` in the current environment. Components expects the package name to match the directory name of the code location."
155+
in str(result.exception)
156+
)
157+
158+
143159
def test_component_scaffold_with_no_dagster_components_fails() -> None:
144160
with ProxyRunner.test() as runner, isolated_example_code_location_foo_bar(runner):
145161
result = runner.invoke(

0 commit comments

Comments
 (0)