Skip to content

Commit

Permalink
Improve conflict resolution.
Browse files Browse the repository at this point in the history
  • Loading branch information
marius-baseten committed Jun 14, 2024
1 parent bbeedd1 commit 4e97c78
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 28 deletions.
47 changes: 38 additions & 9 deletions docs/chains/doc_gen/generate_reference.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# type: ignore # This tool is only for Marius.
"""Script to auot-generate the API reference for Truss Chains."""

import inspect
import pathlib
import shutil
import subprocess
import tempfile
from pathlib import Path

import truss_chains as chains
Expand Down Expand Up @@ -60,20 +60,49 @@ def _clean_build_directory(build_dir: Path) -> None:
def _apply_patch(
original_file_path: str, patch_file_path: str, output_file_path: str
) -> None:
original_file = Path(original_file_path)
patch_file = Path(patch_file_path)
output_file = Path(output_file_path)

with tempfile.NamedTemporaryFile(delete=False) as temp_file:
temp_output_file_path = Path(temp_file.name)

try:
result = subprocess.run(
["patch", original_file_path, "-o", output_file_path, patch_file_path],
subprocess.run(
[
"patch",
str(original_file),
"-o",
str(temp_output_file_path),
str(patch_file),
],
check=True,
capture_output=True,
text=True,
)
print(result.stdout)

# Copy temp file to final output if no errors
shutil.copy(temp_output_file_path, output_file)

except subprocess.CalledProcessError as e:
print("Patch failed with the following output:")
print(e.stdout)
print(e.stderr)
print("Launching meld for manual resolution...")
subprocess.run(["meld", original_file_path, output_file_path])
reject_file = temp_output_file_path.with_suffix(".rej")
if reject_file.exists():
print(f"Conflicts found, saved to {reject_file}")
subprocess.run(
[
"meld",
str(original_file_path),
str(output_file),
str(temp_output_file_path),
],
check=True,
)
else:
print(f"Patch failed: {e.stderr}")

finally:
if temp_output_file_path.exists():
temp_output_file_path.unlink()


def generate_sphinx_docs(
Expand Down
4 changes: 2 additions & 2 deletions docs/chains/doc_gen/generated-reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ Parsed and validated assets. See `Assets` for more information.
| Name | Type | Description |
|------|------|-------------|
| `secrets` | *dict[str,str]* | |
| `cached` | *list[ModelCache]* | |
| `cached` | *list[ModelRepo]* | |


#### cached *: list[ModelCache]*
#### cached *: list[ModelRepo]*

#### secrets *: dict[str, str]*

Expand Down
29 changes: 14 additions & 15 deletions docs/chains/doc_gen/reference.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--- docs/chains/doc_gen/generated-reference.mdx 2024-06-14 12:24:46.789725965 -0700
+++ docs/snippets/chains/API-reference.mdx 2024-06-14 12:31:38.142839277 -0700
--- docs/chains/doc_gen/generated-reference.mdx 2024-06-14 13:02:08.936718855 -0700
+++ docs/snippets/chains/API-reference.mdx 2024-06-14 13:00:56.529110766 -0700
@@ -6,7 +6,7 @@

Model weight caching can be used like this:
Expand All @@ -21,14 +21,14 @@
| Name | Type | Description |
|------|------|-------------|
-| `secrets` | *dict[str,str]* | |
-| `cached` | *list[ModelCache]* | |
-| `cached` | *list[ModelRepo]* | |
-
-
-#### cached *: list[ModelCache]*
-#### cached *: list[ModelRepo]*
-
-#### secrets *: dict[str, str]*
+| `secrets` | *dict[str,str]* | See [`Assets`](#class-truss-chains-assets) |
+| `cached` | *list[ModelCache]* | See [`Assets`](#class-truss-chains-assets) |
+| `cached` | *list[ModelRepo]* | See [`Assets`](#class-truss-chains-assets) |

## *class* `truss_chains.ChainletBase`

Expand Down Expand Up @@ -396,13 +396,7 @@
-
-
-#### assets *: [Assets](#truss_chains.Assets)*
+| Name | Type | Description |
+|------|--------------------------------------------------|-------------|
+| `docker_image` | *[DockerImage](#class-truss-chains-dockerimage)* | |
+| `compute` | *[Compute](#class-truss-chains-compute)* | |
+| `assets` | *[Assets](#class-truss-chains-assets)* | |
+| `name` | *str\|None* | |

-
-#### compute *: [Compute](#truss_chains.Compute)*
-
-#### docker_image *: [DockerImage](#truss_chains.DockerImage)*
Expand All @@ -416,7 +410,13 @@
-
-* **Return type:**
- [*ComputeSpec*](#truss_chains.definitions.ComputeSpec)
-
+| Name | Type | Description |
+|------|--------------------------------------------------|-------------|
+| `docker_image` | *[DockerImage](#class-truss-chains-dockerimage)* | |
+| `compute` | *[Compute](#class-truss-chains-compute)* | |
+| `assets` | *[Assets](#class-truss-chains-assets)* | |
+| `name` | *str\|None* | |

-#### name *: str | None*

## *class* `truss_chains.RemoteErrorDetail`
Expand Down Expand Up @@ -545,7 +545,7 @@


#### *classmethod* from_url(predict_url, context, options=None)
@@ -658,9 +594,8 @@
@@ -658,8 +594,8 @@

**Parameters:**

Expand All @@ -554,7 +554,6 @@
-| `predict_url` | *str* | URL to predict endpoint of another chain / truss model. |
-| `context` | *[DeploymentContext](#truss_chains.DeploymentContext* | Deployment context object, obtained in the chainlet’s `__init__`. |
-| `options` | *[RPCOptions](#truss_chains.RPCOptions* | RPC options, e.g. retries. |
-
+| Name | Type | Description |
+|------|------------------------------------------------------------------------------|-------------|
+| `predict_url` | *str* | URL to predict endpoint of another chain / truss model. |
Expand Down
2 changes: 1 addition & 1 deletion docs/snippets/chains/API-reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Parsed and validated assets. See [`Assets`](#class-truss-chains-assets) for more
| Name | Type | Description |
|------|------|-------------|
| `secrets` | *dict[str,str]* | See [`Assets`](#class-truss-chains-assets) |
| `cached` | *list[ModelCache]* | See [`Assets`](#class-truss-chains-assets) |
| `cached` | *list[ModelRepo]* | See [`Assets`](#class-truss-chains-assets) |

## *class* `truss_chains.ChainletBase`

Expand Down
2 changes: 1 addition & 1 deletion truss-chains/truss_chains/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ class AssetSpec(SafeModel):

# TODO: this is not stable yet and might change or refer back to truss.
secrets: dict[str, str] = pydantic.Field({})
cached: list[truss_config.ModelCache] = []
cached: list[truss_config.ModelRepo] = []


class Assets:
Expand Down

0 comments on commit 4e97c78

Please sign in to comment.