Skip to content

Commit

Permalink
drop Python 3.9 and add support for 3.12 (#502)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmeier authored Aug 29, 2024
1 parent ef6c6a5 commit dff37bd
Show file tree
Hide file tree
Showing 18 changed files with 77 additions and 141 deletions.
2 changes: 1 addition & 1 deletion .github/actions/setup-env/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: "Setup development environment"

inputs:
python-version:
default: "3.9"
default: "3.10"
description: "Python version to install."
optional-dependencies:
default: "true"
Expand Down
20 changes: 10 additions & 10 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ jobs:
- ubuntu-latest
- windows-latest
- macos-latest
python-version: ["3.9"]
python-version: ["3.10"]
include:
- os: ubuntu-latest
python-version: "3.10"
- os: ubuntu-latest
python-version: "3.11"
- os: ubuntu-latest
python-version: "3.12"

fail-fast: false

Expand Down Expand Up @@ -91,22 +91,22 @@ jobs:
- chromium
- firefox
python-version:
- "3.9"
- "3.10"
- "3.11"
- "3.10"
- "3.12"
exclude:
- python-version: "3.10"
os: windows-latest
- python-version: "3.11"
os: windows-latest
- python-version: "3.10"
os: macos-latest
- python-version: "3.12"
os: windows-latest
- python-version: "3.11"
os: macos-latest
- python-version: "3.12"
os: macos-latest
include:
- browser: webkit
os: macos-latest
python-version: "3.9"
python-version: "3.10"

fail-fast: false

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/update-docker-requirements.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- name: Setup environment
uses: ./.github/actions/setup-env
with:
python-version: "3.11"
python-version: "3.12"
optional-dependencies: "false"

- name: Update docker requirements
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.11
FROM python:3.12

WORKDIR /opt/ragna

Expand Down
2 changes: 1 addition & 1 deletion environment-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: ragna-dev
channels:
- conda-forge
dependencies:
- python =3.9
- python =3.10
- pip
- git-lfs
- pip:
Expand Down
10 changes: 7 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@ classifiers = [
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
]
requires-python = ">=3.9"
requires-python = ">=3.10"
dependencies = [
"aiofiles",
"emoji",
"fastapi",
"httpx",
"importlib_metadata>=4.6; python_version<'3.10'",
"packaging",
"panel==1.4.4",
"pydantic>=2",
Expand Down Expand Up @@ -96,14 +95,19 @@ ignore = ["E501"]
[tool.pytest.ini_options]
minversion = "6.0"
addopts = "-ra --tb=short --asyncio-mode=auto"
asyncio_default_fixture_loop_scope = "function"
testpaths = [
"tests",
]
filterwarnings = [
"error",
"ignore::ResourceWarning",
# https://github.com/lancedb/lancedb/issues/1296
"ignore:Function 'semver.parse_version_info' is deprecated:DeprecationWarning"
"ignore:Function 'semver.parse_version_info' is deprecated:DeprecationWarning",
# chromadb -> opentelemetry -> google
"ignore:Type google._upb._message:DeprecationWarning",
# chromadb
"ignore:Python 3.14 will:DeprecationWarning"
]
xfail_strict = true

Expand Down
97 changes: 0 additions & 97 deletions ragna/_compat.py

This file was deleted.

3 changes: 1 addition & 2 deletions ragna/assistants/_http_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import httpx

import ragna
from ragna._compat import anext
from ragna.core import (
Assistant,
EnvVarRequirement,
Expand Down Expand Up @@ -132,7 +131,7 @@ async def read(self, n: int) -> bytes:
# and set up decoding.
if n == 0:
return b""
return await anext(self._ait, b"") # type: ignore[call-arg]
return await anext(self._ait, b"")

@contextlib.asynccontextmanager
async def _stream_json(
Expand Down
10 changes: 3 additions & 7 deletions ragna/core/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@
import pydantic
import pydantic_core

from ragna._compat import importlib_metadata_package_distributions

importlib_metadata_package_distributions = functools.cache(
importlib_metadata_package_distributions
)
packages_distributions = functools.cache(importlib.metadata.packages_distributions)


class RagnaExceptionHttpDetail(enum.Enum):
Expand Down Expand Up @@ -98,8 +94,8 @@ def is_available(self) -> bool:

for module_name in {
module_name
for module_name, distribution_names in importlib_metadata_package_distributions().items()
if distribution.name in distribution_names # type: ignore[attr-defined]
for module_name, distribution_names in packages_distributions().items()
if distribution.name in distribution_names
and module_name not in self._exclude_modules
}:
try:
Expand Down
1 change: 0 additions & 1 deletion ragna/deploy/_api/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import ragna
import ragna.core
from ragna._compat import aiter, anext
from ragna._utils import handle_localhost_origins
from ragna.core import Assistant, Component, Rag, RagnaException, SourceStorage
from ragna.core._rag import SpecialChatParams
Expand Down
33 changes: 31 additions & 2 deletions ragna/deploy/_api/orm.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
from typing import Any
from datetime import datetime, timezone
from typing import Any, Optional

from sqlalchemy import Column, ForeignKey, Table, types
from sqlalchemy.engine import Dialect
Expand Down Expand Up @@ -30,6 +31,34 @@ def process_result_value(
return json.loads(value)


class UtcDateTime(types.TypeDecorator):
"""UTC timezone aware datetime type.
This is needed because sqlalchemy.types.DateTime(timezone=True) does not
consistently store the timezone.
"""

impl = types.DateTime

cache_ok = True

def process_bind_param( # type: ignore[override]
self, value: Optional[datetime], dialect: Dialect
) -> Optional[datetime]:
if value is not None:
assert value.tzinfo == timezone.utc

return value

def process_result_value(
self, value: Optional[datetime], dialect: Dialect
) -> Optional[datetime]:
if value is None:
return None

return value.replace(tzinfo=timezone.utc)


class Base(DeclarativeBase):
pass

Expand Down Expand Up @@ -134,4 +163,4 @@ class Message(Base):
secondary=source_message_association_table,
back_populates="messages",
)
timestamp = Column(types.DateTime, nullable=False)
timestamp = Column(UtcDateTime, nullable=False)
18 changes: 14 additions & 4 deletions ragna/deploy/_api/schemas.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
from __future__ import annotations

import datetime
import uuid
from typing import Any
from datetime import datetime, timezone
from typing import Annotated, Any

from pydantic import BaseModel, Field
from pydantic import AfterValidator, BaseModel, Field

import ragna.core


def _set_utc_timezone(v: datetime) -> datetime:
if v.tzinfo is None:
return v.replace(tzinfo=timezone.utc)
else:
return v.astimezone(timezone.utc)


UtcDateTime = Annotated[datetime, AfterValidator(_set_utc_timezone)]


class Components(BaseModel):
documents: list[str]
source_storages: list[dict[str, Any]]
Expand Down Expand Up @@ -75,7 +85,7 @@ class Message(BaseModel):
content: str
role: ragna.core.MessageRole
sources: list[Source] = Field(default_factory=list)
timestamp: datetime.datetime = Field(default_factory=datetime.datetime.utcnow)
timestamp: UtcDateTime = Field(default_factory=lambda: datetime.now(timezone.utc))

@classmethod
def from_core(cls, message: ragna.core.Message) -> Message:
Expand Down
2 changes: 1 addition & 1 deletion ragna/deploy/_ui/api_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,6 @@ async def start_and_prepare(
return chat["id"]

def improve_message(self, msg):
msg["timestamp"] = datetime.strptime(msg["timestamp"], "%Y-%m-%dT%H:%M:%S.%f")
msg["timestamp"] = datetime.strptime(msg["timestamp"], "%Y-%m-%dT%H:%M:%S.%fZ")
msg["content"] = emoji.emojize(msg["content"], language="alias")
return msg
2 changes: 0 additions & 2 deletions ragna/deploy/_ui/central_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import param
from panel.reactive import ReactiveHTML

from ragna._compat import anext

from . import styles as ui


Expand Down
3 changes: 1 addition & 2 deletions ragna/source_storages/_vector_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
cast,
)

from ragna._compat import itertools_pairwise
from ragna.core import (
PackageRequirement,
Page,
Expand Down Expand Up @@ -106,7 +105,7 @@ def _page_numbers_to_str(self, page_numbers: Optional[Iterable[int]]) -> str:

ranges_str = []
range_int = []
for current_page_number, next_page_number in itertools_pairwise(
for current_page_number, next_page_number in itertools.pairwise(
itertools.chain(sorted(page_numbers), [None])
):
current_page_number = cast(int, current_page_number)
Expand Down
4 changes: 2 additions & 2 deletions requirements-docker.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# This file is autogenerated by pip-compile with Python 3.11
# This file is autogenerated by pip-compile with Python 3.12
# by the following command:
#
# pip-compile --extra=all --output-file=requirements-docker.lock --strip-extras pyproject.toml
Expand Down Expand Up @@ -158,7 +158,7 @@ oauthlib==3.2.2
# via
# kubernetes
# requests-oauthlib
onnxruntime==1.16.3
onnxruntime==1.19.0
# via chromadb
opentelemetry-api==1.22.0
# via
Expand Down
Loading

0 comments on commit dff37bd

Please sign in to comment.