Skip to content

Commit

Permalink
⬆️ Upgrade black to 2023 major version
Browse files Browse the repository at this point in the history
  • Loading branch information
Galileo-Galilei committed Jul 23, 2023
1 parent d55ee7d commit 069c4ee
Show file tree
Hide file tree
Showing 24 changed files with 32 additions and 118 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
exclude: ^kedro_mlflow/template/project/run.py$
repos:
- repo: https://github.com/psf/black
rev: 22.12.0
rev: 23.7.0
hooks:
- id: black
language_version: python3.9
language_version: python3.10
- repo: https://github.com/timothycrosley/isort
rev: 5.12.0
hooks:
Expand All @@ -21,7 +21,7 @@ repos:
rev: v1.12.1
hooks:
- id: blacken-docs
additional_dependencies: [black==22.12.0]
additional_dependencies: [black==23.7.0]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
Expand Down
1 change: 0 additions & 1 deletion kedro_mlflow/config/kedro_mlflow_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ class Config:


class UiOptions(BaseModel):

port: str = "5000"
host: str = "127.0.0.1"

Expand Down
1 change: 0 additions & 1 deletion kedro_mlflow/framework/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ def ui(env: str, port: str, host: str):
project_path=project_path,
env=env,
) as session:

context = session.load_context()
host = host or context.mlflow.ui.host
port = port or context.mlflow.ui.port
Expand Down
1 change: 0 additions & 1 deletion kedro_mlflow/framework/hooks/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
def _assert_mlflow_enabled(
pipeline_name: str, mlflow_config: KedroMlflowConfig
) -> bool:

# TODO: we may want to enable to filter on tags
# but we need to deal with the case when several tags are passed
# what to do if 1 out of 2 is in the list?
Expand Down
2 changes: 0 additions & 2 deletions kedro_mlflow/io/artifacts/mlflow_artifact_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def __new__(
artifact_path: str = None,
credentials: Dict[str, Any] = None,
):

data_set, data_set_args = parse_dataset_definition(config=data_set)

# fake inheritance : this mlflow class should be a mother class which wraps
Expand All @@ -47,7 +46,6 @@ def _logging_activated(self, flag):
self.__logging_activated = flag

def _save(self, data: Any):

# _get_save_path needs to be called before super, otherwise
# it will throw exception that file under path already exist.
if hasattr(self, "_version"):
Expand Down
21 changes: 8 additions & 13 deletions kedro_mlflow/io/models/mlflow_model_logger_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,9 @@ def model_uri(self):
run_id = mlflow.active_run().info.run_id
if run_id is None:
raise DataSetError(
(
"To access the model_uri, you must either: "
"\n - specifiy 'run_id' "
"\n - have an active run to retrieve data from"
)
"To access the model_uri, you must either: "
"\n - specifiy 'run_id' "
"\n - have an active run to retrieve data from"
)

model_uri = f"runs:/{run_id}/{self._artifact_path}"
Expand Down Expand Up @@ -104,13 +102,11 @@ def _save(self, model: Any) -> None:
if mlflow.active_run():
# it is not possible to log in a run which is not the current opened one
raise DataSetError(
(
"'run_id' cannot be specified"
" if there is an mlflow active run."
"Run_id mismatch: "
f"\n - 'run_id'={self._run_id}"
f"\n - active_run id={mlflow.active_run().info.run_id}"
)
"'run_id' cannot be specified"
" if there is an mlflow active run."
"Run_id mismatch: "
f"\n - 'run_id'={self._run_id}"
f"\n - active_run id={mlflow.active_run().info.run_id}"
)
else:
# if the run id is specified and there is no opened run,
Expand All @@ -123,7 +119,6 @@ def _save(self, model: Any) -> None:
self._save_model_in_run(model)

def _save_model_in_run(self, model):

if self._flavor == "mlflow.pyfunc":
# PyFunc models utilise either `python_model` or `loader_module`
# workflow. We we assign the passed `model` object to one of those keys
Expand Down
1 change: 0 additions & 1 deletion kedro_mlflow/io/models/mlflow_model_saver_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def __init__(
log_args: Dict[str, Any] = None,
version: Version = None,
) -> None:

