Skip to content
Open
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
4 changes: 4 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ on:
workflow_call:
workflow_dispatch:

permissions:
contents: read

jobs:
build:
name: Build distributions
runs-on: ubuntu-latest
steps:
- name: Checkout repository
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:

test:
name: Test
needs: build
uses: ./.github/workflows/test.yaml
secrets: inherit

Expand Down
27 changes: 19 additions & 8 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,38 @@ on:
workflow_call:
workflow_dispatch:

permissions:
contents: read

concurrency: lint-${{ github.sha }}

jobs:
lint:
name: Lint and type check with Python ${{ matrix.python-version }}
runs-on: ubuntu-latest
env:
PYTHON_VERSION: "3.10"
strategy:
fail-fast: false
matrix:
python-version:
- "3.10"
- "3.11"
- "3.12"
- "3.13"
- "3.14"
steps:
- name: Checkout repository
uses: actions/checkout@v7

- name: Set up Python ${{ env.PYTHON_VERSION }}
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
with:
python-version: ${{ env.PYTHON_VERSION }}
python-version: ${{ matrix.python-version }}

- name: Install uv
uses: astral-sh/setup-uv@v7

- name: Install the project
run: uv sync --all-extras --dev
- name: Install project dependencies
run: uv sync --all-groups --python ${{ matrix.python-version }}

- name: Run pre-commit hooks
uses: pre-commit/action@v3.0.1
- name: Run hooks
uses: j178/prek-action@v1
33 changes: 27 additions & 6 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,51 @@ on:
workflow_call:
workflow_dispatch:

permissions:
contents: read

concurrency: test-${{ github.sha }}

