-
Notifications
You must be signed in to change notification settings - Fork 7k
[ci][deps] raydepsts: Improved error messages #58058
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -177,7 +177,9 @@ def _build(self): | |||||||||||||
| for depset_name in depset.depsets: | ||||||||||||||
| self.build_graph.add_edge(depset_name, depset.name) | ||||||||||||||
| else: | ||||||||||||||
| raise ValueError(f"Invalid operation: {depset.operation}") | ||||||||||||||
| raise ValueError( | ||||||||||||||
| f"Invalid operation: {depset.operation} for depset {depset.name} in config {depset.config_name}" | ||||||||||||||
| ) | ||||||||||||||
| if depset.pre_hooks: | ||||||||||||||
| for ind, hook in enumerate(depset.pre_hooks): | ||||||||||||||
| hook_name = f"{depset.name}_pre_hook_{ind+1}" | ||||||||||||||
|
|
@@ -232,24 +234,27 @@ def exec_uv_cmd( | |||||||||||||
| self, cmd: str, args: List[str], stdin: Optional[bytes] = None | ||||||||||||||
| ) -> str: | ||||||||||||||
| cmd = [self._uv_binary, "pip", cmd, *args] | ||||||||||||||
| click.echo(f"Executing command: {cmd}") | ||||||||||||||
| status = subprocess.run(cmd, cwd=self.workspace.dir, input=stdin) | ||||||||||||||
| click.echo(f"Executing command: {' '.join(cmd)}") | ||||||||||||||
| status = subprocess.run( | ||||||||||||||
| cmd, cwd=self.workspace.dir, input=stdin, capture_output=True | ||||||||||||||
| ) | ||||||||||||||
| if status.returncode != 0: | ||||||||||||||
| raise RuntimeError(f"Failed to execute command: {cmd}") | ||||||||||||||
| return status.stdout | ||||||||||||||
| raise RuntimeError( | ||||||||||||||
| f"Failed to execute command: {' '.join(cmd)} with error: {status.stderr.decode('utf-8')}" | ||||||||||||||
| ) | ||||||||||||||
|
Comment on lines
+242
to
+244
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly here, using
Suggested change
|
||||||||||||||
| return status.stdout.decode("utf-8") | ||||||||||||||
|
|
||||||||||||||
| def execute_pre_hook(self, pre_hook: str): | ||||||||||||||
| status = subprocess.run( | ||||||||||||||
| shlex.split(pre_hook), | ||||||||||||||
| cwd=self.workspace.dir, | ||||||||||||||
| capture_output=True, | ||||||||||||||
| text=True, | ||||||||||||||
| ) | ||||||||||||||
| if status.returncode != 0: | ||||||||||||||
| raise RuntimeError( | ||||||||||||||
| f"Failed to execute pre_hook {pre_hook} with error: {status.stderr}", | ||||||||||||||
| f"Failed to execute pre_hook {pre_hook} with error: {status.stderr.decode('utf-8')}", | ||||||||||||||
| ) | ||||||||||||||
| click.echo(f"{status.stdout}") | ||||||||||||||
| click.echo(f"{status.stdout.decode('utf-8')}") | ||||||||||||||
| click.echo(f"Executed pre_hook {pre_hook} successfully") | ||||||||||||||
|
|
||||||||||||||
| def execute_depset(self, depset: Depset): | ||||||||||||||
|
|
@@ -379,7 +384,7 @@ def check_subset_exists(self, source_depset: Depset, requirements: List[str]): | |||||||||||||
| for req in requirements: | ||||||||||||||
| if req not in source_depset.requirements: | ||||||||||||||
| raise RuntimeError( | ||||||||||||||
| f"Requirement {req} is not a subset of {source_depset.name}" | ||||||||||||||
| f"Requirement {req} is not a subset of {source_depset.name} in config {source_depset.config_name}" | ||||||||||||||
| ) | ||||||||||||||
|
|
||||||||||||||
| def get_expanded_depset_requirements( | ||||||||||||||
|
|
||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,21 @@ | ||
| import sys | ||
| import tempfile | ||
| import unittest | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
| from ci.raydepsets.tests.utils import copy_data_to_tmpdir, get_depset_by_name | ||
| from ci.raydepsets.workspace import BuildArgSet, Workspace, _substitute_build_args | ||
| from ci.raydepsets.tests.utils import ( | ||
| copy_data_to_tmpdir, | ||
| get_depset_by_name, | ||
| write_to_config_file, | ||
| ) | ||
| from ci.raydepsets.workspace import ( | ||
| BuildArgSet, | ||
| Depset, | ||
| Workspace, | ||
| _substitute_build_args, | ||
| ) | ||
|
|
||
|
|
||
| def test_workspace_init(): | ||
|
|
@@ -134,5 +144,31 @@ def test_get_configs_dir(): | |
| assert f"{tmpdir}/test2.depsets.yaml" in configs_dir | ||
|
|
||
|
|
||
| def test_invalid_build_arg_set_in_config(): | ||
| with tempfile.TemporaryDirectory() as tmpdir: | ||
| copy_data_to_tmpdir(tmpdir) | ||
| depset = Depset( | ||
| name="invalid_build_arg_set", | ||
| operation="compile", | ||
| requirements=["requirements_test.txt"], | ||
| output="requirements_compiled_invalid_build_arg_set.txt", | ||
| config_name="test.depsets.yaml", | ||
| ) | ||
| write_to_config_file( | ||
| tmpdir, | ||
| depset, | ||
| "test.depsets.yaml", | ||
| build_arg_sets=["invalid_build_arg_set"], | ||
| ) | ||
| workspace = Workspace(dir=tmpdir) | ||
| with unittest.TestCase().assertRaises(KeyError) as e: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| workspace.load_config(config_path=Path(tmpdir) / "test.depsets.yaml") | ||
| print(str(e.exception)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| assert ( | ||
| "Build arg set invalid_build_arg_set not found in config test.depsets.yaml" | ||
| in str(e.exception) | ||
| ) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| sys.exit(pytest.main(["-v", __file__])) | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,10 +1,13 @@ | ||||||
| """Shared test utilities for raydepsets tests.""" | ||||||
|
|
||||||
| import shutil | ||||||
| from typing import Optional | ||||||
| from pathlib import Path | ||||||
| from typing import List, Optional | ||||||
|
|
||||||
| import runfiles | ||||||
|
|
||||||
| from ci.raydepsets.workspace import Depset | ||||||
|
|
||||||
| _REPO_NAME = "io_ray" | ||||||
| _runfiles = runfiles.Create() | ||||||
|
|
||||||
|
|
@@ -51,3 +54,27 @@ def get_depset_by_name(depsets, name): | |||||
| for depset in depsets: | ||||||
| if depset.name == name: | ||||||
| return depset | ||||||
|
|
||||||
|
|
||||||
| def write_to_config_file( | ||||||
| tmpdir: str, depset: Depset, config_name: str, build_arg_sets: List[str] = None | ||||||
| ): | ||||||
| with open(Path(tmpdir) / config_name, "w") as f: | ||||||
| f.write( | ||||||
| f""" | ||||||
| depsets: | ||||||
| - name: {depset.name} | ||||||
| operation: {depset.operation} | ||||||
| {f"constraints: {depset.constraints}" if depset.constraints else ""} | ||||||
| {f"requirements: {depset.requirements}" if depset.requirements else ""} | ||||||
| output: {depset.output} | ||||||
| {f"pre_hooks: {depset.pre_hooks}" if depset.pre_hooks else ""} | ||||||
| {f"depsets: {depset.depsets}" if depset.depsets else ""} | ||||||
| {f"source_depset: {depset.source_depset}" if depset.source_depset else ""} | ||||||
| {f"config_name: {depset.config_name}" if depset.config_name else ""} | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Suggested change
|
||||||
| {f"append_flags: {depset.append_flags}" if depset.append_flags else ""} | ||||||
| {f"override_flags: {depset.override_flags}" if depset.override_flags else ""} | ||||||
| {f"packages: {depset.packages}" if depset.packages else ""} | ||||||
| {f"build_arg_sets: {build_arg_sets}" if build_arg_sets else ""} | ||||||
| """ | ||||||
| ) | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For logging the command, using
shlex.join(cmd)is generally safer than' '.join(cmd)as it correctly handles arguments that contain spaces or other special characters. This makes the logged command string easier to copy and paste into a shell for debugging.