diff --git a/examples/docs_snippets/docs_snippets/guides/components/index/1-help.txt b/examples/docs_snippets/docs_snippets/guides/components/index/1-help.txt index 7c6ec1f3c1e07..74960addb1288 100644 --- a/examples/docs_snippets/docs_snippets/guides/components/index/1-help.txt +++ b/examples/docs_snippets/docs_snippets/guides/components/index/1-help.txt @@ -23,7 +23,6 @@ Usage: dg [OPTIONS] COMMAND [ARGS]... │ check Commands for checking the integrity of your Dagster code. │ │ dev Start a local instance of Dagster. │ │ docs Commands for generating docs from your Dagster code. │ -│ env Commands for managing environment variables. │ │ init Initialize a new Dagster project or workspace. │ │ launch Launch a Dagster run. │ │ list Commands for listing Dagster entities. │ diff --git a/python_modules/libraries/dagster-dg/dagster_dg/cli/__init__.py b/python_modules/libraries/dagster-dg/dagster_dg/cli/__init__.py index 760bd77fd6c69..a6af02b22ee63 100644 --- a/python_modules/libraries/dagster-dg/dagster_dg/cli/__init__.py +++ b/python_modules/libraries/dagster-dg/dagster_dg/cli/__init__.py @@ -6,7 +6,6 @@ from dagster_dg.cli.check import check_group from dagster_dg.cli.dev import dev_command from dagster_dg.cli.docs import docs_group -from dagster_dg.cli.env import env_group from dagster_dg.cli.init import init_command from dagster_dg.cli.launch import launch_command from dagster_dg.cli.list import list_group @@ -29,7 +28,6 @@ def create_dg_cli(): commands={ "check": check_group, "docs": docs_group, - "env": env_group, "utils": utils_group, "launch": launch_command, "list": list_group, diff --git a/python_modules/libraries/dagster-dg/dagster_dg/cli/env.py b/python_modules/libraries/dagster-dg/dagster_dg/cli/env.py deleted file mode 100644 index e9c2fae264a04..0000000000000 --- a/python_modules/libraries/dagster-dg/dagster_dg/cli/env.py +++ /dev/null @@ -1,44 +0,0 @@ -from pathlib import Path - -import click -from rich.console import Console -from rich.table import Table - -from dagster_dg.cli.shared_options import dg_global_options -from dagster_dg.config import normalize_cli_config -from dagster_dg.context import DgContext -from dagster_dg.env import ProjectEnvVars -from dagster_dg.utils import DgClickCommand, DgClickGroup -from dagster_dg.utils.telemetry import cli_telemetry_wrapper - - -@click.group(name="env", cls=DgClickGroup) -def env_group(): - """Commands for managing environment variables.""" - - -# ######################## -# ##### ENVIRONMENT -# ######################## - - -@env_group.command(name="list", cls=DgClickCommand) -@dg_global_options -@cli_telemetry_wrapper -def list_env_command(**global_options: object) -> None: - """List environment variables from the .env file of the current project.""" - cli_config = normalize_cli_config(global_options, click.get_current_context()) - dg_context = DgContext.for_project_environment(Path.cwd(), cli_config) - - env = ProjectEnvVars.from_ctx(dg_context) - if not env.values: - click.echo("No environment variables are defined for this project.") - return - - table = Table(border_style="dim") - table.add_column("Env Var") - table.add_column("Value") - for key, value in env.values.items(): - table.add_row(key, value) - console = Console() - console.print(table) diff --git a/python_modules/libraries/dagster-dg/dagster_dg/cli/list.py b/python_modules/libraries/dagster-dg/dagster_dg/cli/list.py index f44f61cf8d170..a97ccc61867ef 100644 --- a/python_modules/libraries/dagster-dg/dagster_dg/cli/list.py +++ b/python_modules/libraries/dagster-dg/dagster_dg/cli/list.py @@ -23,6 +23,7 @@ from dagster_dg.component import PluginObjectFeature, RemotePluginRegistry from dagster_dg.config import normalize_cli_config from dagster_dg.context import DgContext +from dagster_dg.env import ProjectEnvVars from dagster_dg.utils import DgClickCommand, DgClickGroup from dagster_dg.utils.telemetry import cli_telemetry_wrapper @@ -309,3 +310,30 @@ def list_defs_command(output_json: bool, **global_options: object) -> None: table.add_row("Sensors", _get_sensors_table(sensors)) console.print(table) + + +# ######################## +# ##### ENVIRONMENT +# ######################## + + +@list_group.command(name="env", cls=DgClickCommand) +@dg_global_options +@cli_telemetry_wrapper +def list_env_command(**global_options: object) -> None: + """List environment variables from the .env file of the current project.""" + cli_config = normalize_cli_config(global_options, click.get_current_context()) + dg_context = DgContext.for_project_environment(Path.cwd(), cli_config) + + env = ProjectEnvVars.from_ctx(dg_context) + if not env.values: + click.echo("No environment variables are defined for this project.") + return + + table = Table(border_style="dim") + table.add_column("Env Var") + table.add_column("Value") + for key, value in env.values.items(): + table.add_row(key, value) + console = Console() + console.print(table) diff --git a/python_modules/libraries/dagster-dg/dagster_dg/cli/plus.py b/python_modules/libraries/dagster-dg/dagster_dg/cli/plus.py index a8d5aa85c530c..5628991e4fd53 100644 --- a/python_modules/libraries/dagster-dg/dagster_dg/cli/plus.py +++ b/python_modules/libraries/dagster-dg/dagster_dg/cli/plus.py @@ -76,9 +76,9 @@ def login_command() -> None: # ######################## -@plus_group.group(name="env", cls=DgClickGroup) -def plus_env_group(): - """Commands for managing environment variables in Dagster Plus.""" +@plus_group.group(name="pull", cls=DgClickGroup) +def plus_pull_group(): + """Commands for pulling configuration from Dagster Plus.""" def _get_local_secrets_for_locations( @@ -99,7 +99,7 @@ def _get_local_secrets_for_locations( return secrets_by_location -@plus_env_group.command(name="pull", cls=DgClickCommand) +@plus_pull_group.command(name="env", cls=DgClickCommand) @dg_global_options @cli_telemetry_wrapper def pull_env_command(**global_options: object) -> None: @@ -109,7 +109,7 @@ def pull_env_command(**global_options: object) -> None: dg_context = DgContext.for_workspace_or_project_environment(Path.cwd(), cli_config) if not DagsterPlusCliConfig.exists(): raise click.UsageError( - "`dg plus env pull` requires authentication with Dagster Plus. Run `dg plus login` to authenticate." + "`dg plus pull env` requires authentication with Dagster Plus. Run `dg plus login` to authenticate." ) config = DagsterPlusCliConfig.get() diff --git a/python_modules/libraries/dagster-dg/dagster_dg_tests/cli_tests/plus_tests/test_pull_env_command.py b/python_modules/libraries/dagster-dg/dagster_dg_tests/cli_tests/plus_tests/test_pull_env_command.py index 7cdf70cd7aa78..df9b9803781c8 100644 --- a/python_modules/libraries/dagster-dg/dagster_dg_tests/cli_tests/plus_tests/test_pull_env_command.py +++ b/python_modules/libraries/dagster-dg/dagster_dg_tests/cli_tests/plus_tests/test_pull_env_command.py @@ -24,10 +24,10 @@ def test_pull_env_command_no_auth(monkeypatch): ): monkeypatch.setenv("DG_CLI_CONFIG", str(Path(cloud_config_dir) / "dg.toml")) monkeypatch.setenv("DAGSTER_CLOUD_CLI_CONFIG", str(Path(cloud_config_dir) / "config")) - result = runner.invoke("plus", "env", "pull") + result = runner.invoke("plus", "pull", "env") assert result.exit_code != 0, result.output + " " + str(result.exception) assert ( - "`dg plus env pull` requires authentication with Dagster Plus. Run `dg plus login` to authenticate." + "`dg plus pull env` requires authentication with Dagster Plus. Run `dg plus login` to authenticate." in str(result.output) ) @@ -50,7 +50,7 @@ def test_pull_env_command_auth_err(dg_plus_cli_config): }, expected_variables={"onlyViewable": True, "scopes": {"localDeploymentScope": True}}, ) - result = runner.invoke("plus", "env", "pull") + result = runner.invoke("plus", "pull", "env") assert result.exit_code != 0, result.output + " " + str(result.exception) assert "Unauthorized: Not authorized" in str(result.output) @@ -74,7 +74,7 @@ def test_pull_env_command_python_err(dg_plus_cli_config): }, expected_variables={"onlyViewable": True, "scopes": {"localDeploymentScope": True}}, ) - result = runner.invoke("plus", "env", "pull") + result = runner.invoke("plus", "pull", "env") assert result.exit_code != 0, result.output + " " + str(result.exception) assert "Error: An error has occurred" in str(result.output) @@ -121,7 +121,7 @@ def test_pull_env_command_project(dg_plus_cli_config): }, expected_variables={"onlyViewable": True, "scopes": {"localDeploymentScope": True}}, ) - result = runner.invoke("plus", "env", "pull") + result = runner.invoke("plus", "pull", "env") assert result.exit_code == 0, result.output + " " + str(result.exception) assert result.output.strip() == "Environment variables saved to .env" @@ -174,7 +174,7 @@ def test_pull_env_command_workspace(dg_plus_cli_config): }, expected_variables={"onlyViewable": True, "scopes": {"localDeploymentScope": True}}, ) - result = runner.invoke("plus", "env", "pull") + result = runner.invoke("plus", "pull", "env") assert result.exit_code == 0, result.output + " " + str(result.exception) assert ( result.output.strip() diff --git a/python_modules/libraries/dagster-dg/dagster_dg_tests/cli_tests/test_env_commands.py b/python_modules/libraries/dagster-dg/dagster_dg_tests/cli_tests/test_env_commands.py deleted file mode 100644 index fa54eafdbce36..0000000000000 --- a/python_modules/libraries/dagster-dg/dagster_dg_tests/cli_tests/test_env_commands.py +++ /dev/null @@ -1,45 +0,0 @@ -import textwrap -from pathlib import Path - -from dagster_dg.utils import ensure_dagster_dg_tests_import - -ensure_dagster_dg_tests_import() - -from dagster_dg_tests.utils import ( - ProxyRunner, - assert_runner_result, - isolated_example_project_foo_bar, -) - -# ######################## -# ##### LIST -# ######################## - - -def test_list_env_succeeds(): - with ( - ProxyRunner.test(use_fixed_test_components=True) as runner, - isolated_example_project_foo_bar(runner, in_workspace=False), - ): - result = runner.invoke("env", "list") - assert_runner_result(result) - assert ( - result.output.strip() - == textwrap.dedent(""" - No environment variables are defined for this project. - """).strip() - ) - - Path(".env").write_text("FOO=bar") - result = runner.invoke("env", "list") - assert_runner_result(result) - assert ( - result.output.strip() - == textwrap.dedent(""" - ┏━━━━━━━━━┳━━━━━━━┓ - ┃ Env Var ┃ Value ┃ - ┡━━━━━━━━━╇━━━━━━━┩ - │ FOO │ bar │ - └─────────┴───────┘ - """).strip() - ) diff --git a/python_modules/libraries/dagster-dg/dagster_dg_tests/cli_tests/test_environment_validation.py b/python_modules/libraries/dagster-dg/dagster_dg_tests/cli_tests/test_environment_validation.py index 736bc25502fe9..bccca6e7a570f 100644 --- a/python_modules/libraries/dagster-dg/dagster_dg_tests/cli_tests/test_environment_validation.py +++ b/python_modules/libraries/dagster-dg/dagster_dg_tests/cli_tests/test_environment_validation.py @@ -66,8 +66,8 @@ def to_cli_args(self) -> tuple[str, ...]: CommandSpec(("check", "yaml")), CommandSpec(("list", "component")), CommandSpec(("list", "defs")), + CommandSpec(("list", "env")), CommandSpec(("scaffold", DEFAULT_COMPONENT_TYPE, "foot")), - CommandSpec(("env", "list")), ] WORKSPACE_CONTEXT_COMMANDS = [ diff --git a/python_modules/libraries/dagster-dg/dagster_dg_tests/cli_tests/test_list_commands.py b/python_modules/libraries/dagster-dg/dagster_dg_tests/cli_tests/test_list_commands.py index d88be8ce4ebf8..da218981d4ce6 100644 --- a/python_modules/libraries/dagster-dg/dagster_dg_tests/cli_tests/test_list_commands.py +++ b/python_modules/libraries/dagster-dg/dagster_dg_tests/cli_tests/test_list_commands.py @@ -9,6 +9,8 @@ ensure_dagster_dg_tests_import() +from dagster_dg.utils import ensure_dagster_dg_tests_import + from dagster_dg_tests.utils import ( ProxyRunner, assert_runner_result, @@ -432,3 +434,37 @@ def _sample_env_var_assets(): @asset(kinds={"sling"}, group_name=os.getenv("GROUP_NAME", "MISSING")) def alpha(): pass + + +# ######################## +# ##### LIST +# ######################## + + +def test_list_env_succeeds(): + with ( + ProxyRunner.test(use_fixed_test_components=True) as runner, + isolated_example_project_foo_bar(runner, in_workspace=False), + ): + result = runner.invoke("list", "env") + assert_runner_result(result) + assert ( + result.output.strip() + == textwrap.dedent(""" + No environment variables are defined for this project. + """).strip() + ) + + Path(".env").write_text("FOO=bar") + result = runner.invoke("list", "env") + assert_runner_result(result) + assert ( + result.output.strip() + == textwrap.dedent(""" + ┏━━━━━━━━━┳━━━━━━━┓ + ┃ Env Var ┃ Value ┃ + ┡━━━━━━━━━╇━━━━━━━┩ + │ FOO │ bar │ + └─────────┴───────┘ + """).strip() + )