Skip to content

Commit

Permalink
Merge pull request #117 from PainterQubits/#114-support-python-39
Browse files Browse the repository at this point in the history
#114 Support Python 3.9
  • Loading branch information
alexhad6 authored Aug 30, 2023
2 parents 423f15b + 8f7b41c commit 525b720
Show file tree
Hide file tree
Showing 12 changed files with 495 additions and 416 deletions.
28 changes: 21 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ on:
- develop

env:
PYTHON_VERSION: "3.10"
POETRY_VERSION: "1.5.1"
POETRY_VERSION: "1.6.1"
MAIN_PYTHON_VERSION: "3.9"

jobs:
ci:
strategy:
matrix:
python_version: ["3.9", "3.10", "3.11"]
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -27,34 +30,45 @@ jobs:
- name: Set up Python with Poetry cache
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
python-version: ${{ matrix.python_version }}
cache: poetry

- name: Install dependencies
run: poetry install --all-extras --without docs

- name: Check Formatting (Black)
- name: Check formatting (Black)
if: matrix.python_version == env.MAIN_PYTHON_VERSION
run: poetry run black paramdb tests --check

- name: Lint (Flake8)
if: matrix.python_version == env.MAIN_PYTHON_VERSION
run: poetry run flake8 paramdb tests

- name: Lint (Pylint)
if: matrix.python_version == env.MAIN_PYTHON_VERSION
run: poetry run pylint paramdb tests

- name: Mypy cache
if: matrix.python_version == env.MAIN_PYTHON_VERSION
uses: actions/cache@v3
with:
path: .mypy_cache
key: mypy-${{ runner.os }}-python-${{ env.PYTHON_VERSION }}-${{ github.sha }}
key: mypy-${{ runner.os }}-python-${{ matrix.python_version }}-${{ github.sha }}
restore-keys: |
mypy-${{ runner.os }}-python-${{ env.PYTHON_VERSION }}-
mypy-${{ runner.os }}-python-${{ matrix.python_version }}-
- name: Type Check (Mypy)
- name: Type check (Mypy)
if: matrix.python_version == env.MAIN_PYTHON_VERSION
run: poetry run mypy paramdb tests

- name: Test (Pytest)
if: matrix.python_version != env.MAIN_PYTHON_VERSION
run: poetry run pytest

- name: Test (Pytest) with coverage
if: matrix.python_version == env.MAIN_PYTHON_VERSION
run: poetry run pytest --cov=paramdb --cov-report=xml

- name: Upload coverage reports to Codecov
if: matrix.python_version == env.MAIN_PYTHON_VERSION
uses: codecov/codecov-action@v3
3 changes: 1 addition & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ on:
types: [published]

env:
PYTHON_VERSION: "3.10"
POETRY_VERSION: "1.5.1"
POETRY_VERSION: "1.6.1"

jobs:
build:
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- Support for Python 3.9

### Removed

- Parameter dataclass bases (`Param` and `Struct`) no longer set `kw_only` to True by
default (since this feature does not exist in Python 3.9).

## [0.9.1] (Aug 9 2023)

### Changed
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# ParamDB

[![PyPI Latest Release](https://img.shields.io/pypi/v/paramdb)](https://pypi.org/project/paramdb/)
![PyPI Python Versions](https://img.shields.io/pypi/pyversions/paramdb)
[![License](https://img.shields.io/pypi/l/paramdb)](https://github.com/PainterQubits/paramdb/blob/main/LICENSE)
[![CI](https://github.com/PainterQubits/paramdb/actions/workflows/ci.yml/badge.svg)](https://github.com/PainterQubits/paramdb/actions/workflows/ci.yml)
[![Codecov](https://codecov.io/github/PainterQubits/paramdb/branch/main/graph/badge.svg?token=PQEJWLBTBK)](https://codecov.io/github/PainterQubits/paramdb)
Expand Down
18 changes: 12 additions & 6 deletions docs/parameter-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,24 @@ param.value
The dataclass aspects of the subclass can be customized by passing keyword arguments when
defining the custom class (the same arguments that would be passed to the [`@dataclass`]
decorator), and by using the dataclass [`field`] function. The class arguments have the
same default values as in [`@dataclass`], except `kw_only` is True by default for
ParamDB dataclasses to facilitate dataclass inheritance with default values. An example of
dataclass customization is shown below.
same default values as in [`@dataclass`]. An example of dataclass customization is shown
below.

```{note}
The `kw_only` setting below only works in Python 3.10, but is useful for defining
non-default arguments after those with default values (like in the example), especially
when building up dataclasses through inheritance.
```

```{jupyter-execute}
from dataclasses import field
class CustomizedDataclassParam(Param, kw_only=False, repr=False):
class CustomizedDataclassParam(Param, kw_only=True):
values: list[int] = field(default_factory=list)
count: int
customized_dataclass_param = CustomizedDataclassParam([1, 2, 3])
customized_dataclass_param.values
customized_dataclass_param = CustomizedDataclassParam(count=123)
customized_dataclass_param
```

```{warning}
Expand Down
1 change: 1 addition & 0 deletions paramdb/_database.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Parameter database backend using SQLAlchemy and SQLite."""

from __future__ import annotations
from typing import TypeVar, Generic, Literal, Any, overload
from dataclasses import dataclass
from datetime import datetime, timezone
Expand Down
2 changes: 1 addition & 1 deletion paramdb/_param_data/_collections.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Parameter data collection classes."""

from __future__ import annotations
from typing import TypeVar, Generic, SupportsIndex, Any, overload
from collections.abc import (
Iterator,
Expand All @@ -17,7 +18,6 @@
from paramdb._keys import PARAMLIST_ITEMS_KEY
from paramdb._param_data._param_data import ParamData


T = TypeVar("T")


Expand Down
6 changes: 3 additions & 3 deletions paramdb/_param_data/_dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from paramdb._param_data._param_data import ParamData


@dataclass_transform(kw_only_default=True)
@dataclass_transform()
class _ParamDataclass(ParamData):
"""
Base class for parameter dataclasses.
Expand All @@ -19,10 +19,10 @@ class _ParamDataclass(ParamData):
constructor.
"""

def __init_subclass__(cls, /, kw_only: bool = True, **kwargs: Any) -> None:
def __init_subclass__(cls, /, **kwargs: Any) -> None:
# Convert subclasses into dataclasses
super().__init_subclass__() # kwargs are passed to dataclass constructor
dataclass(kw_only=kw_only, **kwargs)(cls)
dataclass(**kwargs)(cls)

def __getitem__(self, name: str) -> Any:
# Enable getting attributes via indexing
Expand Down
Loading

0 comments on commit 525b720

Please sign in to comment.