Skip to content

Commit

Permalink
Use tomllib if python>=3.11, tomli if not
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinmacaulay committed Aug 23, 2024
1 parent 8af101e commit 66ffab6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -23,7 +23,7 @@ dependencies = [
"matplotlib",
"pandas",
"xarray",
"toml"
'tomli >= 1.1.0; python_version < "3.11"'
]
dev-dependencies = [
"mkdocstrings[python]"
Expand Down
11 changes: 8 additions & 3 deletions src/echosms/referencemodels.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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())
Expand Down Expand Up @@ -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

0 comments on commit 66ffab6

Please sign in to comment.