Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 7 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,20 @@ jobs:
- name: Install dependencies
run: uv sync

# uv run, not uvx: uvx resolves ruff at run time, so a new release silently
# changes what CI enforces. This uses the version pinned in the lockfile.
- name: Check formatting
run: uvx ruff format --check .
run: uv run ruff format --check .

- name: Lint
run: uvx ruff check .
run: uv run ruff check .

# No test declares a "unit" marker, so `-m unit` deselected every test and the
# exit-5 guard reported that as success — the suite never actually ran.
- name: Run unit tests
run: |
if [ -d "tests" ]; then
uv run pytest tests/ -m unit || [ $? -eq 5 ] # exit 5 means no tests selected; treat as success
uv run pytest tests/
else
echo "No tests directory, skipping"
fi
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "gradient-labs"
version = "0.12.1"
version = "0.12.2"
description = "Python bindings for the Gradient Labs API"
readme = "README.md"
requires-python = ">=3.9,<4.0"
Expand Down
15 changes: 13 additions & 2 deletions src/gradient_labs/_http_client.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
from typing import Any, Callable
from datetime import datetime
from importlib import metadata

from pytz import UTC
import requests

from .errors import ResponseError

API_BASE_URL = "https://api.gradient-labs.ai"
USER_AGENT = "Gradient Labs Python"

try:
_version = metadata.version("gradient-labs")
except metadata.PackageNotFoundError:
# Running from a source tree with no installed distribution metadata.
_version = "unknown"

USER_AGENT = f"Gradient Labs Python/{_version}"


class HttpClient:
Expand Down Expand Up @@ -36,7 +44,10 @@ def delete(self, path: str, body: Any):

@classmethod
def localize(cls, timestamp: datetime) -> str:
return UTC.localize(timestamp).strftime("%Y-%m-%dT%H:%M:%S.%fZ")
# Naive datetimes are taken to already be UTC, as they always have been.
if timestamp.tzinfo is None:
return timestamp.strftime("%Y-%m-%dT%H:%M:%S.%fZ")
return timestamp.astimezone(UTC).strftime("%Y-%m-%dT%H:%M:%S.%fZ")

def _api_call(self, request_func: Callable, path: str, body: Any):
url = f"{self.base_url}/{path}"
Expand Down
Loading
Loading