Skip to content

Commit

Permalink
Add Python 3.12 support (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxbro authored Nov 8, 2023
1 parent 1e297bc commit 4f6d00f
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
name: Run pre-commit
runs-on: 'ubuntu-latest'
steps:
- uses: holoviz-dev/holoviz_tasks/pre-commit@v0.1a17
- uses: holoviz-dev/holoviz_tasks/pre-commit@v0.1a18
unit_test_suite:
name: Unit tests on ${{ matrix.os }} with Python ${{ matrix.python-version }}
needs: [pre_commit]
Expand All @@ -25,7 +25,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ['3.9', '3.10', '3.11']
python-version: ['3.9', '3.10', '3.11', '3.12']
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
Expand Down
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ exclude: (\.min\.js$|\.svg$|\.html$)
default_stages: [commit]
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-builtin-literals
- id: check-case-conflict
Expand All @@ -16,7 +16,7 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.292
rev: v0.1.4
hooks:
- id: ruff
args: [holonote]
Expand All @@ -25,7 +25,7 @@ repos:
args: [holonote]
files: holonote/
- repo: https://github.com/hoxbro/clean_notebook
rev: v0.1.11
rev: v0.1.13
hooks:
- id: clean-notebook
- repo: https://github.com/codespell-project/codespell
Expand Down
3 changes: 3 additions & 0 deletions holonote/annotate/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import pandas as pd
import param

from .util import sqlite_date_adapters

if TYPE_CHECKING:
from .typing import SpecDict

Expand Down Expand Up @@ -298,6 +300,7 @@ def __init__(self, column_schema=None, connect=True, **params):
self._initialize(column_schema, create_table=False)

def _initialize(self, column_schema, create_table=True):
sqlite_date_adapters()
if self.con is None:
self.con = sqlite3.connect(
self.filename, detect_types=sqlite3.PARSE_DECLTYPES | sqlite3.PARSE_COLNAMES
Expand Down
41 changes: 41 additions & 0 deletions holonote/annotate/util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import datetime
import sqlite3
import sys
from functools import cache


@cache
def sqlite_date_adapters() -> None:
# Python 3.12 has removed datetime support from sqlite3
# https://github.com/python/cpython/pull/93095
# The following code has been copied here from in Python 3.11:
# `sqlite3.dbapi2.register_adapters_and_converters`
# Including minor modifications to source code to pass linting
# https://docs.python.org/3/license.html#psf-license

if sys.version_info < (3, 12):
return

def adapt_date(val):
return val.isoformat()

def adapt_datetime(val):
return val.isoformat(" ")

def convert_date(val):
return datetime.date(*map(int, val.split(b"-")))

def convert_timestamp(val):
datepart, timepart = val.split(b" ")
year, month, day = map(int, datepart.split(b"-"))
timepart_full = timepart.split(b".")
hours, minutes, seconds = map(int, timepart_full[0].split(b":"))
microseconds = int(f"{timepart_full[1].decode():0<6.6}") if len(timepart_full) == 2 else 0

val = datetime.datetime(year, month, day, hours, minutes, seconds, microseconds)
return val

sqlite3.register_adapter(datetime.date, adapt_date)
sqlite3.register_adapter(datetime.datetime, adapt_datetime)
sqlite3.register_converter("date", convert_date)
sqlite3.register_converter("timestamp", convert_timestamp)
8 changes: 5 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ classifiers = [
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Operating System :: OS Independent",
]
dependencies = ["holoviews >=1.18.0a1", "pandas"]
dependencies = ["holoviews >=1.18.0", "pandas"]

[project.optional-dependencies]
dev = [
Expand All @@ -36,7 +37,7 @@ scripts.build = "bash conda/build.sh"
[tool.hatch.envs.test]
dependencies = ["pytest", "pytest-github-actions-annotate-failures"]
scripts.run = "python -m pytest holonote/tests"
matrix = [{ python = ["3.9", "3.10", "3.11"] }]
matrix = [{ python = ["3.9", "3.10", "3.11", "3.12"] }]

[tool.hatch.envs.fmt]
detached = true
Expand All @@ -47,10 +48,11 @@ scripts.update = "pre-commit autoupdate"
addopts = "-vv"
filterwarnings = [
"error",
# 2023-10: Datetime's utctimestamp() and utcnow() is deprecated in Python 3.12
"ignore:datetime.datetime.utcfromtimestamp():DeprecationWarning:dateutil.tz.tz", # https://github.com/dateutil/dateutil/pull/1285
]

[tool.ruff]
target-version = "py39"
line-length = 99

select = [
Expand Down

0 comments on commit 4f6d00f

Please sign in to comment.