Skip to content

Commit

Permalink
[ruff] 0.3.0 -> 0.3.4 (dagster-io#20753)
Browse files Browse the repository at this point in the history
## Summary & Motivation

Internal companion PR: dagster-io/internal#8961

Bump ruff from 0.3.0 -> 0.3.4.

The major change here is a more aggressive UP032, which automatically
converts some str.format() calls to f-strings.

## How I Tested These Changes

Existing test suite.
  • Loading branch information
smackesey authored Mar 27, 2024
1 parent e4c2b64 commit db84034
Show file tree
Hide file tree
Showing 62 changed files with 202 additions and 472 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,8 @@ def build_test_project_steps() -> List[GroupStep]:
"docker push $${TEST_PROJECT_IMAGE}",
)
.on_python_image(
"buildkite-build-test-project-image:py{python_version}-{image_version}".format(
python_version=AvailablePythonVersion.V3_8, # py version can be bumped when rebuilt
image_version=BUILDKITE_BUILD_TEST_PROJECT_IMAGE_IMAGE_VERSION,
),
# py version can be bumped when rebuilt
f"buildkite-build-test-project-image:py{AvailablePythonVersion.V3_8}-{BUILDKITE_BUILD_TEST_PROJECT_IMAGE_IMAGE_VERSION}",
[
"AIRFLOW_HOME",
"AWS_ACCOUNT_ID",
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.3.0
rev: v0.3.4
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand Down
18 changes: 3 additions & 15 deletions examples/deploy_docker/tests/test_deploy_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,7 @@ def test_deploy_docker():
}

launch_res = requests.post(
"http://{webserver_host}:3000/graphql?query={query_string}&variables={variables}".format(
webserver_host=webserver_host,
query_string=LAUNCH_PIPELINE_MUTATION,
variables=json.dumps(variables),
)
f"http://{webserver_host}:3000/graphql?query={LAUNCH_PIPELINE_MUTATION}&variables={json.dumps(variables)}"
).json()

assert launch_res["data"]["launchPipelineExecution"]["__typename"] == "LaunchRunSuccess"
Expand All @@ -198,11 +194,7 @@ def test_deploy_docker():
}

launch_res = requests.post(
"http://{webserver_host}:3000/graphql?query={query_string}&variables={variables}".format(
webserver_host=webserver_host,
query_string=LAUNCH_PIPELINE_MUTATION,
variables=json.dumps(variables),
)
f"http://{webserver_host}:3000/graphql?query={LAUNCH_PIPELINE_MUTATION}&variables={json.dumps(variables)}"
).json()

assert launch_res["data"]["launchPipelineExecution"]["__typename"] == "LaunchRunSuccess"
Expand All @@ -226,11 +218,7 @@ def test_deploy_docker():
}

launch_res = requests.post(
"http://{webserver_host}:3000/graphql?query={query_string}&variables={variables}".format(
webserver_host=webserver_host,
query_string=LAUNCH_PIPELINE_MUTATION,
variables=json.dumps(variables),
)
f"http://{webserver_host}:3000/graphql?query={LAUNCH_PIPELINE_MUTATION}&variables={json.dumps(variables)}"
).json()

