Skip to content

Commit

Permalink
Update ruff on requirements/lint-requirements.txt (mlflow#9120)
Browse files Browse the repository at this point in the history
Signed-off-by: Viktorius Suwandi <viktorius.tori@gmail.com>
Signed-off-by: harupy <hkawamura0130@gmail.com>
Co-authored-by: harupy <hkawamura0130@gmail.com>
  • Loading branch information
viktoriussuwandi and harupy committed Jul 23, 2023
1 parent 9d88ac5 commit aabfa91
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 156 deletions.
12 changes: 4 additions & 8 deletions mlflow/pyfunc/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,14 +380,10 @@ def copy_model_into_container(dockerfile_context_dir):
env_manager=self._env_manager,
)
else:
return """
ENV {disable_env}="true"
ENV {ENABLE_MLSERVER}={enable_mlserver}
""".format(
disable_env=DISABLE_ENV_CREATION,
ENABLE_MLSERVER=ENABLE_MLSERVER,
enable_mlserver=repr(enable_mlserver),
)
return f"""
ENV {DISABLE_ENV_CREATION}="true"
ENV {ENABLE_MLSERVER}={repr(enable_mlserver)}
"""

return copy_model_into_container

Expand Down
2 changes: 1 addition & 1 deletion requirements/lint-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pylint==2.14.4
ruff==0.0.278
ruff==0.0.280
rstcheck==6.1.1
black[jupyter]==23.7.0
# Use harupy's fork until https://github.com/adamchainz/blacken-docs/issues/214 is resolved
Expand Down
12 changes: 4 additions & 8 deletions tests/projects/test_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,20 +360,16 @@ def exec_cmd_mock_raise(cmd, *args, **kwargs): # pylint: disable=unused-argumen

def test_conda_environment_cleaned_up_when_pip_fails(tmp_path):
conda_yaml = tmp_path / "conda.yaml"
content = """
name: {name}
content = f"""
name: {uuid.uuid4().hex}
channels:
- conda-forge
dependencies:
- python={python_version}
- python={PYTHON_VERSION}
- pip
- pip:
- mlflow==999.999.999
""".format(
# Enforce creating a new environment
name=uuid.uuid4().hex,
python_version=PYTHON_VERSION,
)
"""
conda_yaml.write_text(content)
envs_before = mlflow.utils.conda._list_conda_environments()

