Skip to content

Commit

Permalink
Merge pull request #106 from PainterQubits/develop
Browse files Browse the repository at this point in the history
Merge develop into main
  • Loading branch information
alexhad6 authored Aug 9, 2023
2 parents 7b85ca3 + 423f15b commit 43e8ba1
Show file tree
Hide file tree
Showing 9 changed files with 587 additions and 440 deletions.
1 change: 1 addition & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ build:
- poetry config virtualenvs.create false
post_install:
- poetry install --without dev
- poetry run python -m ipykernel install --user

sphinx:
configuration: docs/conf.py
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [0.9.1] (Aug 9 2023)

### Changed

- Custom `ParamData` subclasses have an improved error message if extra keyword arguments
are passed.

## [0.9.0] (June 29 2023)

### Added
Expand Down Expand Up @@ -106,7 +113,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.0...develop
[unreleased]: https://github.com/PainterQubits/paramdb/compare/v0.9.1...develop
[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
[0.7.0]: https://github.com/PainterQubits/paramdb/releases/tag/v0.7.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.0
date-released: 2023-06-29
version: 0.9.1
date-released: 2023-08-09
url: "https://github.com/PainterQubits/paramdb"
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.0"
release = "0.9.1"

# General configuration
extensions = [
Expand Down
9 changes: 7 additions & 2 deletions paramdb/_param_data/_dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@

@dataclass_transform(kw_only_default=True)
class _ParamDataclass(ParamData):
"""Base class for parameter dataclasses."""
"""
Base class for parameter dataclasses.
Any keyword arguments given when creating a subclass are passed to the dataclass
constructor.
"""

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

def __getitem__(self, name: str) -> Any:
Expand Down
4 changes: 2 additions & 2 deletions paramdb/_param_data/_param_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ class ParamData(ABC):
# Most recently initialized structure that contains this parameter data
_parent: ParamData | None = None

def __init_subclass__(cls) -> None:
def __init_subclass__(cls, /, **kwargs: Any) -> None:
# Add subclass to dictionary of parameter data classes
super().__init_subclass__(**kwargs)
_param_classes[cls.__name__] = cls
super().__init_subclass__()

def _add_child(self, child: Any) -> None:
"""Add the given object as a child, if it is ``ParamData``."""
Expand Down
959 changes: 536 additions & 423 deletions poetry.lock

Large diffs are not rendered by default.

19 changes: 10 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "paramdb"
version = "0.9.0"
version = "0.9.1"
description = "Python package for storing and retrieving experiment parameters."
authors = ["Alex Hadley <[email protected]>"]
license = "BSD-3-Clause"
Expand All @@ -9,28 +9,29 @@ repository = "https://github.com/PainterQubits/paramdb"

[tool.poetry.dependencies]
python = "^3.10"
typing-extensions = "^4.7.0"
sqlalchemy = "^2.0.17"
typing-extensions = "^4.7.1"
sqlalchemy = "^2.0.19"
zstandard = "^0.21.0"
astropy = {version = "^5.3", optional = true}
astropy = {version = "^5.3.1", optional = true}

[tool.poetry.extras]
astropy = ["astropy"]

[tool.poetry.group.dev.dependencies]
pytest = "^7.4.0"
pytest-cov = "^4.1.0"
flake8 = "^6.0.0"
pylint = "^2.17.4"
flake8 = "^6.1.0"
pylint = "^2.17.5"
mypy = "^1.4.1"
black = "^23.3.0"
black = "^23.7.0"

[tool.poetry.group.docs.dependencies]
sphinx = "^7.0.1"
sphinx = "^7.1.2"
myst-parser = "^2.0.0"
furo = "^2023.5.20"
furo = "^2023.7.26"
sphinx-copybutton = "^0.5.2"
jupyter-sphinx = "^0.4.0"
ipykernel = "^6.25.1"
sphinx-autobuild = "^2021.3.14"

[tool.pytest.ini_options]
Expand Down
19 changes: 19 additions & 0 deletions tests/_param_data/test_param_data.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
"""Tests for the paramdb._param_data._param_data module."""

from dataclasses import is_dataclass
from copy import deepcopy
import pytest
from tests.helpers import CustomStruct, sleep_for_datetime
from paramdb import ParamData
from paramdb._param_data._param_data import get_param_class


def test_custom_subclass_extra_kwarg(param_data: ParamData) -> None:
"""Extra keyword arugments in a custom parameter data subclass raise a TypeError."""
cls = type(param_data)
with pytest.raises(TypeError) as exc_info:
# pylint: disable-next=unused-variable
class CustomParamData(cls, extra_kwarg="test"): # type: ignore
"""Custom parameter data class with an extra keyword arugment."""

error_message = str(exc_info.value)
if is_dataclass(cls):
assert (
error_message
== "dataclass() got an unexpected keyword argument 'extra_kwarg'"
)
else:
assert "takes no keyword arguments" in error_message


def test_is_param_data(param_data: ParamData) -> None:
"""Parameter data object is an instance of the `ParamData` class."""
assert isinstance(param_data, ParamData)
Expand Down

0 comments on commit 43e8ba1

Please sign in to comment.