Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update project template cruft, dependencies #117

Merged
merged 3 commits into from
Jan 15, 2025
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
2 changes: 1 addition & 1 deletion .cruft.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"template": "https://github.com/smkent/cookie-python",
"commit": "dee411e1e91b735d5df2ca480c611b21a4d371be",
"commit": "7025e55adab820dd8e63d8be0e0ec0cabad0d830",
"context": {
"cookiecutter": {
"project_name": "jmapc",
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/actions/python-poetry/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ runs:
# https://github.com/actions/runner-images/issues/6185
PYTHON_KEYRING_BACKEND: "keyring.backends.null.Keyring"
run: |
poetry install
poetry lock --check
poetry check --lock
poetry sync
PROJECT_VERSION=$(poetry version -s)
[ "${PROJECT_VERSION}" != "0.0.0" ] \
|| { echo "Versioning broken"; exit 1; }
Expand Down
17 changes: 9 additions & 8 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,26 @@ name: Release

env:
ENABLE_PYPI_PUBLISH: true
ENABLE_TEST_PYPI_PUBLISH: true
ENABLE_TEST_PYPI_PUBLISH: false
RELEASE_PYTHON_VERSION: "3.12"
RELEASE_POETRY_VERSION: "1.8"
RELEASE_POETRY_VERSION: "2.0"

on:
push:
tags:
- '*'
workflow_dispatch:

jobs:
Publish:
name: Publish package for ${{ github.ref_name }}

if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/jmapc
permissions:
id-token: write

steps:
- name: 💾 Check out repository
Expand Down Expand Up @@ -49,15 +53,12 @@ jobs:
uses: pypa/gh-action-pypi-publish@release/v1
if: ${{ env.ENABLE_TEST_PYPI_PUBLISH == 'true' }}
with:
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository_url: https://test.pypi.org/legacy/
skip_existing: true
repository-url: https://test.pypi.org/legacy/
skip-existing: true

- name: ☢️ Publish to PyPI
if: ${{ env.ENABLE_PYPI_PUBLISH == 'true' }}
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ jobs:
os:
- Ubuntu
python-version:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
- "3.13"
poetry-version:
- "1.8"
- "2.0"

runs-on: ${{ matrix.os }}-latest
steps:
Expand Down
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: check-yaml
- id: check-merge-conflict
- id: debug-statements
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 24.4.2
rev: 24.10.0
hooks:
- id: black
args: ["--config", "pyproject.toml"]
Expand All @@ -18,14 +18,14 @@ repos:
- id: isort
args: ["--show-config"]
- repo: https://github.com/pycqa/bandit
rev: 1.7.9
rev: 1.8.2
hooks:
- id: bandit
additional_dependencies: ['.[toml]']
args: ["--configfile", "pyproject.toml"]
exclude: '^tests/'
- repo: https://github.com/pycqa/flake8
rev: 7.1.0
rev: 7.1.1
hooks:
- id: flake8
additional_dependencies:
Expand All @@ -38,10 +38,10 @@ repos:
hooks:
- id: autoflake
- repo: https://github.com/asottile/pyupgrade
rev: v3.16.0
rev: v3.19.1
hooks:
- id: pyupgrade
args: ["--keep-runtime-typing"]
args: ["--py39-plus", "--keep-runtime-typing"]
- repo: local
hooks:
- id: mypy
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ Via [`pipx`][pipx]:
```console
pip install pipx
pipx install poetry
pipx inject poetry poetry-dynamic-versioning poetry-pre-commit-plugin
pipx inject poetry poetry-pre-commit-plugin
```

Via `pip`:

```console
pip install poetry
poetry self add poetry-dynamic-versioning poetry-pre-commit-plugin
poetry self add poetry-pre-commit-plugin
```

### Development tasks
Expand Down
4 changes: 2 additions & 2 deletions examples/event_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import collections
import os
from typing import Dict, Optional
from typing import Optional

from jmapc import Client, Ref, TypeState
from jmapc.methods import EmailChanges, EmailGet, EmailGetResponse
Expand Down Expand Up @@ -32,7 +32,7 @@ def email_change_callback(


# Listen for events from the EventSource endpoint
all_prev_state: Dict[str, TypeState] = collections.defaultdict(TypeState)
all_prev_state: dict[str, TypeState] = collections.defaultdict(TypeState)
for i, event in enumerate(client.events):
if i >= MAX_EVENTS:
# Exit after receiving MAX_EVENTS events
Expand Down
23 changes: 9 additions & 14 deletions jmapc/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,10 @@
from typing import (
Any,
Callable,
Dict,
List,
Sequence,
Set,
Tuple,
Type,
Union,
cast,
)
from collections.abc import Sequence

from dataclasses_json import config

Expand All @@ -30,9 +25,9 @@


def decode_method_responses(
value: Sequence[Tuple[str, Dict[str, Any], str]],
) -> List[InvocationResponseOrError]:
def _response_type(method_name: str) -> Type[ResponseOrError]:
value: Sequence[tuple[str, dict[str, Any], str]],
) -> list[InvocationResponseOrError]:
def _response_type(method_name: str) -> type[ResponseOrError]:
if method_name == "error":
return errors.Error
return Response.response_types.get(method_name, CustomResponse)
Expand All @@ -49,13 +44,13 @@ def _response_type(method_name: str) -> Type[ResponseOrError]:
@dataclass
class APIResponse(Model):
session_state: str
method_responses: List[InvocationResponseOrError] = field(
method_responses: list[InvocationResponseOrError] = field(
metadata=config(
encoder=lambda value: None,
decoder=decode_method_responses,
),
)
created_ids: List[str] = field(default_factory=list)
created_ids: list[str] = field(default_factory=list)


@dataclass
Expand All @@ -64,8 +59,8 @@ class APIRequest(Model):
repr=False,
metadata=config(exclude=cast(Callable[..., bool], lambda *_: True)),
)
method_calls: List[Tuple[str, Any, str]]
using: Set[str] = field(
method_calls: list[tuple[str, Any, str]]
using: set[str] = field(
init=False,
default_factory=lambda: {constants.JMAP_URN_CORE},
metadata=config(encoder=lambda value: sorted(list(value))),
Expand All @@ -77,7 +72,7 @@ def from_calls(
calls: Union[Sequence[Request], Sequence[Method], Method],
) -> APIRequest:
calls_list = calls if isinstance(calls, Sequence) else [calls]
invocations: List[Invocation] = []
invocations: list[Invocation] = []
# Create Invocations for Methods
for i, c in enumerate(calls_list):
if isinstance(c, Invocation):
Expand Down
23 changes: 6 additions & 17 deletions jmapc/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,10 @@

import functools
import mimetypes
from collections.abc import Generator, Sequence
from dataclasses import asdict, dataclass
from pathlib import Path
from typing import (
Any,
Generator,
Literal,
Optional,
Sequence,
Tuple,
Type,
TypeVar,
Union,
cast,
overload,
)
from typing import Any, Literal, Optional, TypeVar, Union, cast, overload

import requests
import sseclient
Expand All @@ -36,7 +25,7 @@
from .models import Blob, EmailBodyPart, Event
from .session import Session

RequestsAuth = Union[requests.auth.AuthBase, Tuple[str, str]]
RequestsAuth = Union[requests.auth.AuthBase, tuple[str, str]]
ClientType = TypeVar("ClientType", bound="Client")

REQUEST_TIMEOUT = 30
Expand All @@ -53,7 +42,7 @@ class ClientError(RuntimeError):
def __init__(
self,
*args: Any,
result: Sequence[InvocationResponseOrError],
result: Sequence[Union[InvocationResponse, InvocationResponseOrError]],
**kwargs: Any,
):
super().__init__(*args, **kwargs)
Expand All @@ -63,7 +52,7 @@ def __init__(
class Client:
@classmethod
def create_with_api_token(
cls: Type[ClientType],
cls: type[ClientType],
host: str,
api_token: str,
*args: Any,
Expand All @@ -74,7 +63,7 @@ def create_with_api_token(

@classmethod
def create_with_password(
cls: Type[ClientType],
cls: type[ClientType],
host: str,
user: str,
password: str,
Expand Down
8 changes: 4 additions & 4 deletions jmapc/errors.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
from __future__ import annotations

from dataclasses import dataclass
from typing import Any, Dict, List, Optional, Type, cast
from typing import Any, Optional, cast

from .serializer import Model

__all__ = ["Error", "ServerFail"]


class ErrorCollector(Model):
error_types: Dict[str, Type[Error]] = {}
error_types: dict[str, type[Error]] = {}

@classmethod
def __init_subclass__(cls) -> None:
error_class = cast(Type["Error"], cls)
error_class = cast(type["Error"], cls)
type_attr = getattr(error_class, "_type", None)
if type_attr:
ErrorCollector.error_types[type_attr] = error_class
Expand Down Expand Up @@ -62,7 +62,7 @@ class CannotCalculateChanges(Error):
@dataclass
class InvalidArguments(Error):
_type = "invalidArguments"
arguments: Optional[List[str]] = None
arguments: Optional[list[str]] = None
description: Optional[str] = None


Expand Down
8 changes: 4 additions & 4 deletions jmapc/fastmail/maskedemail_methods.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

from dataclasses import dataclass, field
from typing import Dict, List, Optional
from typing import Optional

from dataclasses_json import config

Expand All @@ -23,7 +23,7 @@ class MaskedEmailGet(MaskedEmailBase, Get):

@dataclass
class MaskedEmailGetResponse(MaskedEmailBase, GetResponse):
data: List[MaskedEmail] = field(metadata=config(field_name="list"))
data: list[MaskedEmail] = field(metadata=config(field_name="list"))


@dataclass
Expand All @@ -33,5 +33,5 @@ class MaskedEmailSet(MaskedEmailBase, Set):

@dataclass
class MaskedEmailSetResponse(MaskedEmailBase, SetResponse):
created: Optional[Dict[str, Optional[MaskedEmail]]]
updated: Optional[Dict[str, Optional[MaskedEmail]]]
created: Optional[dict[str, Optional[MaskedEmail]]]
updated: Optional[dict[str, Optional[MaskedEmail]]]
Loading
Loading