Expand Down
65 changes: 24 additions & 41 deletions tests/recipes/test_evaluate_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ def test_evaluate_step_run(

recipe_yaml = tmp_recipe_root_path.joinpath(_RECIPE_CONFIG_FILE_NAME)
recipe_yaml.write_text(
"""
f"""
recipe: "regression/v1"
target_col: "y"
experiment:
tracking_uri: {tracking_uri}
tracking_uri: {mlflow.get_tracking_uri()}
steps:
evaluate:
validation_criteria:
Expand All @@ -73,10 +73,7 @@ def test_evaluate_step_run(
- name: weighted_mean_squared_error
function: weighted_mean_squared_error_func
greater_is_better: False
""".format(
tracking_uri=mlflow.get_tracking_uri(),
mae_threshold=mae_threshold,
)
"""
)
recipe_steps_dir = tmp_recipe_root_path.joinpath("steps")
recipe_steps_dir.mkdir(parents=True)
Expand Down Expand Up @@ -116,21 +113,19 @@ def test_evaluate_produces_expected_step_card(

recipe_yaml = tmp_recipe_root_path.joinpath(_RECIPE_CONFIG_FILE_NAME)
recipe_yaml.write_text(
"""
f"""
recipe: "classification/v1"
positive_class: "Iris-setosa"
target_col: "y"
primary_metric: "f1_score"
experiment:
tracking_uri: {tracking_uri}
tracking_uri: {mlflow.get_tracking_uri()}
steps:
evaluate:
validation_criteria:
- metric: f1_score
threshold: 10
""".format(
tracking_uri=mlflow.get_tracking_uri(),
)
"""
)
recipe_steps_dir = tmp_recipe_root_path.joinpath("steps")
recipe_steps_dir.mkdir(parents=True)
Expand All @@ -154,16 +149,14 @@ def test_no_validation_criteria(tmp_recipe_root_path: Path, tmp_recipe_exec_path

recipe_yaml = tmp_recipe_root_path.joinpath(_RECIPE_CONFIG_FILE_NAME)
recipe_yaml.write_text(
"""
f"""
recipe: "regression/v1"
target_col: "y"
experiment:
tracking_uri: {tracking_uri}
tracking_uri: {mlflow.get_tracking_uri()}
steps:
evaluate:
""".format(
tracking_uri=mlflow.get_tracking_uri()
)
"""
)
recipe_steps_dir = tmp_recipe_root_path.joinpath("steps")
recipe_steps_dir.mkdir(parents=True)
Expand All @@ -185,21 +178,19 @@ def test_no_validation_criteria(tmp_recipe_root_path: Path, tmp_recipe_exec_path
def test_validation_criteria_contain_undefined_metrics(tmp_recipe_root_path: Path):
recipe_yaml = tmp_recipe_root_path.joinpath(_RECIPE_CONFIG_FILE_NAME)
recipe_yaml.write_text(
"""
f"""
recipe: "regression/v1"
target_col: "y"
experiment:
tracking_uri: {tracking_uri}
tracking_uri: {mlflow.get_tracking_uri()}
steps:
evaluate:
validation_criteria:
- metric: root_mean_squared_error
threshold: 100
- metric: undefined_metric
threshold: 100
""".format(
tracking_uri=mlflow.get_tracking_uri()
)
"""
)
recipe_steps_dir = tmp_recipe_root_path.joinpath("steps")
recipe_steps_dir.mkdir(parents=True)
Expand All @@ -220,11 +211,11 @@ def test_custom_metric_function_does_not_exist(
):
recipe_yaml = tmp_recipe_root_path.joinpath(_RECIPE_CONFIG_FILE_NAME)
recipe_yaml.write_text(
"""
f"""
recipe: "regression/v1"
target_col: "y"
experiment:
tracking_uri: {tracking_uri}
tracking_uri: {mlflow.get_tracking_uri()}
steps:
evaluate:
validation_criteria:
Expand All @@ -234,9 +225,7 @@ def test_custom_metric_function_does_not_exist(
- name: weighted_mean_squared_error
function: weighted_mean_squared_error
greater_is_better: False
""".format(
tracking_uri=mlflow.get_tracking_uri()
)
"""
)
recipe_steps_dir = tmp_recipe_root_path.joinpath("steps")
recipe_steps_dir.mkdir(parents=True)
Expand All @@ -262,11 +251,11 @@ def test_custom_metrics_module_does_not_exist(
):
recipe_yaml = tmp_recipe_root_path.joinpath(_RECIPE_CONFIG_FILE_NAME)
recipe_yaml.write_text(
"""
f"""
recipe: "regression/v1"
target_col: "y"
experiment:
tracking_uri: {tracking_uri}
tracking_uri: {mlflow.get_tracking_uri()}
steps:
evaluate:
validation_criteria:
Expand All @@ -276,9 +265,7 @@ def test_custom_metrics_module_does_not_exist(
- name: weighted_mean_squared_error
function: weighted_mean_squared_error
greater_is_better: False
""".format(
tracking_uri=mlflow.get_tracking_uri()
)
"""
)
recipe_steps_dir = tmp_recipe_root_path.joinpath("steps")
recipe_steps_dir.mkdir(parents=True)
Expand All @@ -302,11 +289,11 @@ def test_custom_metrics_override_builtin_metrics(

recipe_yaml = tmp_recipe_root_path.joinpath(_RECIPE_CONFIG_FILE_NAME)
recipe_yaml.write_text(
"""
f"""
recipe: "regression/v1"
target_col: "y"
experiment:
tracking_uri: {tracking_uri}
tracking_uri: {mlflow.get_tracking_uri()}
steps:
evaluate:
validation_criteria:
Expand All @@ -321,9 +308,7 @@ def test_custom_metrics_override_builtin_metrics(
- name: root_mean_squared_error
function: root_mean_squared_error
greater_is_better: False
""".format(
tracking_uri=mlflow.get_tracking_uri()
)
"""
)
recipe_steps_dir = tmp_recipe_root_path.joinpath("steps")
recipe_steps_dir.mkdir(parents=True)
Expand Down Expand Up @@ -369,19 +354,17 @@ def test_evaluate_step_writes_card_with_model_and_run_links_on_databricks(

recipe_yaml = tmp_recipe_root_path.joinpath(_RECIPE_CONFIG_FILE_NAME)
recipe_yaml.write_text(
"""
f"""
recipe: "regression/v1"
target_col: "y"
experiment:
tracking_uri: {tracking_uri}
tracking_uri: {mlflow.get_tracking_uri()}
steps:
evaluate:
validation_criteria:
- metric: root_mean_squared_error
threshold: 1_000_000
""".format(
tracking_uri=mlflow.get_tracking_uri()
)
"""
)

evaluate_step_output_dir = tmp_recipe_exec_path.joinpath("steps", "evaluate", "outputs")
Expand Down
8 changes: 3 additions & 5 deletions tests/recipes/test_predict_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,12 @@ def predict_step_output_dir(tmp_recipe_root_path: Path, tmp_recipe_exec_path: Pa
predict_step_output_dir.mkdir(parents=True)
recipe_yaml = tmp_recipe_root_path.joinpath(_RECIPE_CONFIG_FILE_NAME)
recipe_yaml.write_text(
"""
f"""
recipe: "regression/v1"
experiment:
name: "test"
tracking_uri: {tracking_uri}
""".format(
tracking_uri=mlflow.get_tracking_uri(),
)
tracking_uri: {mlflow.get_tracking_uri()}
"""
)
return predict_step_output_dir

Expand Down
48 changes: 17 additions & 31 deletions tests/recipes/test_register_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ def test_register_step_run(
)
recipe_yaml = tmp_recipe_root_path.joinpath(_RECIPE_CONFIG_FILE_NAME)
recipe_yaml.write_text(
"""
f"""
recipe: "regression/v1"
target_col: "y"
experiment:
tracking_uri: {tracking_uri}
tracking_uri: {mlflow.get_tracking_uri()}
model_registry:
model_name: "demo_model"
steps:
Expand All @@ -53,16 +53,12 @@ def test_register_step_run(
- metric: weighted_mean_squared_error
threshold: 1_000_000
register:
{allow_non_validated_model}
{register_flag}
custom_metrics:
- name: weighted_mean_squared_error
function: weighted_mean_squared_error
greater_is_better: False
""".format(
tracking_uri=mlflow.get_tracking_uri(),
mae_threshold=mae_threshold,
allow_non_validated_model=register_flag,
)
"""
)
recipe_steps_dir = tmp_recipe_root_path.joinpath("steps")
recipe_steps_dir.mkdir(parents=True)
Expand Down Expand Up @@ -106,21 +102,18 @@ def test_register_with_no_validation_criteria(
)
recipe_yaml = tmp_recipe_root_path.joinpath(_RECIPE_CONFIG_FILE_NAME)
recipe_yaml.write_text(
"""
f"""
recipe: "regression/v1"
target_col: "y"
experiment:
tracking_uri: {tracking_uri}
tracking_uri: {mlflow.get_tracking_uri()}
model_registry:
model_name: "demo_model"
steps:
evaluate:
register:
{allow_non_validated_model}
""".format(
tracking_uri=mlflow.get_tracking_uri(),
allow_non_validated_model=register_flag,
)
{register_flag}
"""
)
recipe_steps_dir = tmp_recipe_root_path.joinpath("steps")
recipe_steps_dir.mkdir(parents=True)
Expand Down Expand Up @@ -151,13 +144,13 @@ def test_usage_tracking_correctly_added(
)
recipe_yaml = tmp_recipe_root_path.joinpath(_RECIPE_CONFIG_FILE_NAME)
recipe_yaml.write_text(
"""
f"""
recipe: "regression/v1"
target_col: "y"
model_registry:
model_name: "demo_model"
experiment:
tracking_uri: {tracking_uri}
tracking_uri: {mlflow.get_tracking_uri()}
steps:
evaluate:
validation_criteria:
Expand All @@ -171,9 +164,7 @@ def test_usage_tracking_correctly_added(
- name: weighted_mean_squared_error
function: weighted_mean_squared_error
greater_is_better: False
""".format(
tracking_uri=mlflow.get_tracking_uri(),
)
"""
)
recipe_steps_dir = tmp_recipe_root_path.joinpath("steps")
recipe_steps_dir.mkdir(parents=True)
Expand Down Expand Up @@ -211,11 +202,11 @@ def test_register_uri(
recipe_yaml = tmp_recipe_root_path.joinpath(_RECIPE_CONFIG_FILE_NAME)
registry_uri = registry_uri_path
recipe_yaml.write_text(
"""
f"""
recipe: "regression/v1"
target_col: "y"
experiment:
tracking_uri: {tracking_uri}
tracking_uri: {mlflow.get_tracking_uri()}
model_registry:
registry_uri: {registry_uri}
model_name: "demo_model"
Expand All @@ -232,10 +223,7 @@ def test_register_uri(
- name: weighted_mean_squared_error
function: weighted_mean_squared_error
greater_is_better: False
""".format(
tracking_uri=mlflow.get_tracking_uri(),
registry_uri=registry_uri,
)
"""
)
recipe_steps_dir = tmp_recipe_root_path.joinpath("steps")
recipe_steps_dir.mkdir(parents=True)
Expand Down Expand Up @@ -271,21 +259,19 @@ def test_register_step_writes_card_with_model_link_and_version_link_on_databrick

recipe_yaml = tmp_recipe_root_path.joinpath(_RECIPE_CONFIG_FILE_NAME)
recipe_yaml.write_text(
"""
f"""
recipe: "regression/v1"
target_col: "y"
experiment:
tracking_uri: {tracking_uri}
tracking_uri: {mlflow.get_tracking_uri()}
model_registry:
model_name: "demo_model"
steps:
evaluate:
validation_criteria:
- metric: root_mean_squared_error
threshold: 1_000_000
""".format(
tracking_uri=mlflow.get_tracking_uri()
)
"""
)

evaluate_step_output_dir, register_step_output_dir = setup_model_and_evaluate(
Expand Down
Loading

0 comments on commit aabfa91

Please sign in to comment.