Skip to content

Commit 150594c

Browse files
authored
[mldesigner] Centralize private imports for mldesigner (Azure#27220)
* Add mldesigner __init__ * sort modules order * add load_environment * remove public functions/entities from __init__.py * update new imports * update * update * update * update * have 3 category * reduce imports * update * update test * update * update * Revert "update" This reverts commit 6a20b1617adc1cdc82294fa0f0c2a774b10ab0f0. * update
1 parent 797f8dd commit 150594c

File tree

3 files changed

+139
-0
lines changed

3 files changed

+139
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# ---------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# ---------------------------------------------------------
4+
5+
"""
6+
This file stores functions and objects that will be used in mldesigner package.
7+
DO NOT change the module names in "all" list. If the interface has changed in source code, wrap it here and keep
8+
original function/module names the same as before, otherwise mldesigner will be broken by this change.
9+
"""
10+
11+
__path__ = __import__("pkgutil").extend_path(__path__, __name__) # type: ignore
12+
13+
from azure.ai.ml.entities._component.component_factory import component_factory
14+
from azure.ai.ml.entities._job.pipeline._load_component import _generate_component_function
15+
from azure.ai.ml.entities._inputs_outputs import _get_param_with_standard_annotation
16+
from azure.ai.ml._internal.entities._additional_includes import _AdditionalIncludes # pylint: disable=unused-import
17+
from azure.ai.ml._utils._asset_utils import get_ignore_file
18+
from azure.ai.ml._utils.utils import try_enable_internal_components
19+
from azure.ai.ml._internal.entities import InternalComponent # pylint: disable=unused-import
20+
from azure.ai.ml.dsl._condition import condition
21+
from azure.ai.ml.dsl._do_while import do_while
22+
from azure.ai.ml.dsl._group_decorator import group
23+
24+
from ._constants import V1_COMPONENT_TO_NODE
25+
26+
component_factory_load_from_dict = component_factory.load_from_dict
27+
28+
29+
__all__ = [
30+
# to be put in main package
31+
"condition",
32+
"do_while",
33+
"group",
34+
35+
# must keep
36+
"get_ignore_file",
37+
"_get_param_with_standard_annotation",
38+
"_generate_component_function",
39+
"component_factory_load_from_dict",
40+
"V1_COMPONENT_TO_NODE",
41+
"try_enable_internal_components",
42+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# ---------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# ---------------------------------------------------------
4+
5+
"""
6+
This file stores constants that will be used in mldesigner package.
7+
"""
8+
from azure.ai.ml._internal._schema.component import NodeType as V1NodeType
9+
from azure.ai.ml._internal.entities import (
10+
Ae365exepool,
11+
Command as InternalCommand,
12+
Parallel as InternalParallel,
13+
DataTransfer,
14+
Distributed,
15+
HDInsight,
16+
Hemera,
17+
Scope,
18+
Starlite,
19+
)
20+
21+
V1_COMPONENT_TO_NODE = {
22+
V1NodeType.SCOPE: Scope,
23+
V1NodeType.COMMAND: InternalCommand,
24+
V1NodeType.PARALLEL: InternalParallel,
25+
V1NodeType.DATA_TRANSFER: DataTransfer,
26+
V1NodeType.DISTRIBUTED: Distributed,
27+
V1NodeType.HDI: HDInsight,
28+
V1NodeType.STARLITE: Starlite,
29+
V1NodeType.HEMERA: Hemera,
30+
V1NodeType.AE365EXEPOOL: Ae365exepool,
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import pytest
2+
from azure.ai.ml import Input
3+
from azure.ai.ml.entities import(
4+
Component,
5+
CommandComponent,
6+
PipelineComponent,
7+
ValidationResult,
8+
)
9+
from azure.ai.ml.dsl._mldesigner import(
10+
_AdditionalIncludes,
11+
InternalComponent,
12+
)
13+
from azure.ai.ml.entities._builders.base_node import BaseNode
14+
from azure.ai.ml.entities._inputs_outputs import GroupInput
15+
from azure.ai.ml.entities._job.pipeline._io import PipelineInput, NodeOutput, NodeInput
16+
17+
18+
@pytest.mark.unittest
19+
@pytest.mark.pipeline_test
20+
class TestMldesignerImports:
21+
"""
22+
The assertions are NOT SUPPOSED TO BE CHANGED once they are added.
23+
24+
The attributes are needed for a certain version of mldesigner package, modifying or deleting any of them will cause
25+
compatibility issues. If there are new dependencies for mldesigner package, add new assertions in this file.
26+
"""
27+
def test_necessay_attributes(self):
28+
assert hasattr(Component, "_customized_validate")
29+
assert hasattr(Component, "_source_path")
30+
assert hasattr(CommandComponent, "_to_dict")
31+
assert hasattr(CommandComponent, "_source_path")
32+
assert hasattr(PipelineComponent, "_to_dict")
33+
assert hasattr(PipelineComponent, "_source_path")
34+
assert hasattr(PipelineComponent, "jobs")
35+
assert hasattr(InternalComponent, "_to_dict")
36+
assert hasattr(InternalComponent, "_source_path")
37+
assert hasattr(InternalComponent, "_additional_includes")
38+
assert hasattr(_AdditionalIncludes, "with_includes")
39+
assert hasattr(_AdditionalIncludes, "_code_path")
40+
assert hasattr(_AdditionalIncludes, "_includes")
41+
assert hasattr(ValidationResult, "passed")
42+
assert hasattr(ValidationResult, "error_messages")
43+
44+
def test_necessary_attributes_for_input(self):
45+
input_obj = Input()
46+
assert hasattr(input_obj, "type")
47+
assert hasattr(input_obj, "_is_enum")
48+
assert hasattr(input_obj, "default")
49+
assert hasattr(input_obj, "min")
50+
assert hasattr(input_obj, "max")
51+
assert hasattr(input_obj, "optional")
52+
assert hasattr(input_obj, "_is_literal")
53+
assert hasattr(input_obj, "_get_python_builtin_type_str")
54+
assert hasattr(input_obj, "_get_param_with_standard_annotation")
55+
56+
node_input_obj = NodeInput(name="sdk", meta=input_obj)
57+
assert hasattr(node_input_obj, "_meta")
58+
assert hasattr(node_input_obj, "_data")
59+
60+
def test_class_names(self):
61+
"""These class are undirectly used in mldesigner by their class names"""
62+
assert BaseNode.__name__ == "BaseNode"
63+
assert GroupInput.__name__ == "GroupInput"
64+
assert PipelineInput.__name__ == "PipelineInput"
65+
assert NodeInput.__name__ == "NodeInput"
66+
assert NodeOutput.__name__ == "NodeOutput"

0 commit comments

Comments
 (0)