Skip to content

Commit

Permalink
Merge pull request #392 from ndustrialio/breaking/drop-py3.8-support
Browse files Browse the repository at this point in the history
breaking: drop support for Python 3.8 [CONTXT-9166]
  • Loading branch information
mgagliardo91 authored Dec 11, 2024
2 parents 455ba04 + 66a7824 commit 8ea8298
Show file tree
Hide file tree
Showing 11 changed files with 695 additions and 529 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
python: ["3.8", "3.9", "3.10", "3.11"]
python: ["3.9", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v3
- run: pipx install poetry
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ jobs:
fetch-depth: 0
- uses: actions/setup-python@v2
with:
python-version: 3.8
python-version: 3.9
- run: pip install poetry
- name: Set up cache
uses: actions/cache@v2
with:
path: .venv
key: ${{ runner.os }}-venv-py3.8-${{ hashFiles('**/poetry.lock') }}
key: ${{ runner.os }}-venv-py3.9-${{ hashFiles('**/poetry.lock') }}
- name: Install package
run: poetry install
- name: Publish documentation
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ _the Python SDK for Contxt_

[![CI](https://github.com/ndustrialio/contxt-sdk-python/workflows/CI/badge.svg)](https://github.com/ndustrialio/contxt-sdk-python/actions?query=workflow%3ACI)
[![pypi version](https://img.shields.io/pypi/v/contxt-sdk.svg)](https://pypi.org/project/contxt-sdk/)
![python](https://img.shields.io/badge/python-3.8+-blue.svg)
![python](https://img.shields.io/badge/python-3.9+-blue.svg)

## Installation

Expand Down
6 changes: 3 additions & 3 deletions contxt/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
LAST_WEEK = NOW - timedelta(days=7)

# FIXME
OPTIONAL_PROMPT_KWARGS = {
OPTIONAL_PROMPT_KWARGS: Any = {
"prompt": True,
"default": "<none>",
"callback": lambda ctx, param, value: value if value != "<none>" else None,
Expand All @@ -23,14 +23,14 @@ def warn(msg: str):


def print_table(
items: List[Any], keys: Optional[List[str]] = None, sort_by: Optional[str] = None, count: bool = True
items: Any, keys: Optional[List[str]] = None, sort_by: Optional[str] = None, count: bool = True
) -> None:
if keys:
items = pluck(keys=keys, items=items)
sort_by = sort_by if sort_by in keys else None
if items:
print(Serializer.to_table(items, sort_by=sort_by))
if count:
if count and isinstance(items, list):
print(f"Count: {len(items)}")


Expand Down
2 changes: 1 addition & 1 deletion contxt/services/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def _log_response(self, response: Response, *args, **kwargs) -> None:
t = response.elapsed.total_seconds()
logger.debug(
f"Called {response.request.method} {response.url} with body" # type: ignore
f" {response.request.body} ({t} s)"
f" {response.request.body!r} ({t} s)"
)

def _process_response(self, response: Response) -> Dict:
Expand Down
4 changes: 2 additions & 2 deletions contxt/services/contxt.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import datetime
from typing import Any, Dict, List, Optional
from typing import Any, Dict, List, Optional, Union

from ..auth import Auth
from ..models.contxt import (
Expand Down Expand Up @@ -100,7 +100,7 @@ def get_project(self, project_id) -> Project:
resp = self.get(f"stacks/{project_id}")
return Project.from_api(resp)

def get_services(self, project_id: int = None) -> List[Service]:
def get_services(self, project_id: Union[int, None] = None) -> List[Service]:
if project_id:
resp = self.get(f"stacks/{project_id}")
return [Service.from_api(rec) for rec in resp["Services"]]
Expand Down
10 changes: 6 additions & 4 deletions contxt/services/iot.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from collections import defaultdict
from copy import deepcopy
from datetime import datetime, timedelta, timezone
from typing import Any, Dict, Iterable, List, Optional, Tuple
from typing import Any, Dict, Iterable, List, Optional, Tuple, Union

from requests import Request

Expand Down Expand Up @@ -148,7 +148,7 @@ def create_field(self, field: Field) -> Field:
def get_time_series_for_field(
self,
field: Field,
start_time: datetime = None,
start_time: Union[datetime, None] = None,
window: Window = Window.RAW,
end_time: Optional[datetime] = None,
per_page: int = 1000,
Expand All @@ -174,7 +174,7 @@ def get_time_series_for_field(
def get_time_series_for_fields(
self,
fields: List[Field],
start_time: datetime = None,
start_time: Union[datetime, None] = None,
window: Window = Window.RAW,
end_time: Optional[datetime] = None,
) -> List[FieldTimeSeries]:
Expand Down Expand Up @@ -443,7 +443,9 @@ def send_time_series(

return responses

def get_source_field_cursor(self, source_key: str, field_name: str = None) -> Optional[datetime]:
def get_source_field_cursor(
self, source_key: str, field_name: Union[str, None] = None
) -> Optional[datetime]:
"""Get the cursor for the given source and field"""

url = f"org/{self.org_id}/sources/{source_key}"
Expand Down
4 changes: 2 additions & 2 deletions contxt/utils/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from enum import Enum
from json import dump, dumps
from pathlib import Path
from typing import Any, Callable, Iterable, Optional
from typing import Any, Callable, Iterable, Optional, Union

from tabulate import tabulate

Expand All @@ -21,7 +21,7 @@ def _keys(obj):
return []

@staticmethod
def to_dict(obj: Any, cls_key: str = None, key_filter: Callable = None):
def to_dict(obj: Any, cls_key: Union[str, None] = None, key_filter: Union[Callable, None] = None):
"""Serializes `obj` to a `dict`. To use a custom format, overload
`obj.to_dict()`.
Expand Down
Loading

0 comments on commit 8ea8298

Please sign in to comment.