"""Initialize the Kedro MlflowModelDataSet.
Parameters are passed from the Data Catalog.
Expand Down
25 changes: 7 additions & 18 deletions kedro_mlflow/mlflow/kedro_pipeline_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ def copy_mode(self):

@copy_mode.setter
def copy_mode(self, copy_mode):

if isinstance(copy_mode, str) or copy_mode is None:
# if it is a string, we must create manually the dictionary
# of all catalog entries with this copy_mode
Expand All @@ -105,7 +104,6 @@ def copy_mode(self, copy_mode):
)

def _extract_pipeline_catalog(self, catalog: DataCatalog) -> DataCatalog:

sub_catalog = DataCatalog()
for data_set_name in self.pipeline.inputs():
if data_set_name == self.input_name:
Expand Down Expand Up @@ -137,18 +135,15 @@ def _extract_pipeline_catalog(self, catalog: DataCatalog) -> DataCatalog:
sub_catalog.add(data_set_name=data_set_name, data_set=data_set)
except KeyError:
raise KedroPipelineModelError(
(
f"The provided catalog must contains '{data_set_name}' data_set "
"since it is the input of the pipeline."
)
f"The provided catalog must contains '{data_set_name}' data_set "
"since it is the input of the pipeline."
)

return sub_catalog

def extract_pipeline_artifacts(
self, parameters_saving_folder: Optional[Path] = None
):

artifacts = {}
for name, dataset in self.initial_catalog._data_sets.items():
if name != self.input_name:
Expand All @@ -163,10 +158,8 @@ def extract_pipeline_artifacts(
persisted_dataset.save(dataset.load())
artifact_path = absolute_param_path.as_uri()
self._logger.info(
(
f"The parameter '{name[7:]}' is persisted (as pickle) "
"at the following location: f'{artifact_path}'"
)
f"The parameter '{name[7:]}' is persisted (as pickle) "
"at the following location: f'{artifact_path}'"
)
else:
# In this second case, we know it cannot be a MemoryDataSet
Expand All @@ -180,7 +173,6 @@ def extract_pipeline_artifacts(
return artifacts

def load_context(self, context):

# a consistency check is made when loading the model
# it would be better to check when saving the model
# but we rely on a mlflow function for saving, and it is unaware of kedro
Expand All @@ -195,11 +187,9 @@ def load_context(self, context):
kedro_artifacts_keys - mlflow_artifacts_keys
)
raise ValueError(
(
"Provided artifacts do not match catalog entries:"
f"\n - 'artifacts - inference.inputs()' = : {in_artifacts_but_not_inference}"
f"\n - 'inference.inputs() - artifacts' = : {in_inference_but_not_artifacts}"
)
"Provided artifacts do not match catalog entries:"
f"\n - 'artifacts - inference.inputs()' = : {in_artifacts_but_not_inference}"
f"\n - 'inference.inputs() - artifacts' = : {in_inference_but_not_artifacts}"
)

updated_catalog = self.initial_catalog.shallow_copy()
Expand All @@ -208,7 +198,6 @@ def load_context(self, context):
self.loaded_catalog.save(name=name, data=updated_catalog.load(name))

def predict(self, context, model_input):

# we create an empty hook manager but do NOT register hooks
# because we want this model be executable outside of a kedro project
hook_manager = _create_hook_manager()
Expand Down
34 changes: 13 additions & 21 deletions kedro_mlflow/pipeline/pipeline_ml.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ def __init__(
kpm_kwargs: Optional[Dict[str, str]] = None,
log_model_kwargs: Optional[Dict[str, str]] = None,
):

"""Store all necessary information for calling mlflow.log_model in the pipeline.
Args:
Expand Down Expand Up @@ -110,10 +109,8 @@ def input_name(self, name: str) -> None:
pp_allowed_names = "\n - ".join(allowed_names)
if name not in allowed_names:
raise KedroMlflowPipelineMLError(
(
f"input_name='{name}' but it must be an input of 'inference'"
f", i.e. one of: \n - {pp_allowed_names}"
)
f"input_name='{name}' but it must be an input of 'inference'"
f", i.e. one of: \n - {pp_allowed_names}"
)
self._input_name = name

