diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index a0e3ba7..922b616 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -18,7 +18,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.8", "3.9", "3.10", "3.11"] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] steps: - name: Checkout diff --git a/config/__init__.py b/config/__init__.py index 0e2393b..23b2dd3 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -12,19 +12,15 @@ except ImportError: # pragma: no cover yaml = None -if sys.version_info[1] < 11: +if sys.version_info < (3, 11): # pragma: no cover try: - import toml + import tomli as toml - toml_readtype = "rt" - except ImportError: # pragma: no cover - toml = None - toml_readtype = "" -else: + except ImportError: + toml = None # type: ignore +else: # pragma: no cover import tomllib as toml - toml_readtype = "rb" - from .configuration import Configuration from .configuration_set import ConfigurationSet @@ -871,7 +867,7 @@ def _reload(self, data: Union[str, TextIO], read_from_file: bool = False) -> Non """Reload the TOML data.""" if read_from_file: if isinstance(data, str): - with open(data, toml_readtype) as f: + with open(data, "rb") as f: loaded = toml.load(f) else: loaded = toml.load(data) # type: ignore [arg-type,unused-ignore] diff --git a/pyproject.toml b/pyproject.toml index 48d61d7..d3afd77 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,10 +17,10 @@ azure-identity = { version = "^1.13.0", optional = true } azure-keyvault = { version = "^4.2.0", optional = true } boto3 = { version = "^1.28.20", optional = true } google-cloud-secret-manager = { version = "^2.16.3", optional = true } -hvac = { version ="^1.1.1", optional = true } +hvac = { version = "^1.1.1", optional = true } pyyaml = { version = "^6.0", optional = true } -toml = { version = "^0.10.0", optional = true } jsonschema = { version = "^4.18.6", optional = true } +tomli = { version = "^2.0.1", optional = true } [tool.poetry.group.dev.dependencies] mypy = "^1.4.1" @@ -40,14 +40,28 @@ pytest-ruff = "^0.2.1" aws = ["boto3"] azure = ["azure-keyvault", "azure-identity"] gcp = ["google-cloud-secret-manager"] -toml = ["toml"] +toml = ["tomli"] vault = ["hvac"] yaml = ["pyyaml"] validation = ["jsonschema"] [tool.ruff] line-length = 88 -select = ['F', 'E', 'W', 'I', 'N', 'D', 'B', 'A', 'COM', 'C4', 'T20', 'Q', 'SIM'] +select = [ + 'F', + 'E', + 'W', + 'I', + 'N', + 'D', + 'B', + 'A', + 'COM', + 'C4', + 'T20', + 'Q', + 'SIM', +] exclude = ["tests", "docs"] @@ -55,7 +69,7 @@ exclude = ["tests", "docs"] legacy_tox_ini = """ [tox] isolated_build = true -envlist = py38, py39, py310, py311 +envlist = py38, py39, py310, py311, py312 [testenv] allowlist_externals = poetry @@ -76,29 +90,25 @@ disallow_untyped_decorators = true no_implicit_optional = true warn_unused_ignores = true warn_redundant_casts = true -exclude = [ - 'tests' -] +exclude = ['tests'] [[tool.mypy.overrides]] -module= [ - 'google.auth.credentials', - 'yaml', - 'toml', +module = [ + 'google.auth.credentials', + 'yaml', + 'toml', 'boto3', - 'botocore.exceptions', + 'botocore.exceptions', 'hvac', 'hvac.exceptions', 'jsonschema', - 'jsonschema.exceptions' + 'jsonschema.exceptions', ] ignore_missing_imports = true [tool.coverage.run] branch = true -include = [ - 'config/*' -] +include = ['config/*'] [tool.coverage.html] directory = 'cover' @@ -106,10 +116,10 @@ directory = 'cover' [tool.pytest.ini_options] minversion = "6.0" addopts = '--cov --cov-report=html --cov-report term-missing --ruff --mypy --black' -filterwarnings =[ +filterwarnings = [ 'ignore::pytest.PytestDeprecationWarning', 'ignore::DeprecationWarning', - 'ignore::pytest.PytestWarning' + 'ignore::pytest.PytestWarning', ] [build-system] diff --git a/tests/test_toml.py b/tests/test_toml.py index 2d6a1aa..44839cd 100644 --- a/tests/test_toml.py +++ b/tests/test_toml.py @@ -78,16 +78,7 @@ def test_load_toml_file(): # type: ignore with tempfile.NamedTemporaryFile() as f: f.file.write(TOML.encode()) f.file.flush() - - # Two different toml libraries are in use - import sys - - if sys.version_info[1] < 11: - read_type = "rt" - else: - read_type = "rb" - - cfg = config_from_toml(open(f.name, read_type), read_from_file=True) + cfg = config_from_toml(open(f.name, "rb"), read_from_file=True) assert cfg["a1.b1.c1"] == 1 assert cfg["a1.b1"].as_dict() == {"c1": 1, "c2": 2, "c3": 3} assert cfg["a1.b2"].as_dict() == {"c1": "a", "c2": True, "c3": 1.1}