Skip to content

Commit cab32b9

Browse files
committed
feat: add dedicated endpoint cli
1 parent b3caa48 commit cab32b9

File tree

15 files changed

+758
-81
lines changed

15 files changed

+758
-81
lines changed

.devcontainer/devcontainer.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
},
66
"features": {
77
"ghcr.io/devcontainers/features/git:1": {},
8+
"ghcr.io/devcontainers/features/java:1": {
9+
"version": "17",
10+
"installMaven": false,
11+
"installGradle": false
12+
},
813
"ghcr.io/devcontainers-contrib/features/poetry:2": {}
914
},
1015
"customizations": {

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ share/python-wheels/
2727
*.egg
2828
MANIFEST
2929

30+
# OpenAPI Generator Ignore
31+
src/together/generated/
32+
3033
# PyInstaller
3134
# Usually these files are written by a python script from a template
3235
# before PyInstaller builds the exe, so as to inject date/other infos into it.

poetry.lock

Lines changed: 32 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,15 @@ aiohttp = "^3.9.3"
3939
filelock = "^3.13.1"
4040
eval-type-backport = ">=0.1.3,<0.3.0"
4141
click = "^8.1.7"
42+
python-dateutil = "^2.8.2"
4243
pillow = "^10.3.0"
4344
pyarrow = ">=10.0.1"
45+
makefun = "^1.15.2"
4446
numpy = [
4547
{ version = ">=1.23.5", python = "<3.12" },
4648
{ version = ">=1.26.0", python = ">=3.12" },
4749
]
50+
aiohttp-retry = "^2.9.1"
4851

4952
[tool.poetry.group.quality]
5053
optional = true
@@ -81,7 +84,6 @@ optional = true
8184
[tool.poetry.group.dev.dependencies]
8285
mypy = "^1.14.1"
8386
types-requests = "^2.31.0"
84-
openapi-python-client = "^0.19.0"
8587

8688
[tool.poetry.urls]
8789
"Homepage" = "https://github.com/togethercomputer/together-python"

scripts/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
openapi-generator-cli.jar
2+
openapi.yaml

scripts/generate_api_client.py

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,29 @@
11
#!/usr/bin/env python3
22
from __future__ import annotations
33

4+
import shutil
45
import subprocess
56
import sys
67
from pathlib import Path
78

8-
import requests
99

10-
11-
OPENAPI_SPEC_URL = (
12-
"https://raw.githubusercontent.com/togethercomputer/openapi/refs/heads/main/openapi.yaml"
13-
)
10+
OPENAPI_SPEC_URL = "https://raw.githubusercontent.com/togethercomputer/openapi/main/openapi.yaml"
1411
OUTPUT_DIR = Path(__file__).parent.parent / "src" / "together" / "generated"
15-
GENERATOR_JAR_URL = "https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/7.3.0/openapi-generator-cli-7.3.0.jar"
12+
GENERATOR_JAR_URL = "https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/7.11.0/openapi-generator-cli-7.11.0.jar"
1613
GENERATOR_JAR = Path(__file__).parent / "openapi-generator-cli.jar"
1714

1815

16+
def run_command(cmd: list[str], check: bool = True) -> subprocess.CompletedProcess:
17+
"""Run a command and optionally check its return code."""
18+
print(f"Running: {' '.join(cmd)}")
19+
return subprocess.run(cmd, check=check, capture_output=True, text=True)
20+
21+
1922
def download_file(url: str, target: Path) -> None:
20-
"""Download a file if it doesn't exist."""
21-
if target.exists():
22-
return
23+
"""Download a file"""
2324

2425
print(f"Downloading {url} to {target}")
25-
response = requests.get(url, stream=True)
26-
response.raise_for_status()
27-
28-
target.parent.mkdir(parents=True, exist_ok=True)
29-
with open(target, "wb") as f:
30-
for chunk in response.iter_content(chunk_size=8192):
31-
f.write(chunk)
26+
run_command(["wget", "-O", str(target), url])
3227

3328

3429
def main() -> None:
@@ -39,6 +34,9 @@ def main() -> None:
3934
# Download generator if needed
4035
download_file(GENERATOR_JAR_URL, GENERATOR_JAR)
4136

37+
# Delete existing generated code
38+
shutil.rmtree(OUTPUT_DIR, ignore_errors=True)
39+
4240
# Ensure output directory exists
4341
OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
4442

@@ -54,19 +52,32 @@ def main() -> None:
5452
"python",
5553
"-o",
5654
str(OUTPUT_DIR),
57-
"--additional-properties=packageName=together.generated",
55+
"--package-name=together.generated",
5856
"--git-repo-id=together-python",
5957
"--git-user-id=togethercomputer",
58+
"--additional-properties=packageUrl=https://github.com/togethercomputer/together-python",
59+
"--additional-properties=library=asyncio",
60+
"--additional-properties=generateSourceCodeOnly=true",
6061
]
6162

6263
print("Generating client code...")
63-
result = subprocess.run(cmd, capture_output=True, text=True)
64+
result = run_command(cmd, check=False)
6465

6566
if result.returncode != 0:
6667
print("Error generating client code:", file=sys.stderr)
6768
print(result.stderr, file=sys.stderr)
6869
sys.exit(1)
6970

71+
# Move files from nested directory to target directory
72+
nested_dir = OUTPUT_DIR / "together" / "generated"
73+
if nested_dir.exists():
74+
print("Moving files from nested directory...")
75+
# Move all contents to parent directory
76+
for item in nested_dir.iterdir():
77+
shutil.move(str(item), str(OUTPUT_DIR / item.name))
78+
# Clean up empty directories
79+
shutil.rmtree(OUTPUT_DIR / "together", ignore_errors=True)
80+
7081
print("Successfully generated client code")
7182

7283

0 commit comments

Comments
 (0)