Skip to content

Commit 314e79b

Browse files
authored
[ML][Pipelines] fix: internal snapshot id calculation ignore files (Azure#28335)
* fix: make test_additional_includes_ignore stable * fix: ignore files in internal snapshot id calculation
1 parent 50b3cd4 commit 314e79b

File tree

2 files changed

+40
-21
lines changed

2 files changed

+40
-21
lines changed

sdk/ml/azure-ai-ml/azure/ai/ml/_internal/entities/component.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def _get_snapshot_id(
219219
:type ignore_file: InternalComponentIgnoreFile
220220
:return: The snapshot id of a component in ml-components with code_path as its working directory.
221221
"""
222-
curr_root = create_merkletree(code_path, lambda x: ignore_file.is_file_excluded(code_path))
222+
curr_root = create_merkletree(code_path, ignore_file.is_file_excluded)
223223
snapshot_id = str(UUID(curr_root.hexdigest_hash[::4]))
224224
return snapshot_id
225225

sdk/ml/azure-ai-ml/tests/internal/unittests/test_component.py

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -358,35 +358,32 @@ def test_additional_includes(self) -> None:
358358
assert not code_path.is_dir()
359359

360360
def test_additional_includes_ignore(self) -> None:
361-
test_configs_dir = Path("./tests/test_configs/internal/")
362-
yaml_path = test_configs_dir / "component_with_additional_includes" / "helloworld_additional_includes.yml"
363-
additional_includes_dir = test_configs_dir / "additional_includes"
364-
component: InternalComponent = load_component(source=yaml_path)
365-
# create some files/folders expected to ignore
366-
code_pycache = yaml_path.parent / "__pycache__"
367-
additional_includes_ignore = additional_includes_dir / "library1" / "x.additional_includes"
368-
additional_includes_pycache = additional_includes_dir / "library1" / "__pycache__"
369-
try:
370-
if not code_pycache.is_dir():
371-
code_pycache.mkdir()
361+
origin_test_configs_dir = Path("./tests/test_configs/internal/")
362+
with tempfile.TemporaryDirectory() as test_configs_dir:
363+
for dir_name in ["component_with_additional_includes", "additional_includes"]:
364+
shutil.copytree(origin_test_configs_dir / dir_name, Path(test_configs_dir) / dir_name)
365+
366+
yaml_path = Path(test_configs_dir) / "component_with_additional_includes" / "helloworld_additional_includes.yml"
367+
additional_includes_dir = Path(test_configs_dir) / "additional_includes"
368+
369+
component: InternalComponent = load_component(source=yaml_path)
370+
# create some files/folders expected to ignore
371+
code_pycache = yaml_path.parent / "__pycache__"
372+
additional_includes_ignore = additional_includes_dir / "library1" / "x.additional_includes"
373+
additional_includes_pycache = additional_includes_dir / "library1" / "__pycache__"
374+
code_pycache.mkdir()
375+
372376
(code_pycache / "a.pyc").touch()
373377
additional_includes_ignore.touch()
374-
if not additional_includes_pycache.is_dir():
375-
additional_includes_pycache.mkdir()
378+
379+
additional_includes_pycache.mkdir()
376380
(additional_includes_pycache / "a.pyc").touch()
377381
# resolve and check snapshot directory
378382
with component._resolve_local_code() as code:
379383
code_path = code.path
380384
assert not (code_path / "__pycache__").exists()
381385
assert not (code_path / "library1" / "x.additional_includes").exists()
382386
assert not (code_path / "library1" / "__pycache__").exists()
383-
finally:
384-
if code_pycache.is_dir():
385-
shutil.rmtree(code_pycache)
386-
if additional_includes_ignore.is_file():
387-
additional_includes_ignore.unlink()
388-
if additional_includes_pycache.is_dir():
389-
shutil.rmtree(additional_includes_pycache)
390387

391388
def test_additional_includes_merge_folder(self) -> None:
392389
yaml_path = (
@@ -668,3 +665,25 @@ def test_anonymous_component_reuse(self, relative_yaml_path: str, expected_snaps
668665
match="InternalCode name are calculated based on its content and cannot be changed.*"
669666
):
670667
code.name = expected_snapshot_id + "1"
668+
669+
def test_snapshot_id_calculation(self):
670+
origin_test_configs_dir = Path("./tests/test_configs/internal/")
671+
with tempfile.TemporaryDirectory() as test_configs_dir:
672+
shutil.copytree(
673+
origin_test_configs_dir / "component-reuse/simple-command",
674+
Path(test_configs_dir) / "simple-command"
675+
)
676+
677+
yaml_path = Path(test_configs_dir) / "simple-command" / "powershell_copy.yaml"
678+
679+
component: InternalComponent = load_component(source=yaml_path)
680+
# create some files/folders expected to ignore
681+
code_pycache = yaml_path.parent / "__pycache__"
682+
code_pycache.mkdir()
683+
(code_pycache / "a.pyc").touch()
684+
685+
# resolve and check snapshot directory
686+
with component._resolve_local_code() as code:
687+
# ANONYMOUS_COMPONENT_TEST_PARAMS[0] is the test params for simple-command
688+
assert code.name == ANONYMOUS_COMPONENT_TEST_PARAMS[0][1]
689+

0 commit comments

Comments
 (0)