Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
059672e
chore: add devcontainer config
CompuIves Jan 28, 2025
b3caa48
add openapi generation
CompuIves Jan 28, 2025
cab32b9
feat: add dedicated endpoint cli
CompuIves Feb 12, 2025
c983f2e
run lints
CompuIves Feb 12, 2025
c24a510
update makefile
CompuIves Feb 12, 2025
f3b7fe8
rerun formatter
CompuIves Feb 12, 2025
d221092
use poetry 1.8.3
CompuIves Feb 12, 2025
a3c0637
fix tests
CompuIves Feb 13, 2025
d8faecc
make install
CompuIves Feb 13, 2025
94e0c8e
skip openapi spec download in ci
CompuIves Feb 13, 2025
6a8e0e8
add debug step
CompuIves Feb 13, 2025
32f0580
add generated to output
CompuIves Feb 13, 2025
fd0e2cf
remove debug
CompuIves Feb 13, 2025
4828da9
fix poetry inclusion of generated files
CompuIves Feb 13, 2025
dba33c8
fix order of generation
CompuIves Feb 13, 2025
5d40a93
remove 3.8
CompuIves Feb 13, 2025
a904a89
fix normal test
CompuIves Feb 13, 2025
3d59638
try include directive
CompuIves Feb 13, 2025
ea7054f
new try
CompuIves Feb 13, 2025
e9f08af
move
CompuIves Feb 13, 2025
d8766cd
try even more
CompuIves Feb 13, 2025
555f2c4
try manifest
CompuIves Feb 13, 2025
bcaed82
i give up, include openapi generated files
CompuIves Feb 13, 2025
33b6c81
fix mypy error
CompuIves Feb 13, 2025
a10e18a
add hardware call and --wait option
CompuIves Feb 13, 2025
e68aa19
remove openapi client 😭😭😭😭😭
CompuIves Feb 13, 2025
1b1390e
manually update type for now
CompuIves Feb 13, 2025
724dee9
revert poetry
CompuIves Feb 13, 2025
c752304
remove some unnecessary changes
CompuIves Feb 13, 2025
fb69922
bump together-python package version
orangetin Feb 13, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM mcr.microsoft.com/devcontainers/python:3.9

ENV PYTHONUNBUFFERED 1

RUN pipx install poetry==1.8.3

# Install pre-commit
RUN pip install pre-commit
40 changes: 40 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "Together Python Development",
"build": {
"dockerfile": "Dockerfile"
},
"features": {
"ghcr.io/devcontainers/features/git:1": {},
"ghcr.io/devcontainers/features/node:1": {},
"ghcr.io/devcontainers/features/java:1": {
"version": "17",
"installMaven": false,
"installGradle": false
}
},
"customizations": {
"vscode": {
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance",
"ms-python.isort",
"charliermarsh.ruff",
"ms-python.mypy-type-checker",
"eamodio.gitlens"
],
"settings": {
"[python]": {
"editor.defaultFormatter": "charliermarsh.ruff"
},
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll": "explicit",
"source.organizeImports": "explicit"
},
"ruff.lineLength": 100
}
}
},
"postCreateCommand": "poetry install",
"remoteUser": "vscode"
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ share/python-wheels/
*.egg
MANIFEST

# OpenAPI Generator Ignore
src/together/generated/

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
Expand Down
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: all format lint test tests test_watch integration_tests docker_tests help extended_tests
.PHONY: all format lint test tests test_watch integration_tests docker_tests help extended_tests generate-client

# Default target executed when no arguments are given to make.
all: help
Expand Down Expand Up @@ -27,10 +27,15 @@ integration_tests:
install:
poetry install --with quality,tests
poetry run pre-commit install
$(MAKE) generate-client

format:
poetry run pre-commit run --all-files

# OpenAPI Client Generation

generate-client:
python scripts/generate_api_client.py

# Documentation

Expand All @@ -49,3 +54,4 @@ help:
@echo 'test_watch - run unit tests in watch mode'
@echo 'extended_tests - run extended tests'
@echo 'integration_tests - run integration tests'
@echo 'generate-client - generate the OpenAPI client'
7 changes: 7 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
[mypy]
plugins = pydantic.mypy
disallow_untyped_defs = true

[mypy-together.generated.*]
ignore_errors = true

[mypy.tests.*]
ignore_errors = true
16 changes: 15 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ numpy = [
{ version = ">=1.23.5", python = "<3.12" },
{ version = ">=1.26.0", python = ">=3.12" },
]
aiohttp-retry = "^2.9.1"
pillow = "^11.1.0"

[tool.poetry.group.quality]
Expand Down Expand Up @@ -75,6 +76,7 @@ datasets = ">=2.18,<4.0"
transformers = "^4.39.3"



[tool.poetry.urls]
"Homepage" = "https://github.com/togethercomputer/together-python"
"Bug Tracker" = "https://github.com/togethercomputer/together-python/issues"
Expand Down
1 change: 1 addition & 0 deletions scripts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
openapi-generator-cli.jar
90 changes: 90 additions & 0 deletions scripts/generate_api_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/usr/bin/env python3
from __future__ import annotations

import shutil
import subprocess
import sys
from pathlib import Path


OPENAPI_SPEC_URL = (
"https://raw.githubusercontent.com/togethercomputer/openapi/main/openapi.yaml"
)
OUTPUT_DIR = Path(__file__).parent.parent / "src" / "together" / "generated"
GENERATOR_JAR_URL = "https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/7.11.0/openapi-generator-cli-7.11.0.jar"
GENERATOR_JAR = Path(__file__).parent / "openapi-generator-cli.jar"


def run_command(cmd: list[str], check: bool = True) -> subprocess.CompletedProcess[str]:
"""Run a command and optionally check its return code."""
print(f"Running: {' '.join(cmd)}")
return subprocess.run(cmd, check=check, capture_output=True, text=True)


def download_file(url: str, target: Path) -> None:
"""Download a file"""

print(f"Downloading {url} to {target}")
run_command(["wget", "-O", str(target), url])


def main() -> None:
# Download OpenAPI spec
spec_file = Path(__file__).parent / "openapi.yaml"
download_file(OPENAPI_SPEC_URL, spec_file)

# Run formatter on the spec for better merge conflict handling
run_command(["npx", "-y", "prettier", "--write", str(spec_file)])

# Download generator if needed
download_file(GENERATOR_JAR_URL, GENERATOR_JAR)

# Delete existing generated code
shutil.rmtree(OUTPUT_DIR, ignore_errors=True)

# Ensure output directory exists
OUTPUT_DIR.mkdir(parents=True, exist_ok=True)

# Generate client code
cmd = [
"java",
"-jar",
str(GENERATOR_JAR),
"generate",
"-i",
str(spec_file),
"-g",
"python",
"-o",
str(OUTPUT_DIR),
"--package-name=together.generated",
"--git-repo-id=together-python",
"--git-user-id=togethercomputer",
"--additional-properties=packageUrl=https://github.com/togethercomputer/together-python",
"--additional-properties=library=asyncio",
"--additional-properties=generateSourceCodeOnly=true",
]

print("Generating client code...")
result = run_command(cmd, check=False)

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

# Move files from nested directory to target directory
nested_dir = OUTPUT_DIR / "together" / "generated"
if nested_dir.exists():
print("Moving files from nested directory...")
# Move all contents to parent directory
for item in nested_dir.iterdir():
shutil.move(str(item), str(OUTPUT_DIR / item.name))
# Clean up empty directories
shutil.rmtree(OUTPUT_DIR / "together", ignore_errors=True)

print("Successfully generated client code")


if __name__ == "__main__":
main()
Loading
Loading