Skip to content
Merged
Show file tree
Hide file tree
Changes from 23 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
The table of contents is too big for display.
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"
}
1 change: 0 additions & 1 deletion .github/workflows/_integration_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ jobs:
strategy:
matrix:
python-version:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ jobs:
strategy:
matrix:
python-version:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/upload-to-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ jobs:
path: .venv
key: venv-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml') }}-${{ hashFiles('poetry.lock') }}

- name: Generate OpenAPI client
run: |
make generate-client-from-existing-spec

- name: Install dependencies
run: |
poetry config virtualenvs.in-project true
Expand Down
11 changes: 10 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,18 @@ 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

generate-client-from-existing-spec:
python scripts/generate_api_client.py --skip-spec-download

# Documentation

Expand All @@ -49,3 +57,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
313 changes: 163 additions & 150 deletions poetry.lock

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ classifiers = [
]
repository = "https://github.com/togethercomputer/together-python"
homepage = "https://github.com/togethercomputer/together-python"
packages = [
{ include = "together", from = "src" },
]

[tool.poetry.dependencies]
python = "^3.9"
Expand All @@ -40,10 +43,12 @@ filelock = "^3.13.1"
eval-type-backport = ">=0.1.3,<0.3.0"
click = "^8.1.7"
pyarrow = ">=10.0.1"
python-dateutil = "^2.8.2"
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 +80,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
109 changes: 109 additions & 0 deletions scripts/generate_api_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#!/usr/bin/env python3
from __future__ import annotations

import argparse
import shutil
import subprocess
import sys
import tempfile
from pathlib import Path


OPENAPI_SPEC_URL = (
"https://raw.githubusercontent.com/togethercomputer/openapi/main/openapi.yaml"
)
# We no longer set OUTPUT_DIR to the src folder for generation.
# Instead, we'll copy the generated client to the target directory.
TARGET_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 parse_args() -> argparse.Namespace:
"""Parse command line arguments."""
parser = argparse.ArgumentParser(description="Generate Together API client")
parser.add_argument(
"--skip-spec-download",
action="store_true",
help="Skip downloading the OpenAPI spec file",
)
return parser.parse_args()


def main() -> None:
args = parse_args()
spec_file = Path(__file__).parent / "openapi.yaml"

# Download OpenAPI spec if not skipped.
if not args.skip_spec_download:
download_file(OPENAPI_SPEC_URL, spec_file)
# Format the spec for better merge conflict handling.
run_command(["npx", "-y", "prettier", "--write", str(spec_file)])
elif not spec_file.exists():
print(
"Error: OpenAPI spec file not found and download was skipped",
file=sys.stderr,
)
sys.exit(1)

# Download generator if needed.
download_file(GENERATOR_JAR_URL, GENERATOR_JAR)

# Create a temporary directory for generation.
with tempfile.TemporaryDirectory() as tmp_dir:
tmp_path = Path(tmp_dir)
# Build the generation command.
cmd = [
"java",
"-jar",
str(GENERATOR_JAR),
"generate",
"-i",
str(spec_file),
"-g",
"python",
"-o",
str(tmp_path),
"--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 into temporary directory...")
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)

# The generator will create a directory structure like: tmp_dir/together/generated
generated_dir = tmp_path / "together" / "generated"
if not generated_dir.exists():
print("Error: Expected generated directory not found", file=sys.stderr)
sys.exit(1)

# Remove any existing generated client code.
shutil.rmtree(TARGET_DIR, ignore_errors=True)
TARGET_DIR.parent.mkdir(parents=True, exist_ok=True)
# Copy the generated code from the temporary directory to the target directory.
shutil.copytree(generated_dir, TARGET_DIR)
print("Successfully generated and copied client code to", TARGET_DIR)


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