Expand All @@ -122,17 +119,14 @@ def _check_inference(self, inference: Pipeline) -> None:
outputs_txt = "\n - ".join(inference.outputs())
if len(inference.outputs()) != 1:
raise KedroMlflowPipelineMLError(
(
"The inference pipeline must have one"
" and only one output. You are trying"
" to set a inference pipeline with"
f" '{nb_outputs}' output(s): \n - {outputs_txt}"
" "
)
"The inference pipeline must have one"
" and only one output. You are trying"
" to set a inference pipeline with"
f" '{nb_outputs}' output(s): \n - {outputs_txt}"
" "
)

def _check_consistency(self) -> None:

inference_parameters = {
input for input in self.inference.inputs() if input.startswith("params:")
}
Expand All @@ -148,14 +142,12 @@ def _check_consistency(self) -> None:
if len(free_inputs_set) > 0:
input_set_txt = "\n - ".join(free_inputs_set)
raise KedroMlflowPipelineMLError(
(
"The following inputs are free for the inference pipeline:\n"
f" - {input_set_txt}."
" \nNo free input is allowed."
" Please make sure that 'inference.inputs()' are all"
" in 'training.all_outputs() + training.inputs()'"
"except 'input_name' and parameters which starts with 'params:'."
)
"The following inputs are free for the inference pipeline:\n"
f" - {input_set_txt}."
" \nNo free input is allowed."
" Please make sure that 'inference.inputs()' are all"
" in 'training.all_outputs() + training.inputs()'"
"except 'input_name' and parameters which starts with 'params:'."
)

