Skip to content

Commit

Permalink
chg: linter changes from ruff for py3.12
Browse files Browse the repository at this point in the history
  • Loading branch information
lindsay-stevens committed Mar 27, 2024
1 parent d3c4368 commit 19978c3
Show file tree
Hide file tree
Showing 27 changed files with 262 additions and 243 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ jobs:
pip list
# Linter.
- run: ruff check pyodk tests --no-fix
- run: ruff format pyodk tests --diff
- run: ruff check pyodk tests docs --no-fix
- run: ruff format pyodk tests docs --diff

test:
runs-on: ${{ matrix.os }}
Expand Down
8 changes: 4 additions & 4 deletions docs/examples/app_user_provisioner/app_user_provisioner.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,25 @@
To run the script, use `python app_user_provisioner.py`.
"""

import base64
import glob
import json
import zlib
from typing import Any, Dict
from typing import Any

import segno
from PIL import Image, ImageDraw, ImageFont, ImageOps

from pyodk.client import Client

# Customise these settings to your environment.
PROJECT_ID = 149
PROJECT_NAME = "My Cool Project"
FORMS_TO_ACCESS = ["all-widgets", "afp-knowledge"]
ADMIN_PASSWORD = "s00p3rs3cr3t"
ADMIN_PASSWORD = "s00p3rs3cr3t" # noqa: S105


def get_settings(server_url: str, project_name: str, username: str) -> Dict[str, Any]:
def get_settings(server_url: str, project_name: str, username: str) -> dict[str, Any]:
"""Template for the settings to encode in the QR image. Customise as needed."""
return {
"general": {
Expand Down
2 changes: 1 addition & 1 deletion pyodk/_endpoints/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__all__ = tuple()
__all__ = ()
4 changes: 2 additions & 2 deletions pyodk/_endpoints/auth.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from typing import TYPE_CHECKING, Optional
from typing import TYPE_CHECKING

from pyodk._utils import config
from pyodk.errors import PyODKError
Expand All @@ -11,7 +11,7 @@


class AuthService:
def __init__(self, session: "Session", cache_path: Optional[str] = None) -> None:
def __init__(self, session: "Session", cache_path: str | None = None) -> None:
self.session: "Session" = session
self.cache_path: str = cache_path

Expand Down
6 changes: 1 addition & 5 deletions pyodk/_endpoints/bases.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Dict

from pydantic import BaseModel

from pyodk._utils.session import Session
Expand All @@ -17,15 +15,13 @@ class Manager:
"""Base for managers of data model classes."""

__slots__ = ("__weakref__",)
pass

@classmethod
def from_dict(cls, session: Session, project_id: int, data: Dict) -> Model:
def from_dict(cls, session: Session, project_id: int, data: dict) -> Model:
raise NotImplementedError()


class Service:
"""Base for services interacting with the ODK Central API over HTTP."""

__slots__ = ("__weakref__",)
pass
31 changes: 15 additions & 16 deletions pyodk/_endpoints/comments.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import logging
from datetime import datetime
from typing import List, Optional

from pyodk._endpoints import bases
from pyodk._utils import validators as pv
Expand Down Expand Up @@ -36,23 +35,23 @@ class CommentService(bases.Service):
def __init__(
self,
session: Session,
default_project_id: Optional[int] = None,
default_form_id: Optional[str] = None,
default_instance_id: Optional[str] = None,
default_project_id: int | None = None,
default_form_id: str | None = None,
default_instance_id: str | None = None,
urls: URLs = None,
):
self.urls: URLs = urls if urls is not None else URLs()
self.session: Session = session
self.default_project_id: Optional[int] = default_project_id
self.default_form_id: Optional[str] = default_form_id
self.default_instance_id: Optional[str] = default_instance_id
self.default_project_id: int | None = default_project_id
self.default_form_id: str | None = default_form_id
self.default_instance_id: str | None = default_instance_id

def list(
self,
form_id: Optional[str] = None,
project_id: Optional[int] = None,
instance_id: Optional[str] = None,
) -> List[Comment]:
form_id: str | None = None,
project_id: int | None = None,
instance_id: str | None = None,
) -> list[Comment]:
"""
Read all Comment details.
Expand All @@ -66,7 +65,7 @@ def list(
iid = pv.validate_instance_id(instance_id, self.default_instance_id)
except PyODKError as err:
log.error(err, exc_info=True)
raise err
raise

response = self.session.response_or_error(
method="GET",
Expand All @@ -81,9 +80,9 @@ def list(
def post(
self,
comment: str,
project_id: Optional[int] = None,
form_id: Optional[str] = None,
instance_id: Optional[str] = None,
project_id: int | None = None,
form_id: str | None = None,
instance_id: str | None = None,
) -> Comment:
"""
Create a Comment.
Expand All @@ -103,7 +102,7 @@ def post(
json = {"body": comment}
except PyODKError as err:
log.error(err, exc_info=True)
raise err
raise

response = self.session.response_or_error(
method="POST",
Expand Down
15 changes: 7 additions & 8 deletions pyodk/_endpoints/form_assignments.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging
from typing import Optional

from pyodk._endpoints import bases
from pyodk._utils import validators as pv
Expand All @@ -23,21 +22,21 @@ class FormAssignmentService(bases.Service):
def __init__(
self,
session: Session,
default_project_id: Optional[int] = None,
default_form_id: Optional[str] = None,
default_project_id: int | None = None,
default_form_id: str | None = None,
urls: URLs = None,
):
self.urls: URLs = urls if urls is not None else URLs()
self.session: Session = session
self.default_project_id: Optional[int] = default_project_id
self.default_form_id: Optional[str] = default_form_id
self.default_project_id: int | None = default_project_id
self.default_form_id: str | None = default_form_id

def assign(
self,
role_id: int,
user_id: int,
form_id: Optional[str] = None,
project_id: Optional[int] = None,
form_id: str | None = None,
project_id: int | None = None,
) -> bool:
"""
Assign a user to a role for a form.
Expand All @@ -54,7 +53,7 @@ def assign(
uid = pv.validate_int(user_id, key="user_id")
except PyODKError as err:
log.error(err, exc_info=True)
raise err
raise

response = self.session.response_or_error(
method="POST",
Expand Down
17 changes: 8 additions & 9 deletions pyodk/_endpoints/form_draft_attachments.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import logging
from pathlib import Path
from typing import Optional

from pyodk._endpoints import bases
from pyodk._utils import validators as pv
Expand All @@ -24,21 +23,21 @@ class FormDraftAttachmentService(bases.Service):
def __init__(
self,
session: Session,
default_project_id: Optional[int] = None,
default_form_id: Optional[str] = None,
default_project_id: int | None = None,
default_form_id: str | None = None,
urls: URLs = None,
):
self.urls: URLs = urls if urls is not None else URLs()
self.session: Session = session
self.default_project_id: Optional[int] = default_project_id
self.default_form_id: Optional[str] = default_form_id
self.default_project_id: int | None = default_project_id
self.default_form_id: str | None = default_form_id

def upload(
self,
file_path: str,
file_name: Optional[str] = None,
form_id: Optional[str] = None,
project_id: Optional[int] = None,
file_name: str | None = None,
form_id: str | None = None,
project_id: int | None = None,
) -> bool:
"""
Upload a Form Draft Attachment.
Expand All @@ -56,7 +55,7 @@ def upload(
file_name = pv.validate_str(file_path.name, key="file_name")
except PyODKError as err:
log.error(err, exc_info=True)
raise err
raise

with open(file_path, "rb") as fd:
response = self.session.response_or_error(
Expand Down
29 changes: 14 additions & 15 deletions pyodk/_endpoints/form_drafts.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import logging
from contextlib import nullcontext
from pathlib import Path
from typing import Optional

from pyodk._endpoints import bases
from pyodk._utils import validators as pv
Expand All @@ -26,21 +25,21 @@ class FormDraftService(bases.Service):
def __init__(
self,
session: Session,
default_project_id: Optional[int] = None,
default_form_id: Optional[str] = None,
default_project_id: int | None = None,
default_form_id: str | None = None,
urls: URLs = None,
):
self.urls: URLs = urls if urls is not None else URLs()
self.session: Session = session
self.default_project_id: Optional[int] = default_project_id
self.default_form_id: Optional[str] = default_form_id
self.default_project_id: int | None = default_project_id
self.default_form_id: str | None = default_form_id

def create(
self,
file_path: Optional[str] = None,
ignore_warnings: Optional[bool] = True,
form_id: Optional[str] = None,
project_id: Optional[int] = None,
file_path: str | None = None,
ignore_warnings: bool | None = True,
form_id: str | None = None,
project_id: int | None = None,
) -> bool:
"""
Create a Form Draft.
Expand Down Expand Up @@ -70,7 +69,7 @@ def create(
elif file_path.suffix == ".xml":
content_type = "application/xml"
else:
raise PyODKError(
raise PyODKError( # noqa: TRY301
"Parameter 'file_path' file name has an unexpected extension, "
"expected one of '.xlsx', '.xls', '.xml'."
)
Expand All @@ -80,7 +79,7 @@ def create(
}
except PyODKError as err:
log.error(err, exc_info=True)
raise err
raise

with open(file_path, "rb") if file_path is not None else nullcontext() as fd:
response = self.session.response_or_error(
Expand All @@ -97,9 +96,9 @@ def create(

def publish(
self,
form_id: Optional[str] = None,
project_id: Optional[int] = None,
version: Optional[str] = None,
form_id: str | None = None,
project_id: int | None = None,
version: str | None = None,
) -> bool:
"""
Publish a Form Draft.
Expand All @@ -117,7 +116,7 @@ def publish(
params[key] = pv.validate_str(version, key=key)
except PyODKError as err:
log.error(err, exc_info=True)
raise err
raise

response = self.session.response_or_error(
method="POST",
Expand Down
Loading

0 comments on commit 19978c3

Please sign in to comment.