jobs:
test:
name: Test with Python ${{ matrix.python-version }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version:
- "3.10"
- "3.11"
- "3.12"
- "3.13"
- "3.14"
env:
PYTHON_VERSION: "3.10"
CONTIGUITY_PROJECT_ID: ${{ secrets.CONTIGUITY_PROJECT_ID }}
CONTIGUITY_TOKEN: ${{ secrets.CONTIGUITY_TOKEN }}
CONTIGUITY_DATA_KEY: ${{ secrets.CONTIGUITY_DATA_KEY }}
steps:
- name: Checkout repository
uses: actions/checkout@v7

- name: Set up Python ${{ env.PYTHON_VERSION }}
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
with:
python-version: ${{ env.PYTHON_VERSION }}
python-version: ${{ matrix.python-version }}

- name: Install uv
uses: astral-sh/setup-uv@v7

- name: Install the project
run: uv sync --all-extras --dev
- name: Install project dependencies
run: uv sync --no-install-project --all-groups --python ${{ matrix.python-version }}

- name: Download sdist artifact
uses: actions/download-artifact@v6
with:
name: sdist
path: ./dist

- name: Install package
run: uv pip install dist/*.tar.gz

- name: Run tests
- name: Run pytest
run: uv run pytest tests
13 changes: 6 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
- repo: builtin
hooks:
- id: check-added-large-files
- id: check-case-conflict
Expand All @@ -11,12 +10,12 @@ repos:
args: [--markdown-linebreak-ext=md]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.14.9
rev: v0.15.22
hooks:
- id: ruff
- id: ruff-check
- id: ruff-format

- repo: https://github.com/RobertCraigie/pyright-python
rev: v1.1.407
- repo: https://github.com/astral-sh/ty-pre-commit
rev: v0.0.60
hooks:
- id: pyright
- id: ty
16 changes: 5 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ keywords = [
classifiers = [
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Topic :: Utilities",
Expand All @@ -34,18 +33,18 @@ dependencies = [

[dependency-groups]
dev = [
"pre-commit>=4.5,<4.7",
"pytest>=9.0.2,<9.2.0",
"pytest-asyncio>=1.3,<1.5",
"pytest-cov>=7.0,<7.2",
"prek~=0.4.10",
"pytest~=9.0.2",
"pytest-asyncio~=1.3.0",
"pytest-cov~=7.0.0",
"python-dotenv~=1.2.1",
]

[project.urls]
Repository = "https://github.com/contiguity/python"

[build-system]
requires = ["uv_build>=0.9.22"]
requires = ["uv_build>=0.11.29,<0.12.0"]
build-backend = "uv_build"

[tool.ruff]
Expand All @@ -59,10 +58,5 @@ ignore = ["A", "D", "T201"]
[tool.ruff.lint.per-file-ignores]
"**/tests/*" = ["S101", "S311"]

[tool.pyright]
venvPath = "."
venv = ".venv"
reportUnnecessaryTypeIgnoreComment = true

[tool.pytest.ini_options]
asyncio_mode = "auto"
2 changes: 1 addition & 1 deletion src/contiguity/_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ErrorResponse(BaseResponse):


def decode_response(content: bytes, /, *, type: type[T]) -> T:
raw = msgspec.json.decode(content, type=RawResponse[type])
raw = msgspec.json.decode(content, type=RawResponse[type]) # ty: ignore[invalid-type-form]
metadata = ResponseMetadata(
id=raw.id,
timestamp=raw.timestamp,
Expand Down
39 changes: 32 additions & 7 deletions src/contiguity/base/async_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from collections.abc import Mapping, Sequence
from datetime import datetime, timedelta, timezone
from http import HTTPStatus
from typing import Any, Generic, Literal, overload
from typing import Any, Generic, Literal, cast, overload
from warnings import warn

import msgspec
Expand Down Expand Up @@ -34,13 +34,38 @@ class AsyncBase(Generic[ItemT]):
EXPIRES_ATTRIBUTE = "__expires"
PUT_LIMIT = 30

@overload
def __init__(
self: "AsyncBase[dict[str, Any]]",
name: str,
/,
*,
data_key: str | None = None,
project_id: str | None = None,
host: str | None = None,
api_version: str = "v1",
) -> None: ...

@overload
@deprecated("The `project_key` parameter has been renamed to `data_key`.")
def __init__(
self: "AsyncBase[dict[str, Any]]",
name: str,
/,
*,
project_key: str | None = None,
project_id: str | None = None,
host: str | None = None,
api_version: str = "v1",
) -> None: ...

@overload
def __init__(
self,
name: str,
/,
*,
item_type: type[ItemT] = Mapping[str, Any],
item_type: type[ItemT],
data_key: str | None = None,
project_id: str | None = None,
host: str | None = None,
Expand All @@ -54,7 +79,7 @@ def __init__(
name: str,
/,
*,
item_type: type[ItemT] = Mapping[str, Any],
item_type: type[ItemT],
project_key: str | None = None,
project_id: str | None = None,
host: str | None = None,
Expand All @@ -66,7 +91,7 @@ def __init__( # noqa: PLR0913
name: str,
/,
*,
item_type: type[ItemT] = Mapping[str, Any],
item_type: type[ItemT] | None = None,
data_key: str | None = None,
project_key: str | None = None, # Deprecated.
project_id: str | None = None,
Expand All @@ -78,7 +103,7 @@ def __init__( # noqa: PLR0913
raise ValueError(msg)

self.name = name
self.item_type = item_type
self.item_type = cast("type[ItemT]", item_type if item_type is not None else dict[str, Any])
self.data_key = data_key or project_key or get_data_key()
self.project_id = project_id or get_project_id()
self.host = host or os.getenv("CONTIGUITY_BASE_HOST") or "api.base.contiguity.co"
Expand Down Expand Up @@ -118,7 +143,7 @@ def _response_as_item_type(
response.raise_for_status()
except HTTPStatusError as exc:
raise ContiguityApiError(exc.response.text) from exc
return msgspec.json.decode(response.content, type=Sequence[self.item_type] if sequence else self.item_type)
return msgspec.json.decode(response.content, type=Sequence[self.item_type] if sequence else self.item_type) # ty: ignore[invalid-type-form]

def _insert_expires_attr(
self,
Expand Down Expand Up @@ -288,7 +313,7 @@ async def query(
response.raise_for_status()
except HTTPStatusError as exc:
raise ContiguityApiError(exc.response.text) from exc
return msgspec.json.decode(response.content, type=QueryResponse[self.item_type])
return msgspec.json.decode(response.content, type=QueryResponse[self.item_type]) # ty: ignore[invalid-type-form]

@deprecated("This method has been renamed to `query` and will be removed in a future release.")
async def fetch(
Expand Down
39 changes: 32 additions & 7 deletions src/contiguity/base/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from collections.abc import Mapping, Sequence
from datetime import datetime, timedelta, timezone
from http import HTTPStatus
from typing import Any, Generic, Literal, overload
from typing import Any, Generic, Literal, cast, overload
from warnings import warn

import msgspec
Expand Down Expand Up @@ -43,13 +43,38 @@ class Base(Generic[ItemT]):
EXPIRES_ATTRIBUTE = "__expires"
PUT_LIMIT = 30

@overload
def __init__(
self: "Base[dict[str, Any]]",
name: str,
/,
*,
data_key: str | None = None,
project_id: str | None = None,
host: str | None = None,
api_version: str = "v1",
) -> None: ...

@overload
@deprecated("The `project_key` parameter has been renamed to `data_key`.")
def __init__(
self: "Base[dict[str, Any]]",
name: str,
/,
*,
project_key: str | None = None,
project_id: str | None = None,
host: str | None = None,
api_version: str = "v1",
) -> None: ...

@overload
def __init__(
self,
name: str,
/,
*,
item_type: type[ItemT] = Mapping[str, Any],
item_type: type[ItemT],
data_key: str | None = None,
project_id: str | None = None,
host: str | None = None,
Expand All @@ -63,7 +88,7 @@ def __init__(
name: str,
/,
*,
item_type: type[ItemT] = Mapping[str, Any],
item_type: type[ItemT],
project_key: str | None = None,
project_id: str | None = None,
host: str | None = None,
Expand All @@ -75,7 +100,7 @@ def __init__( # noqa: PLR0913
name: str,
/,
*,
item_type: type[ItemT] = Mapping[str, Any],
item_type: type[ItemT] | None = None,
data_key: str | None = None,
project_key: str | None = None, # Deprecated.
project_id: str | None = None,
Expand All @@ -87,7 +112,7 @@ def __init__( # noqa: PLR0913
raise ValueError(msg)

self.name = name
self.item_type = item_type
self.item_type = cast("type[ItemT]", item_type if item_type is not None else dict[str, Any])
self.data_key = data_key or project_key or get_data_key()
self.project_id = project_id or get_project_id()
self.host = host or os.getenv("CONTIGUITY_BASE_HOST") or "api.base.contiguity.co"
Expand Down Expand Up @@ -127,7 +152,7 @@ def _response_as_item_type(
response.raise_for_status()
except HTTPStatusError as exc:
raise ContiguityApiError(exc.response.text) from exc
return msgspec.json.decode(response.content, type=Sequence[self.item_type] if sequence else self.item_type)
return msgspec.json.decode(response.content, type=Sequence[self.item_type] if sequence else self.item_type) # ty: ignore[invalid-type-form]

def _insert_expires_attr(
self,
Expand Down Expand Up @@ -297,7 +322,7 @@ def query(
response.raise_for_status()
except HTTPStatusError as exc:
raise ContiguityApiError(exc.response.text) from exc
return msgspec.json.decode(response.content, type=QueryResponse[self.item_type])
return msgspec.json.decode(response.content, type=QueryResponse[self.item_type]) # ty: ignore[invalid-type-form]

@deprecated("This method has been renamed to `query` and will be removed in a future release.")
def fetch(
Expand Down
Loading
Loading