return None
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def _parse_requirements(path, encoding="utf-8"):
"pytest-mock>=3.1.0, <4.0.0",
"scikit-learn>=0.23.0, <1.3.0",
"flake8==6.0.0", # ensure consistency with pre-commit
"black==22.12.0", # pin black version because it is not compatible with a pip range (because of non semver version number)
"black==23.7.0", # pin black version because it is not compatible with a pip range (because of non semver version number)
"isort==5.12.0", # ensure consistency with pre-commit
],
"dev": [
Expand Down
11 changes: 0 additions & 11 deletions tests/config/test_kedro_mlflow_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def test_kedro_mlflow_config_init():
def test_kedro_mlflow_config_new_experiment_does_not_exists(
kedro_project_with_mlflow_conf,
):

config = KedroMlflowConfig(
server=dict(mlflow_tracking_uri="mlruns"),
tracking=dict(experiment=dict(name="exp1")),
Expand All @@ -57,7 +56,6 @@ def test_kedro_mlflow_config_new_experiment_does_not_exists(
def test_kedro_mlflow_config_with_use_env_tracking_uri(
kedro_project_with_mlflow_conf,
):

os.environ["MLFLOW_TRACKING_URI"] = "my_mlruns"

# default key server.mlflow_tracking_uri=None, so the environment variable will be used
Expand All @@ -72,7 +70,6 @@ def test_kedro_mlflow_config_with_use_env_tracking_uri(


def test_kedro_mlflow_config_experiment_exists(kedro_project_with_mlflow_conf):

# create an experiment with the same name
mlflow_tracking_uri = (
kedro_project_with_mlflow_conf / "conf" / "local" / "mlruns"
Expand All @@ -94,7 +91,6 @@ def test_kedro_mlflow_config_experiment_exists(kedro_project_with_mlflow_conf):


def test_kedro_mlflow_config_experiment_was_deleted(kedro_project_with_mlflow_conf):

# create an experiment with the same name and then delete it
mlflow_tracking_uri = (kedro_project_with_mlflow_conf / "mlruns").as_uri()
mlflow_client = MlflowClient(mlflow_tracking_uri)
Expand Down Expand Up @@ -122,7 +118,6 @@ def test_kedro_mlflow_config_experiment_was_deleted(kedro_project_with_mlflow_co
def test_kedro_mlflow_config_setup_set_experiment_globally(
kedro_project_with_mlflow_conf,
):

mlflow_tracking_uri = (kedro_project_with_mlflow_conf / "mlruns").as_uri()

# the config must restore properly the experiment
Expand Down Expand Up @@ -157,7 +152,6 @@ def test_kedro_mlflow_config_setup_set_experiment_globally(


def test_kedro_mlflow_config_setup_set_tracking_uri(kedro_project_with_mlflow_conf):

mlflow_tracking_uri = (kedro_project_with_mlflow_conf / "awesome_tracking").as_uri()

config = KedroMlflowConfig(
Expand All @@ -174,7 +168,6 @@ def test_kedro_mlflow_config_setup_set_tracking_uri(kedro_project_with_mlflow_co


def test_kedro_mlflow_config_setup_set_registry_uri(kedro_project_with_mlflow_conf):

mlflow_registry_uri = (
kedro_project_with_mlflow_conf / "awesome_registry.db"
).as_uri()
Expand All @@ -194,7 +187,6 @@ def test_kedro_mlflow_config_setup_set_registry_uri(kedro_project_with_mlflow_co


def test_kedro_mlflow_config_setup_export_credentials(kedro_project_with_mlflow_conf):

(kedro_project_with_mlflow_conf / "conf/base/credentials.yml").write_text(
yaml.dump(dict(my_mlflow_creds=dict(fake_mlflow_cred="my_fake_cred")))
)
Expand Down Expand Up @@ -244,23 +236,20 @@ def test_kedro_mlflow_config_setup_tracking_priority(kedro_project_with_mlflow_c


def test_validate_uri_local_relative_path(kedro_project_with_mlflow_conf):

validated_uri = _validate_uri(
uri=r"mlruns", project_path=kedro_project_with_mlflow_conf
)
assert validated_uri == (kedro_project_with_mlflow_conf / "mlruns").as_uri()


def test_validate_uri_local_absolute_posix(kedro_project_with_mlflow_conf, tmp_path):

validated_uri = _validate_uri(
uri=tmp_path.as_posix(), project_path=kedro_project_with_mlflow_conf
)
assert validated_uri == tmp_path.as_uri()


def test_validate_uri_local_absolute_uri(kedro_project_with_mlflow_conf, tmp_path):

validated_uri = _validate_uri(
uri=tmp_path.as_uri(), project_path=kedro_project_with_mlflow_conf
)
Expand Down
4 changes: 0 additions & 4 deletions tests/framework/cli/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ def test_cli_init_existing_config_force_option(

bootstrap_project(kedro_project)
with KedroSession.create(project_path=kedro_project) as session:

# emulate first call by writing a mlflow.yml file
yaml_str = yaml.dump(dict(server=dict(mlflow_tracking_uri="toto")))
(
Expand Down Expand Up @@ -197,7 +196,6 @@ def test_cli_init_with_wrong_env(monkeypatch, kedro_project, env):
# other solution is to use pytest-xprocess
# TODO: create an initlaized_kedro_project fixture with a global scope
def test_ui_is_up(monkeypatch, mocker, kedro_project_with_mlflow_conf):

monkeypatch.chdir(kedro_project_with_mlflow_conf)
cli_runner = CliRunner()

Expand Down Expand Up @@ -233,7 +231,6 @@ def test_ui_is_up(monkeypatch, mocker, kedro_project_with_mlflow_conf):
def test_ui_overwrite_conf_at_runtime(
monkeypatch, mocker, kedro_project_with_mlflow_conf
):

monkeypatch.chdir(kedro_project_with_mlflow_conf)
cli_runner = CliRunner()

Expand All @@ -257,7 +254,6 @@ def test_ui_overwrite_conf_at_runtime(


def test_ui_open_http_uri(monkeypatch, mocker, tmp_path):

config = {
"output_dir": tmp_path,
"kedro_version": kedro_version,
Expand Down
Loading

0 comments on commit 069c4ee

Please sign in to comment.