From 66ffab6b54e62671c4027cc9322c1fa5a23a7602 Mon Sep 17 00:00:00 2001 From: Gavin Macaulay Date: Sat, 24 Aug 2024 10:47:32 +1200 Subject: [PATCH] Use tomllib if python>=3.11, tomli if not --- pyproject.toml | 4 ++-- src/echosms/referencemodels.py | 11 ++++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index c7b6fb4..8c5055a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ packages = ["src/echosms"] [project] name = 'echosms' -version = '0.1.3' +version = '0.1.4' license = {file = "LICENSE"} keywords = ["acoustic", "backscatter", "model"] authors = [ @@ -23,7 +23,7 @@ dependencies = [ "matplotlib", "pandas", "xarray", - "toml" + 'tomli >= 1.1.0; python_version < "3.11"' ] dev-dependencies = [ "mkdocstrings[python]" diff --git a/src/echosms/referencemodels.py b/src/echosms/referencemodels.py index 8e019f4..82d478d 100644 --- a/src/echosms/referencemodels.py +++ b/src/echosms/referencemodels.py @@ -1,7 +1,11 @@ """Reference model parameters.""" from pathlib import Path -import toml # Could use standard library tomllib once python >=3.11 +import sys +if sys.version_info >= (3, 11): + import tomllib +else: + import tomli as tomllib import pandas as pd pd.options.mode.copy_on_write = True @@ -25,8 +29,8 @@ def __init__(self): self.definitions = [] - with open(self.defs_filename, 'r') as f: - self.definitions = toml.load(f) + with open(self.defs_filename, 'rb') as f: + self.definitions = tomllib.load(f) # Flag duplicate target names pda = pd.Series(self.names()) @@ -98,5 +102,6 @@ def parameters(self, name): # Remove the entries that are not parameters p = s.copy() + {} [p.pop(k, None) for k in ['name', 'shape', 'description', 'source', 'benchmark_model']] return p