Skip to content

Commit

Permalink
[workspace-refactor] Standardize format and naming of click option de…
Browse files Browse the repository at this point in the history
…corators
  • Loading branch information
smackesey committed Feb 2, 2025
1 parent 357f918 commit c706236
Show file tree
Hide file tree
Showing 17 changed files with 182 additions and 149 deletions.
4 changes: 2 additions & 2 deletions python_modules/dagster-graphql/dagster_graphql/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import dagster._seven as seven
import requests
from dagster._cli.utils import get_instance_for_cli, get_temporary_instance_for_cli
from dagster._cli.workspace import workspace_target_argument
from dagster._cli.workspace import workspace_target_options
from dagster._cli.workspace.cli_target import (
WORKSPACE_TARGET_WARNING,
get_workspace_process_context_from_kwargs,
Expand Down Expand Up @@ -127,7 +127,7 @@ def execute_query_against_remote(host, query, variables):
}


@workspace_target_argument
@workspace_target_options
@click.command(
name="ui",
help=(
Expand Down
4 changes: 2 additions & 2 deletions python_modules/dagster-webserver/dagster_webserver/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from dagster._cli.utils import get_possibly_temporary_instance_for_cli
from dagster._cli.workspace import (
get_workspace_process_context_from_kwargs,
workspace_target_argument,
workspace_target_options,
)
from dagster._cli.workspace.cli_target import WORKSPACE_TARGET_WARNING, ClickArgValue
from dagster._core.instance import InstanceRef
Expand Down Expand Up @@ -75,7 +75,7 @@ def create_dagster_webserver_cli():
"""
),
)
@workspace_target_argument
@workspace_target_options
@click.option(
"--host",
"-h",
Expand Down
4 changes: 2 additions & 2 deletions python_modules/dagster/dagster/_cli/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from dagster._cli.utils import get_instance_for_cli
from dagster._cli.workspace.cli_target import (
get_working_directory_from_kwargs,
python_origin_target_argument,
python_origin_target_options,
)
from dagster._core.definitions.metadata import MetadataValue
from dagster._core.errors import DagsterExecutionInterruptedError
Expand Down Expand Up @@ -601,7 +601,7 @@ def _execute_step_command_body(
),
envvar="DAGSTER_LAZY_LOAD_USER_CODE",
)
@python_origin_target_argument
@python_origin_target_options
@click.option(
"--use-python-environment-entry-point",
is_flag=True,
Expand Down
10 changes: 5 additions & 5 deletions python_modules/dagster/dagster/_cli/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from dagster._cli.utils import get_instance_for_cli, get_possibly_temporary_instance_for_cli
from dagster._cli.workspace.cli_target import (
get_repository_python_origin_from_kwargs,
python_job_config_argument,
python_origin_target_argument,
python_job_config_option,
python_origin_target_options,
)
from dagster._core.definitions.asset_selection import AssetSelection
from dagster._core.definitions.backfill_policy import BackfillPolicyType
Expand All @@ -32,15 +32,15 @@ def asset_cli():


@asset_cli.command(name="materialize", help="Execute a run to materialize a selection of assets")
@python_origin_target_argument
@python_origin_target_options
@click.option("--select", help="Comma-separated Asset selection to target", required=True)
@click.option("--partition", help="Asset partition to target", required=False)
@click.option(
"--partition-range",
help="Asset partition range to target i.e. <start>...<end>",
required=False,
)
@python_job_config_argument("materialize")
@python_job_config_option(command_name="materialize")
@click.option(
"--config-json",
type=click.STRING,
Expand Down Expand Up @@ -157,7 +157,7 @@ def execute_materialize_command(instance: DagsterInstance, kwargs: Mapping[str,


@asset_cli.command(name="list", help="List assets")
@python_origin_target_argument
@python_origin_target_options
@click.option("--select", help="Asset selection to target", required=False)
def asset_list_command(**kwargs):
repository_origin = get_repository_python_origin_from_kwargs(kwargs)
Expand Down
4 changes: 2 additions & 2 deletions python_modules/dagster/dagster/_cli/code_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import dagster._seven as seven
from dagster._cli.workspace.cli_target import (
get_working_directory_from_kwargs,
python_origin_target_argument,
python_origin_target_options,
)
from dagster._core.instance import InstanceRef
from dagster._core.types.loadable_target_origin import LoadableTargetOrigin
Expand Down Expand Up @@ -66,7 +66,7 @@ def code_server_cli():
help="Maximum number of (threaded) workers to use in the code server",
envvar="DAGSTER_CODE_SERVER_MAX_WORKERS",
)
@python_origin_target_argument
@python_origin_target_options
@click.option(
"--use-python-environment-entry-point",
is_flag=True,
Expand Down
12 changes: 6 additions & 6 deletions python_modules/dagster/dagster/_cli/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
from dagster._cli.utils import get_possibly_temporary_instance_for_cli
from dagster._cli.workspace.cli_target import (
ClickArgValue,
generate_module_name_option,
generate_python_file_option,
generate_workspace_option,
get_workspace_from_kwargs,
python_file_option,
python_module_option,
workspace_option,
)
from dagster._utils.log import configure_loggers

Expand All @@ -25,9 +25,9 @@ def definitions_cli():
def validate_command_options(f):
return apply_click_params(
f,
workspace_option(),
python_file_option(allow_multiple=True),
python_module_option(allow_multiple=True),
generate_workspace_option(),
generate_python_file_option(allow_multiple=True),
generate_module_name_option(allow_multiple=True),
)


Expand Down
20 changes: 10 additions & 10 deletions python_modules/dagster/dagster/_cli/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
from dagster._cli.utils import get_possibly_temporary_instance_for_cli
from dagster._cli.workspace.cli_target import (
ClickArgValue,
generate_grpc_server_target_options,
generate_module_name_option,
generate_python_file_option,
generate_working_directory_option,
generate_workspace_option,
get_workspace_load_target,
grpc_server_target_click_options,
python_file_option,
python_module_option,
working_directory_option,
workspace_option,
)
from dagster._core.instance import DagsterInstance
from dagster._core.workspace.context import WorkspaceProcessContext
Expand All @@ -39,11 +39,11 @@
def dev_command_options(f):
return apply_click_params(
f,
workspace_option(),
python_file_option(allow_multiple=True),
python_module_option(allow_multiple=True),
working_directory_option(),
*grpc_server_target_click_options(hidden=True),
generate_workspace_option(),
generate_python_file_option(allow_multiple=True),
generate_module_name_option(allow_multiple=True),
generate_working_directory_option(),
*generate_grpc_server_target_options(hidden=True),
)


Expand Down
24 changes: 12 additions & 12 deletions python_modules/dagster/dagster/_cli/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
get_remote_repository_from_kwargs,
get_run_config_from_file_list,
get_workspace_from_kwargs,
job_repository_target_argument,
job_target_argument,
python_job_config_argument,
python_job_target_argument,
job_repository_target_options,
job_target_options,
python_job_config_option,
python_job_target_options,
)
from dagster._core.definitions import JobDefinition
from dagster._core.definitions.reconstruct import ReconstructableJob
Expand Down Expand Up @@ -84,7 +84,7 @@ def apply_click_params(command: T_Callable, *click_params: ClickOption) -> T_Cal
name="list",
help=f"List the jobs in a repository. {WORKSPACE_TARGET_WARNING}",
)
@job_repository_target_argument
@job_repository_target_options
def job_list_command(**kwargs):
return execute_list_command(kwargs, click.echo)

Expand Down Expand Up @@ -141,7 +141,7 @@ def get_job_instructions(command_name):
help="Print a job.\n\n{instructions}".format(instructions=get_job_instructions("print")),
)
@click.option("--verbose", is_flag=True)
@job_target_argument
@job_target_options
def job_print_command(verbose, **cli_args):
with get_possibly_temporary_instance_for_cli("``dagster job print``") as instance:
return execute_print_command(instance, verbose, cli_args, click.echo)
Expand Down Expand Up @@ -244,8 +244,8 @@ def print_op(
instructions=get_job_in_same_python_env_instructions("execute")
),
)
@python_job_target_argument
@python_job_config_argument("execute")
@python_job_target_options
@python_job_config_option(command_name="execute")
@click.option("--tags", type=click.STRING, help="JSON string of tags to use for this job run")
@click.option(
"-o",
Expand Down Expand Up @@ -342,8 +342,8 @@ def do_execute_command(
)
),
)
@job_target_argument
@python_job_config_argument("launch")
@job_target_options
@python_job_config_option(command_name="launch")
@click.option(
"--config-json",
type=click.STRING,
Expand Down Expand Up @@ -497,7 +497,7 @@ def _check_execute_remote_job_args(
instructions=get_job_in_same_python_env_instructions("scaffold_config")
),
)
@python_job_target_argument
@python_job_target_options
@click.option("--print-only-required", default=False, is_flag=True)
def job_scaffold_command(**kwargs):
execute_scaffold_command(kwargs, click.echo)
Expand Down Expand Up @@ -530,7 +530,7 @@ def do_scaffold_command(
instructions=get_job_instructions("backfill")
),
)
@job_target_argument
@job_target_options
@click.option(
"--partitions",
type=click.STRING,
Expand Down
4 changes: 2 additions & 2 deletions python_modules/dagster/dagster/_cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from dagster import __version__ as dagster_version
from dagster._cli.utils import get_instance_for_cli
from dagster._cli.workspace.cli_target import get_remote_job_from_kwargs, job_target_argument
from dagster._cli.workspace.cli_target import get_remote_job_from_kwargs, job_target_options


@click.group(name="run")
Expand Down Expand Up @@ -85,7 +85,7 @@ def run_wipe_command(force: bool) -> None:
"from_label",
help="The repository from which to migrate (format: <repository_name>@<location_name>)",
)
@job_target_argument
@job_target_options
def run_migrate_command(from_label: str, **kwargs: Any) -> None:
from dagster._core.storage.dagster_run import RunsFilter
from dagster._core.storage.runs.sql_run_storage import SqlRunStorage
Expand Down
14 changes: 7 additions & 7 deletions python_modules/dagster/dagster/_cli/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from dagster._cli.utils import get_instance_for_cli
from dagster._cli.workspace.cli_target import (
get_remote_repository_from_kwargs,
repository_target_argument,
repository_target_options,
)
from dagster._core.definitions.run_request import InstigatorType
from dagster._core.instance import DagsterInstance
Expand Down Expand Up @@ -140,7 +140,7 @@ def check_repo_and_scheduler(repository: RemoteRepository, instance: DagsterInst
@schedule_cli.command(
name="preview", help="Preview changes that will be performed by `dagster schedule up`."
)
@repository_target_argument
@repository_target_options
def schedule_preview_command(**kwargs):
return execute_preview_command(kwargs, click.echo)

Expand All @@ -159,7 +159,7 @@ def execute_preview_command(cli_args, print_fn):
name="list",
help="List all schedules that correspond to a repository.",
)
@repository_target_argument
@repository_target_options
@click.option("--running", help="Filter for running schedules", is_flag=True, default=False)
@click.option("--stopped", help="Filter for stopped schedules", is_flag=True, default=False)
@click.option("--name", help="Only display schedule schedule names", is_flag=True, default=False)
Expand Down Expand Up @@ -230,7 +230,7 @@ def extract_schedule_name(schedule_name: Optional[Union[str, Sequence[str]]]) ->
@schedule_cli.command(name="start", help="Start an existing schedule.")
@click.argument("schedule_name", nargs=-1) # , required=True)
@click.option("--start-all", help="start all schedules", is_flag=True, default=False)
@repository_target_argument
@repository_target_options
def schedule_start_command(schedule_name, start_all, **kwargs):
schedule_name = extract_schedule_name(schedule_name)
if schedule_name is None and start_all is False:
Expand Down Expand Up @@ -270,7 +270,7 @@ def execute_start_command(schedule_name, all_flag, cli_args, print_fn):

@schedule_cli.command(name="stop", help="Stop an existing schedule.")
@click.argument("schedule_name", nargs=-1)
@repository_target_argument
@repository_target_options
def schedule_stop_command(schedule_name, **kwargs):
schedule_name = extract_schedule_name(schedule_name)
return execute_stop_command(schedule_name, kwargs, click.echo)
Expand Down Expand Up @@ -298,7 +298,7 @@ def execute_stop_command(schedule_name, cli_args, print_fn, instance=None):

@schedule_cli.command(name="logs", help="Get logs for a schedule.")
@click.argument("schedule_name", nargs=-1)
@repository_target_argument
@repository_target_options
def schedule_logs_command(schedule_name, **kwargs):
schedule_name = extract_schedule_name(schedule_name)
if schedule_name is None:
Expand Down Expand Up @@ -370,7 +370,7 @@ def execute_logs_command(schedule_name, cli_args, print_fn, instance=None):
is_flag=True,
default=False,
)
@repository_target_argument
@repository_target_options
def schedule_restart_command(schedule_name, restart_all_running, **kwargs):
schedule_name = extract_schedule_name(schedule_name)
return execute_restart_command(schedule_name, restart_all_running, kwargs, click.echo)
Expand Down
12 changes: 6 additions & 6 deletions python_modules/dagster/dagster/_cli/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
get_code_location_from_kwargs,
get_remote_repository_from_code_location,
get_remote_repository_from_kwargs,
repository_target_argument,
repository_target_options,
)
from dagster._core.definitions.run_request import InstigatorType
from dagster._core.instance import DagsterInstance
Expand Down Expand Up @@ -123,7 +123,7 @@ def extract_sensor_name(sensor_name):
name="list",
help="List all sensors that correspond to a repository.",
)
@repository_target_argument
@repository_target_options
@click.option("--running", help="Filter for running sensors", is_flag=True, default=False)
@click.option("--stopped", help="Filter for stopped sensors", is_flag=True, default=False)
@click.option("--name", help="Only display sensor sensor names", is_flag=True, default=False)
Expand Down Expand Up @@ -183,7 +183,7 @@ def execute_list_command(running_filter, stopped_filter, name_filter, cli_args,
@sensor_cli.command(name="start", help="Start an existing sensor.")
@click.argument("sensor_name", nargs=-1) # , required=True)
@click.option("--start-all", help="start all sensors", is_flag=True, default=False)
@repository_target_argument
@repository_target_options
def sensor_start_command(sensor_name, start_all, **kwargs):
if not start_all:
sensor_name = extract_sensor_name(sensor_name)
Expand Down Expand Up @@ -217,7 +217,7 @@ def execute_start_command(sensor_name, all_flag, cli_args, print_fn):

@sensor_cli.command(name="stop", help="Stop an existing sensor.")
@click.argument("sensor_name", nargs=-1)
@repository_target_argument
@repository_target_options
def sensor_stop_command(sensor_name, **kwargs):
sensor_name = extract_sensor_name(sensor_name)
return execute_stop_command(sensor_name, kwargs, click.echo)
Expand Down Expand Up @@ -259,7 +259,7 @@ def execute_stop_command(sensor_name, cli_args, print_fn):
help="Set the cursor value for the sensor context",
default=None,
)
@repository_target_argument
@repository_target_options
def sensor_preview_command(sensor_name, since, last_run_key, cursor, **kwargs):
sensor_name = extract_sensor_name(sensor_name)
if since:
Expand Down Expand Up @@ -332,7 +332,7 @@ def execute_preview_command(
@click.option(
"--delete", help="Delete the existing cursor value for the sensor context", is_flag=True
)
@repository_target_argument
@repository_target_options
def sensor_cursor_command(sensor_name, **kwargs):
sensor_name = extract_sensor_name(sensor_name)
return execute_cursor_command(sensor_name, kwargs, click.echo)
Expand Down
2 changes: 1 addition & 1 deletion python_modules/dagster/dagster/_cli/workspace/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from dagster._cli.workspace.cli_target import (
get_workspace_process_context_from_kwargs as get_workspace_process_context_from_kwargs,
workspace_target_argument as workspace_target_argument,
workspace_target_options as workspace_target_options,
)
Loading

0 comments on commit c706236

Please sign in to comment.