assert launch_res["data"]["launchPipelineExecution"]["__typename"] == "LaunchRunSuccess"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def less_simple_data_frame_type_check(_, value):
row = value[i]
if not isinstance(row, dict):
raise Failure(
"LessSimpleDataFrame should be a list of dicts, got {type_} for row"
" {idx}".format(type_=type(row), idx=(i + 1))
f"LessSimpleDataFrame should be a list of dicts, got {type(row)} for row"
f" {i + 1}"
)
row_fields = [field for field in row.keys()]
if fields != row_fields:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ def _cluster_provider(request):
client = docker.from_env()
client.images.get(docker_image)
print(
"Found existing image tagged {image}, skipping image build. To rebuild,"
" first run: docker rmi {image}".format(image=docker_image)
f"Found existing image tagged {docker_image}, skipping image build. To rebuild,"
f" first run: docker rmi {docker_image}"
)
except docker.errors.ImageNotFound:
build_and_tag_test_image(docker_image)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def dagster_docker_image():
client = docker.from_env()
client.images.get(docker_image)
print( # noqa: T201
"Found existing image tagged {image}, skipping image build. To rebuild, first run: "
"docker rmi {image}".format(image=docker_image)
f"Found existing image tagged {docker_image}, skipping image build. To rebuild, first run: "
f"docker rmi {docker_image}"
)
except docker.errors.ImageNotFound:
build_and_tag_test_image(docker_image)
Expand Down
4 changes: 2 additions & 2 deletions integration_tests/test_suites/k8s-test-suite/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ def dagster_docker_image() -> str:
client = docker.from_env()
client.images.get(docker_image)
print( # noqa: T201
"Found existing image tagged {image}, skipping image build. To rebuild, first run: "
"docker rmi {image}".format(image=docker_image)
f"Found existing image tagged {docker_image}, skipping image build. To rebuild, first run: "
f"docker rmi {docker_image}"
)
except docker.errors.ImageNotFound:
build_and_tag_test_image(docker_image)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ extend-exclude = [
line-length = 100

# Fail if Ruff is not running this version.
required-version = "0.3.0"
required-version = "0.3.4"

[tool.ruff.lint]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,7 @@ def terminate_pipeline_execution(
if not valid_status:
return GrapheneTerminateRunFailure(
run=graphene_run,
message="Run {run_id} could not be terminated due to having status {status}.".format(
run_id=run.run_id, status=run.status.value
),
message=f"Run {run.run_id} could not be terminated due to having status {run.status.value}.",
)

if force_mark_as_canceled:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,7 @@ def create_and_launch_partition_backfill(

if len(matches) != 1:
raise DagsterInvariantViolationError(
"Partition set names must be unique: found {num} matches for {partition_set_name}".format(
num=len(matches), partition_set_name=partition_set_name
)
f"Partition set names must be unique: found {len(matches)} matches for {partition_set_name}"
)
external_partition_set = next(iter(matches))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ def find_local_test_image(docker_image):
client = docker.from_env()
client.images.get(docker_image)
print( # noqa: T201
"Found existing image tagged {image}, skipping image build. To rebuild, first run: "
"docker rmi {image}".format(image=docker_image)
f"Found existing image tagged {docker_image}, skipping image build. To rebuild, first run: "
f"docker rmi {docker_image}"
)
except docker.errors.ImageNotFound:
build_and_tag_test_image(docker_image)
Expand Down
4 changes: 1 addition & 3 deletions python_modules/dagster-webserver/dagster_webserver/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ def webserver_debug_command(input_files, port):
debug_payload = deserialize_value(blob, DebugRunPayload)

click.echo(
"\trun_id: {} \n\tdagster version: {}".format(
debug_payload.dagster_run.run_id, debug_payload.version
)
f"\trun_id: {debug_payload.dagster_run.run_id} \n\tdagster version: {debug_payload.version}"
)
debug_payloads.append(debug_payload)

Expand Down
17 changes: 7 additions & 10 deletions python_modules/dagster/dagster/_cli/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,13 @@ def get_job_in_same_python_env_instructions(command_name):
def get_job_instructions(command_name):
return (
"This commands targets a job. The job can be specified in a number of ways:\n\n1. dagster"
" job {command_name} -j <<job_name>> (works if .{default_filename} exists)\n\n2. dagster"
" job {command_name} -j <<job_name>> -w path/to/{default_filename}\n\n3. dagster job"
" {command_name} -f /path/to/file.py -a define_some_job\n\n4. dagster job {command_name} -m"
" a_module.submodule -a define_some_job\n\n5. dagster job {command_name} -f"
" /path/to/file.py -a define_some_repo -j <<job_name>>\n\n6. dagster job {command_name} -m"
f" job {command_name} -j <<job_name>> (works if .{DEFAULT_WORKSPACE_YAML_FILENAME} exists)\n\n2. dagster"
f" job {command_name} -j <<job_name>> -w path/to/{DEFAULT_WORKSPACE_YAML_FILENAME}\n\n3. dagster job"
f" {command_name} -f /path/to/file.py -a define_some_job\n\n4. dagster job {command_name} -m"
f" a_module.submodule -a define_some_job\n\n5. dagster job {command_name} -f"
f" /path/to/file.py -a define_some_repo -j <<job_name>>\n\n6. dagster job {command_name} -m"
" a_module.submodule -a define_some_repo -j <<job_name>>"
).format(command_name=command_name, default_filename=DEFAULT_WORKSPACE_YAML_FILENAME)
)


@job_cli.command(
Expand Down Expand Up @@ -386,10 +386,7 @@ def get_config_from_args(kwargs: Mapping[str, str]) -> Mapping[str, object]:

except JSONDecodeError:
raise click.UsageError(
"Invalid JSON-string given for `--config-json`: {}\n\n{}".format(
config_json,
serializable_error_info_from_exc_info(sys.exc_info()).to_string(),
)
f"Invalid JSON-string given for `--config-json`: {config_json}\n\n{serializable_error_info_from_exc_info(sys.exc_info()).to_string()}"
)
else:
check.failed("Unhandled case getting config from kwargs")
Expand Down
13 changes: 3 additions & 10 deletions python_modules/dagster/dagster/_cli/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ def print_changes(external_repository, instance, print_fn=print, preview=False):
for schedule_origin_id in added_schedules:
print_fn(
click.style(
" + {name} (add) [{id}]".format(
name=external_schedules_dict[schedule_origin_id].name, id=schedule_origin_id
),
f" + {external_schedules_dict[schedule_origin_id].name} (add) [{schedule_origin_id}]",
fg="green",
)
)
Expand All @@ -106,10 +104,7 @@ def print_changes(external_repository, instance, print_fn=print, preview=False):
for schedule_origin_id in removed_schedules:
print_fn(
click.style(
" - {name} (delete) [{id}]".format(
name=schedule_states_dict[schedule_origin_id].instigator_name,
id=schedule_origin_id,
),
f" - {schedule_states_dict[schedule_origin_id].instigator_name} (delete) [{schedule_origin_id}]",
fg="red",
)
)
Expand Down Expand Up @@ -414,9 +409,7 @@ def execute_restart_command(schedule_name, all_running_flag, cli_args, print_fn)
)
if schedule_state is not None and schedule_state.status != InstigatorStatus.RUNNING:
click.UsageError(
"Cannot restart a schedule {name} because is not currently running".format(
name=schedule_state.instigator_name
)
f"Cannot restart a schedule {schedule_state.instigator_name} because is not currently running"
)

try:
Expand Down
10 changes: 2 additions & 8 deletions python_modules/dagster/dagster/_cli/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,20 +289,14 @@ def execute_preview_command(
except Exception:
error_info = serializable_error_info_from_exc_info(sys.exc_info())
print_fn(
"Failed to resolve sensor for {sensor_name} : {error_info}".format(
sensor_name=external_sensor.name,
error_info=error_info.to_string(),
)
f"Failed to resolve sensor for {external_sensor.name} : {error_info.to_string()}"
)
return

if not sensor_runtime_data.run_requests:
if sensor_runtime_data.skip_message:
print_fn(
"Sensor returned false for {sensor_name}, skipping: {skip_message}".format(
sensor_name=external_sensor.name,
skip_message=sensor_runtime_data.skip_message,
)
f"Sensor returned false for {external_sensor.name}, skipping: {sensor_runtime_data.skip_message}"
)
else:
print_fn(f"Sensor returned false for {external_sensor.name}, skipping")
Expand Down
5 changes: 1 addition & 4 deletions python_modules/dagster/dagster/_cli/workspace/cli_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -709,10 +709,7 @@ def get_code_location_from_workspace(

if workspace.has_code_location_error(provided_location_name):
raise click.UsageError(
'Error loading location "{provided_location_name}": {error_str}'.format(
provided_location_name=provided_location_name,
error_str=str(workspace.get_code_location_error(provided_location_name)),
)
f'Error loading location "{provided_location_name}": {workspace.get_code_location_error(provided_location_name)!s}'
)

return workspace.get_code_location(provided_location_name)
Expand Down
52 changes: 14 additions & 38 deletions python_modules/dagster/dagster/_config/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,8 @@ def create_fields_not_defined_error(
stack=context.stack,
reason=DagsterEvaluationErrorReason.FIELDS_NOT_DEFINED,
message=(
'Received unexpected config entries "{undefined_fields}" {path_msg}. '
'Expected: "{available_fields}."'
).format(
undefined_fields=undefined_fields,
path_msg=get_friendly_path_msg(context.stack),
available_fields=available_fields,
f'Received unexpected config entries "{undefined_fields}" {get_friendly_path_msg(context.stack)}. '
f'Expected: "{available_fields}."'
),
error_data=FieldsNotDefinedErrorData(field_names=undefined_fields),
)
Expand All @@ -214,10 +210,7 @@ def create_enum_type_mismatch_error(context: ContextData, config_value: object)
return EvaluationError(
stack=context.stack,
reason=DagsterEvaluationErrorReason.RUNTIME_TYPE_MISMATCH,
message="Value {path_msg} for enum type {type_name} must be a string".format(
type_name=context.config_type_snap.given_name,
path_msg=get_friendly_path_msg(context.stack),
),
message=f"Value {get_friendly_path_msg(context.stack)} for enum type {context.config_type_snap.given_name} must be a string",
error_data=RuntimeMismatchErrorData(context.config_type_snap, repr(config_value)),
)

Expand All @@ -228,11 +221,7 @@ def create_enum_value_missing_error(context: ContextData, config_value: object)
return EvaluationError(
stack=context.stack,
reason=DagsterEvaluationErrorReason.RUNTIME_TYPE_MISMATCH,
message="Value {path_msg} not in enum type {type_name} got {config_value}".format(
config_value=config_value,
type_name=context.config_type_snap.given_name,
path_msg=get_friendly_path_msg(context.stack),
),
message=f"Value {get_friendly_path_msg(context.stack)} not in enum type {context.config_type_snap.given_name} got {config_value}",
error_data=RuntimeMismatchErrorData(context.config_type_snap, repr(config_value)),
)

Expand Down Expand Up @@ -366,13 +355,8 @@ def create_scalar_error(context: ContextData, config_value: object) -> Evaluatio
stack=context.stack,
reason=DagsterEvaluationErrorReason.RUNTIME_TYPE_MISMATCH,
message=(
'Invalid scalar {path_msg}. Value "{config_value}" of type '
'"{type}" is not valid for expected type "{type_name}".'.format(
path_msg=get_friendly_path_msg(context.stack),
type_name=context.config_type_snap.given_name,
config_value=config_value,
type=type(config_value),
)
f'Invalid scalar {get_friendly_path_msg(context.stack)}. Value "{config_value}" of type '
f'"{type(config_value)}" is not valid for expected type "{context.config_type_snap.given_name}".'
),
error_data=RuntimeMismatchErrorData(context.config_type_snap, repr(config_value)),
)
Expand Down Expand Up @@ -410,12 +394,8 @@ def create_selector_multiple_fields_error(
stack=context.stack,
reason=DagsterEvaluationErrorReason.SELECTOR_FIELD_ERROR,
message=(
"You can only specify a single field {path_msg}. You specified {incoming_fields}. "
"The available fields are {defined_fields}"
).format(
incoming_fields=incoming_fields,
defined_fields=defined_fields,
path_msg=get_friendly_path_msg(context.stack),
f"You can only specify a single field {get_friendly_path_msg(context.stack)}. You specified {incoming_fields}. "
f"The available fields are {defined_fields}"
),
error_data=SelectorTypeErrorData(
config_type_snap=context.config_type_snap, incoming_fields=incoming_fields
Expand All @@ -434,9 +414,9 @@ def create_selector_multiple_fields_no_field_selected_error(
stack=context.stack,
reason=DagsterEvaluationErrorReason.SELECTOR_FIELD_ERROR,
message=(
"Must specify a field {path_msg} if more than one field is defined. "
"Defined fields: {defined_fields}"
).format(defined_fields=defined_fields, path_msg=get_friendly_path_msg(context.stack)),
f"Must specify a field {get_friendly_path_msg(context.stack)} if more than one field is defined. "
f"Defined fields: {defined_fields}"
),
error_data=SelectorTypeErrorData(
config_type_snap=context.config_type_snap, incoming_fields=[]
),
Expand Down Expand Up @@ -465,8 +445,8 @@ def create_selector_unspecified_value_error(context: ContextData) -> EvaluationE
stack=context.stack,
reason=DagsterEvaluationErrorReason.SELECTOR_FIELD_ERROR,
message=(
"Must specify the required field {path_msg}. Defined fields: {defined_fields}"
).format(defined_fields=defined_fields, path_msg=get_friendly_path_msg(context.stack)),
f"Must specify the required field {get_friendly_path_msg(context.stack)}. Defined fields: {defined_fields}"
),
error_data=SelectorTypeErrorData(
config_type_snap=context.config_type_snap, incoming_fields=[]
),
Expand Down Expand Up @@ -499,11 +479,7 @@ def create_failed_post_processing_error(
stack=context.stack,
reason=DagsterEvaluationErrorReason.FAILED_POST_PROCESSING,
message=(
"Post processing {path_msg} of original value {original_value} failed:\n{error}".format(
path_msg=get_friendly_path_msg(context.stack),
original_value=original_value,
error=error_data.to_string(),
)
f"Post processing {get_friendly_path_msg(context.stack)} of original value {original_value} failed:\n{error_data.to_string()}"
),
error_data=error_data,
)
Expand Down
8 changes: 3 additions & 5 deletions python_modules/dagster/dagster/_config/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,9 @@ def __init__(
raise DagsterInvalidDefinitionError(
(
"You have passed into a python enum value as the default value "
"into of a config enum type {name}. You must pass in the underlying "
"string represention as the default value. One of {value_set}."
).format(
value_set=[ev.config_value for ev in self.config_type.enum_values], # type: ignore
name=self.config_type.given_name,
f"into of a config enum type {self.config_type.given_name}. You must pass in the underlying "
"string represention as the default value. "
f"One of {[ev.config_value for ev in self.config_type.enum_values]}." # type: ignore
)
)

Expand Down
Loading

0 comments on commit db84034

Please sign in to comment.