Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge develop into main #118

Merged
merged 9 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [0.10.0] (Aug 30 2023)

### 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 Expand Up @@ -113,7 +124,8 @@ project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
- Database class `ParamDB` to store parameters in a SQLite file
- Ability to retrieve the commit history as `CommitEntry` objects

[unreleased]: https://github.com/PainterQubits/paramdb/compare/v0.9.1...develop
[unreleased]: https://github.com/PainterQubits/paramdb/compare/v0.10.0...develop
[0.10.0]: https://github.com/PainterQubits/paramdb/releases/tag/v0.10.0
[0.9.1]: https://github.com/PainterQubits/paramdb/releases/tag/v0.9.1
[0.9.0]: https://github.com/PainterQubits/paramdb/releases/tag/v0.9.0
[0.8.0]: https://github.com/PainterQubits/paramdb/releases/tag/v0.8.0
Expand Down
4 changes: 2 additions & 2 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ authors:
- family-names: "Hadley"
given-names: "Alex"
title: "ParamDB"
version: 0.9.1
date-released: 2023-08-09
version: 0.10.0
date-released: 2023-08-30
url: "https://github.com/PainterQubits/paramdb"
3 changes: 2 additions & 1 deletion 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 All @@ -26,7 +27,7 @@ To install along with [Astropy] for support for storing scalar [`astropy.units.Q
objects in the database, ParamDB can be installed with the `astropy` extra:

```
pip install -U paramdb[astropy]
pip install -U "paramdb[astropy]"
```

[astropy]: https://docs.astropy.org/en/stable/index.html
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
project = "ParamDB"
copyright = "2023, California Institute of Technology"
author = "Alex Hadley"
release = "0.9.1"
release = "0.10.0"

# General configuration
extensions = [
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