Skip to content

Commit

Permalink
feat: drop python 3.9 and env list fixes (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
zifeo authored Sep 16, 2024
1 parent 932179f commit b1d5980
Show file tree
Hide file tree
Showing 8 changed files with 217 additions and 186 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ jobs:
test-release:
uses: zifeo/workflows/.github/workflows/py-test-release.yml@main
with:
python-matrix: '["3.8", "3.9", "3.10", "3.11"]'
poetry-version: "1.3.2"
python-version: "3.11"
python-matrix: '["3.9", "3.10", "3.11", "3.12"]'
poetry-version: "1.8.3"
python-version: "3.12"
publish-pypi: true
secrets:
pypi-token: ${{ secrets.PYPI_TOKEN }}
6 changes: 4 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
repos:
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.1.9"
rev: "v0.6.5"
hooks:
- id: ruff
args:
- --fix
- id: ruff-format
- repo: https://github.com/commitizen-tools/commitizen
rev: v3.13.0
rev: v3.29.0
hooks:
- id: commitizen
stages: [commit-msg]
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ hocon/json/yaml/properties/env-vars/dict/cli support.

## Getting started

Requires at least Python 3.8.
Requires at least Python 3.9.

```bash
# pypi
Expand Down Expand Up @@ -77,11 +77,11 @@ zone {

class AbstractBaseClass:
pass

@dataclass
class Person(AbstractBaseClass):
name: Text

@dataclass
class Zone(AbstractBaseClass):
area_code: int
Expand Down
6 changes: 6 additions & 0 deletions dataconf/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ class EnvListOrderException(Exception):
pass


class EnvListFormatException(Exception):
"""Format exception."""

pass


class ParseException(Exception):
"""Parsing exception."""

Expand Down
9 changes: 5 additions & 4 deletions dataconf/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from typing import Type
from typing import Union

from dataconf.exceptions import AmbiguousSubclassException
from dataconf.exceptions import AmbiguousSubclassException, EnvListFormatException
from dataconf.exceptions import EnvListOrderException
from dataconf.exceptions import MalformedConfigException
from dataconf.exceptions import MissingTypeException
Expand Down Expand Up @@ -333,6 +333,8 @@ def set_lens(p, focus, v):
if len(p) == 1:
# []x
if isinstance(focus, list):
if not isinstance(p[0], int):
raise EnvListFormatException
if p[0] != len(focus):
raise EnvListOrderException
focus.append(v)
Expand All @@ -346,9 +348,8 @@ def set_lens(p, focus, v):
if p[0] not in focus:
# []{x}
if isinstance(focus, list):
if p[0] != len(focus):
raise EnvListOrderException
focus.append({})
if p[0] == len(focus):
focus.append({})
# {}{x}
else:
focus[p[0]] = {}
Expand Down
315 changes: 153 additions & 162 deletions poetry.lock

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ include = [
classifiers = [
"Topic :: Software Development :: Libraries :: Python Modules",
"Programming Language :: Python",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11"
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12"
]
keywords = [
"configuration",
Expand All @@ -32,19 +32,19 @@ keywords = [
dataconf = 'dataconf.cli:run'

[tool.poetry.dependencies]
python = "^3.8"
python-dateutil = "^2.8.2"
PyYAML = "^6.0.1"
python = "^3.9"
python-dateutil = "^2.9.0.post0"
PyYAML = "^6.0.2"
isodate = "^0.6.1"
pyhocon = "^0.3.61"
pyparsing = "^3.1.2"
pyparsing = "^3.1.4"

[tool.poetry.group.dev.dependencies]
pytest = ">=7.4.2,<9.0.0"
pre-commit = ">=2.21,<4.0"
commitizen = ">=2.42.1,<4.0.0"
pytest-httpserver = "^1.0.8"
ruff = ">=0.5.0,<0.7.0"
pytest = ">=8.3.3"
pre-commit = ">=3.8.0"
commitizen = ">=3.29.0"
pytest-httpserver = "^1.1.0"
ruff = ">=0.6.5"

[tool.commitizen]
name = "cz_conventional_commits"
Expand Down
33 changes: 32 additions & 1 deletion tests/test_env_vars.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from dataconf.exceptions import EnvListOrderException
from dataconf.exceptions import EnvListFormatException, EnvListOrderException
from dataconf.exceptions import ParseException
from dataconf.utils import __env_vars_parse as env_vars_parse
import pytest
Expand Down Expand Up @@ -65,6 +65,37 @@ def test_ls_order(self) -> None:
with pytest.raises(EnvListOrderException):
env_vars_parse("P", env)

def test_ls_obj(self) -> None:
env = {
"P_A_0__A": "1",
"P_A_1__A": "2",
}
assert env_vars_parse("P", env) == dict(a=[dict(a="1"), dict(a="2")])

env = {
"P_A_0__A": "1",
"P_A_0__B": "2",
}
assert env_vars_parse("P", env) == dict(a=[dict(a="1", b="2")])

env = {
"P_A_0__A": "1",
"P_A_0__B": "2",
"P_A_1__A": "3",
"P_A_1__B": "4",
}
assert env_vars_parse("P", env) == dict(
a=[dict(a="1", b="2"), dict(a="3", b="4")]
)

def test_ls_wrong_obj(self) -> None:
env = {
"P_A_0_A": "1",
"P_A_1_A": "2",
}
with pytest.raises(EnvListFormatException):
env_vars_parse("P", env)

def test_number(self) -> None:
env = {
"A": "1",
Expand Down

0 comments on commit b1d5980

Please sign in to comment.