Skip to content

Commit ee48d1a

Browse files
authored
Misc cleanup (#3229)
* Misc cleanup * Improve docstring * Remove component spec path * Replace zenml up with zenml login --local
1 parent 1dafa07 commit ee48d1a

17 files changed

+69
-106
lines changed

src/zenml/artifacts/artifact_config.py

-14
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
from zenml.logger import get_logger
2222
from zenml.metadata.metadata_types import MetadataType
2323
from zenml.utils.pydantic_utils import before_validator_handler
24-
from zenml.utils.string_utils import format_name_template
2524

2625
logger = get_logger(__name__)
2726

@@ -118,16 +117,3 @@ def _remove_old_attributes(cls, data: Dict[str, Any]) -> Dict[str, Any]:
118117
data.setdefault("artifact_type", ArtifactType.SERVICE)
119118

120119
return data
121-
122-
def _evaluated_name(self, substitutions: Dict[str, str]) -> Optional[str]:
123-
"""Evaluated name of the artifact.
124-
125-
Args:
126-
substitutions: Extra placeholders to use in the name template.
127-
128-
Returns:
129-
The evaluated name of the artifact.
130-
"""
131-
if self.name:
132-
return format_name_template(self.name, substitutions=substitutions)
133-
return self.name

src/zenml/cli/server.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ def logs(
469469
if server is None:
470470
cli_utils.error(
471471
"The local ZenML dashboard is not running. Please call `zenml "
472-
"up` first to start the ZenML dashboard locally."
472+
"login --local` first to start the ZenML dashboard locally."
473473
)
474474

475475
from zenml.zen_server.deploy.deployer import LocalServerDeployer

src/zenml/cli/stack.py

-3
Original file line numberDiff line numberDiff line change
@@ -1129,14 +1129,12 @@ def export_stack(
11291129
def _import_stack_component(
11301130
component_type: StackComponentType,
11311131
component_dict: Dict[str, Any],
1132-
component_spec_path: Optional[str] = None,
11331132
) -> UUID:
11341133
"""Import a single stack component with given type/config.
11351134
11361135
Args:
11371136
component_type: The type of component to import.
11381137
component_dict: Dict representation of the component to import.
1139-
component_spec_path: Path to the component spec file.
11401138
11411139
Returns:
11421140
The ID of the imported component.
@@ -1172,7 +1170,6 @@ def _import_stack_component(
11721170
component_type=component_type,
11731171
flavor=flavor,
11741172
configuration=config,
1175-
component_spec_path=component_spec_path,
11761173
)
11771174
return component.id
11781175

src/zenml/cli/stack_components.py

-1
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,6 @@ def copy_stack_component_command(
573573
component_type=component_to_copy.type,
574574
configuration=component_to_copy.configuration,
575575
labels=component_to_copy.labels,
576-
component_spec_path=component_to_copy.component_spec_path,
577576
)
578577
print_model_url(get_component_url(copied_component))
579578

src/zenml/cli/utils.py

-5
Original file line numberDiff line numberDiff line change
@@ -711,11 +711,6 @@ def print_stack_component_configuration(
711711

712712
console.print(rich_table)
713713

714-
if component.component_spec_path:
715-
declare(
716-
f"Component spec path for `mlstacks`: {component.component_spec_path}"
717-
)
718-
719714

720715
def expand_argument_value_from_file(name: str, value: str) -> str:
721716
"""Expands the value of an argument pointing to a file into the contents of that file.

src/zenml/client.py

-6
Original file line numberDiff line numberDiff line change
@@ -1979,15 +1979,13 @@ def create_stack_component(
19791979
flavor: str,
19801980
component_type: StackComponentType,
19811981
configuration: Dict[str, str],
1982-
component_spec_path: Optional[str] = None,
19831982
labels: Optional[Dict[str, Any]] = None,
19841983
) -> "ComponentResponse":
19851984
"""Registers a stack component.
19861985
19871986
Args:
19881987
name: The name of the stack component.
19891988
flavor: The flavor of the stack component.
1990-
component_spec_path: The path to the stack spec file.
19911989
component_type: The type of the stack component.
19921990
configuration: The configuration of the stack component.
19931991
labels: The labels of the stack component.
@@ -2016,7 +2014,6 @@ def create_stack_component(
20162014
name=name,
20172015
type=component_type,
20182016
flavor=flavor,
2019-
component_spec_path=component_spec_path,
20202017
configuration=configuration,
20212018
user=self.active_user.id,
20222019
workspace=self.active_workspace.id,
@@ -2033,7 +2030,6 @@ def update_stack_component(
20332030
name_id_or_prefix: Optional[Union[UUID, str]],
20342031
component_type: StackComponentType,
20352032
name: Optional[str] = None,
2036-
component_spec_path: Optional[str] = None,
20372033
configuration: Optional[Dict[str, Any]] = None,
20382034
labels: Optional[Dict[str, Any]] = None,
20392035
disconnect: Optional[bool] = None,
@@ -2047,7 +2043,6 @@ def update_stack_component(
20472043
update.
20482044
component_type: The type of the stack component to update.
20492045
name: The new name of the stack component.
2050-
component_spec_path: The new path to the stack spec file.
20512046
configuration: The new configuration of the stack component.
20522047
labels: The new labels of the stack component.
20532048
disconnect: Whether to disconnect the stack component from its
@@ -2072,7 +2067,6 @@ def update_stack_component(
20722067
update_model = ComponentUpdate(
20732068
workspace=self.active_workspace.id,
20742069
user=self.active_user.id,
2075-
component_spec_path=component_spec_path,
20762070
)
20772071

20782072
if name is not None:

src/zenml/model/model.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ def _get_or_create_model(self) -> "ModelResponse":
537537

538538
zenml_client = Client()
539539
# backup logic, if the Model class is used directly from the code
540-
self.name = format_name_template(self.name, substitutions={})
540+
self.name = format_name_template(self.name)
541541
if self.model_version_id:
542542
mv = zenml_client.get_model_version(
543543
model_version_name_or_number_or_id=self.model_version_id,
@@ -667,7 +667,7 @@ def _get_or_create_model_version(
667667

668668
# backup logic, if the Model class is used directly from the code
669669
if isinstance(self.version, str):
670-
self.version = format_name_template(self.version, substitutions={})
670+
self.version = format_name_template(self.version)
671671

672672
try:
673673
if self.version or self.model_version_id:

src/zenml/models/v2/core/component.py

-22
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,6 @@ class ComponentBase(BaseModel):
8181
title="The stack component labels.",
8282
)
8383

84-
component_spec_path: Optional[str] = Field(
85-
default=None,
86-
title="The path to the component spec used for mlstacks deployments.",
87-
)
88-
8984

9085
# ------------------ Request Model ------------------
9186

@@ -155,10 +150,6 @@ class ComponentUpdate(BaseUpdate):
155150
title="The stack component labels.",
156151
default=None,
157152
)
158-
component_spec_path: Optional[str] = Field(
159-
title="The path to the component spec used for mlstacks deployments.",
160-
default=None,
161-
)
162153
connector: Optional[UUID] = Field(
163154
title="The service connector linked to this stack component.",
164155
default=None,
@@ -201,10 +192,6 @@ class ComponentResponseMetadata(WorkspaceScopedResponseMetadata):
201192
default=None,
202193
title="The stack component labels.",
203194
)
204-
component_spec_path: Optional[str] = Field(
205-
default=None,
206-
title="The path to the component spec used for mlstacks deployments.",
207-
)
208195
connector_resource_id: Optional[str] = Field(
209196
default=None,
210197
description="The ID of a specific resource instance to "
@@ -325,15 +312,6 @@ def labels(self) -> Optional[Dict[str, Any]]:
325312
"""
326313
return self.get_metadata().labels
327314

328-
@property
329-
def component_spec_path(self) -> Optional[str]:
330-
"""The `component_spec_path` property.
331-
332-
Returns:
333-
the value of the property.
334-
"""
335-
return self.get_metadata().component_spec_path
336-
337315
@property
338316
def connector_resource_id(self) -> Optional[str]:
339317
"""The `connector_resource_id` property.

src/zenml/models/v2/core/pipeline_run.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ class PipelineRunResponseMetadata(WorkspaceScopedResponseMetadata):
237237
default=False,
238238
description="Whether a template can be created from this run.",
239239
)
240-
steps_substitutions: Dict[str, Dict[str, str]] = Field(
240+
step_substitutions: Dict[str, Dict[str, str]] = Field(
241241
title="Substitutions used in the step runs of this pipeline run.",
242242
default_factory=dict,
243243
)

src/zenml/orchestrators/step_launcher.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,8 @@ def _create_or_reuse_run(self) -> Tuple[PipelineRunResponse, bool]:
310310
and a boolean indicating whether the run was created or reused.
311311
"""
312312
start_time = datetime.utcnow()
313-
run_name = orchestrator_utils.get_run_name(
314-
run_name_template=self._deployment.run_name_template,
313+
run_name = string_utils.format_name_template(
314+
name_template=self._deployment.run_name_template,
315315
substitutions=self._deployment.pipeline_configuration._get_full_substitutions(
316316
start_time
317317
),

src/zenml/orchestrators/step_runner.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
parse_return_type_annotations,
5757
resolve_type_annotation,
5858
)
59-
from zenml.utils import materializer_utils, source_utils
59+
from zenml.utils import materializer_utils, source_utils, string_utils
6060
from zenml.utils.typing_utils import get_origin, is_union
6161

6262
if TYPE_CHECKING:
@@ -292,16 +292,15 @@ def _evaluate_artifact_names_in_collections(
292292
"""
293293
collections.append(output_annotations)
294294
for k, v in list(output_annotations.items()):
295-
_evaluated_name = None
296-
if v.artifact_config:
297-
_evaluated_name = v.artifact_config._evaluated_name(
298-
step_run.config.substitutions
295+
name = k
296+
if v.artifact_config and v.artifact_config.name:
297+
name = string_utils.format_name_template(
298+
v.artifact_config.name,
299+
substitutions=step_run.config.substitutions,
299300
)
300-
if _evaluated_name is None:
301-
_evaluated_name = k
302301

303302
for d in collections:
304-
d[_evaluated_name] = d.pop(k)
303+
d[name] = d.pop(k)
305304

306305
def _load_step(self) -> "BaseStep":
307306
"""Load the step instance.

src/zenml/orchestrators/utils.py

-24
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
from zenml.enums import AuthScheme, StackComponentType, StoreType
3333
from zenml.logger import get_logger
3434
from zenml.stack import StackComponent
35-
from zenml.utils.string_utils import format_name_template
3635

3736
logger = get_logger(__name__)
3837

@@ -196,29 +195,6 @@ def get_config_environment_vars(
196195
return environment_vars
197196

198197

199-
def get_run_name(run_name_template: str, substitutions: Dict[str, str]) -> str:
200-
"""Fill out the run name template to get a complete run name.
201-
202-
Args:
203-
run_name_template: The run name template to fill out.
204-
substitutions: The substitutions to use in the template.
205-
206-
Raises:
207-
ValueError: If the run name is empty.
208-
209-
Returns:
210-
The run name derived from the template.
211-
"""
212-
run_name = format_name_template(
213-
run_name_template, substitutions=substitutions
214-
)
215-
216-
if run_name == "":
217-
raise ValueError("Empty run names are not allowed.")
218-
219-
return run_name
220-
221-
222198
class register_artifact_store_filesystem:
223199
"""Context manager for the artifact_store/filesystem_registry dependency.
224200

src/zenml/pipelines/run_utils.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@
2323
StackResponse,
2424
)
2525
from zenml.orchestrators.publish_utils import publish_failed_pipeline_run
26-
from zenml.orchestrators.utils import get_run_name
2726
from zenml.stack import Flavor, Stack
28-
from zenml.utils import code_utils, notebook_utils, source_utils
27+
from zenml.utils import code_utils, notebook_utils, source_utils, string_utils
2928
from zenml.zen_stores.base_zen_store import BaseZenStore
3029

3130
if TYPE_CHECKING:
@@ -68,8 +67,8 @@ def create_placeholder_run(
6867
return None
6968
start_time = datetime.utcnow()
7069
run_request = PipelineRunRequest(
71-
name=get_run_name(
72-
run_name_template=deployment.run_name_template,
70+
name=string_utils.format_name_template(
71+
name_template=deployment.run_name_template,
7372
substitutions=deployment.pipeline_configuration._get_full_substitutions(
7473
start_time
7574
),

src/zenml/utils/string_utils.py

+15-8
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import random
1919
import string
2020
from datetime import datetime
21-
from typing import Any, Callable, Dict, TypeVar, cast
21+
from typing import Any, Callable, Dict, Optional, TypeVar, cast
2222

2323
from pydantic import BaseModel
2424

@@ -147,24 +147,26 @@ def validate_name(model: BaseModel) -> None:
147147

148148
def format_name_template(
149149
name_template: str,
150-
substitutions: Dict[str, str],
150+
substitutions: Optional[Dict[str, str]] = None,
151151
) -> str:
152152
"""Formats a name template with the given arguments.
153153
154-
By default, ZenML support Date and Time placeholders.
155-
E.g. `my_run_{date}_{time}` will be formatted as `my_run_1970_01_01_00_00_00`.
156-
Extra placeholders need to be explicitly passed in as kwargs.
154+
Default substitutions for `{date}` and `{time}` placeholders will be used if
155+
not included in the provided substitutions.
157156
158157
Args:
159158
name_template: The name template to format.
160-
substitutions: A dictionary of substitutions to use in the template.
159+
substitutions: Substitutions to use in the template.
161160
162161
Returns:
163162
The formatted name template.
164163
165164
Raises:
166-
KeyError: If a key in template is missing in the kwargs.
165+
KeyError: If a key in template is missing in the substitutions.
166+
ValueError: If the formatted name is empty.
167167
"""
168+
substitutions = substitutions or {}
169+
168170
if ("date" not in substitutions and "{date}" in name_template) or (
169171
"time" not in substitutions and "{time}" in name_template
170172
):
@@ -183,13 +185,18 @@ def format_name_template(
183185
substitutions.setdefault("time", start_time.strftime("%H_%M_%S_%f"))
184186

185187
try:
186-
return name_template.format(**substitutions)
188+
formatted_name = name_template.format(**substitutions)
187189
except KeyError as e:
188190
raise KeyError(
189191
f"Could not format the name template `{name_template}`. "
190192
f"Missing key: {e}"
191193
)
192194

195+
if not formatted_name:
196+
raise ValueError("Empty names are not allowed.")
197+
198+
return formatted_name
199+
193200

194201
def substitute_string(value: V, substitution_func: Callable[[str], str]) -> V:
195202
"""Recursively substitute strings in objects.

0 commit comments

Comments
 (0)