Skip to content

Commit

Permalink
Merge pull request #398 from neutrinoceros/dep/bump_inifix
Browse files Browse the repository at this point in the history
DEP: require inifix 5.1.0 or newer, fix newly detected type-checking errors
  • Loading branch information
neutrinoceros authored Dec 15, 2024
2 parents 94df00f + f3a0833 commit eef407a
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 29 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ classifiers = [
]
requires-python = ">=3.10"
dependencies = [
"inifix>=4.2.2",
"inifix>=5.1.0",
"packaging>=21.0",
"termcolor>=2.3.0",
"typing-extensions>=4.1.0;python_version < '3.11'",
Expand Down
36 changes: 15 additions & 21 deletions src/idefix_cli/_commands/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,17 +309,18 @@ def command(
return 1

with open(pinifile, "rb") as fh:
conf = inifix.load(fh)
try:
conf = inifix.load(fh, sections="require", parse_scalars_as_lists=True)
except ValueError as exc:
print_error(
"configuration file seems malformed. "
f"The following exception was raised\n{exc}"
)
return 1
base_conf = deepcopy(conf)

# conf type validation
conf.setdefault("TimeIntegrator", {})
if not isinstance(conf["TimeIntegrator"], dict):
print_error(
"configuration file seems malformed, "
"expected 'TimeIntegrator' to be a section title, not a parameter name."
)
return 1

if outputs and "-maxcycles" not in unknown_args:
print_error("--out requires -maxcycles")
Expand All @@ -335,28 +336,21 @@ def command(
if outputs:
output_types = set(outputs) - {"log"}
if time_step is None:
conf["TimeIntegrator"].setdefault("first_dt", 1e-6)
time_step = conf["TimeIntegrator"]["first_dt"]
conf["TimeIntegrator"].setdefault("first_dt", [1e-6])
time_step = float(conf["TimeIntegrator"]["first_dt"][0])

conf.setdefault("Output", {})
output_sec = conf["Output"]
if not isinstance(output_sec, dict):
print_error(
"configuration file seems malformed, "
"expected 'Output' to be a section title, not a parameter name."
)
return 1

output_sec["log"] = 1
output_sec["log"] = [1]

if len(output_types) > 0:
for entry in output_types:
output_sec[entry] = 0 # output on every time step
output_sec[entry] = [0] # output on every time step

if time_step is not None:
conf["TimeIntegrator"]["first_dt"] = time_step
conf["TimeIntegrator"]["first_dt"] = [time_step]
if tstop is not None:
conf["TimeIntegrator"]["tstop"] = tstop
conf["TimeIntegrator"]["tstop"] = [tstop]

rebuild_mode_str: str = get_option("idfx run", "recompile") or "always"

Expand Down Expand Up @@ -435,7 +429,7 @@ def command(
if conf != base_conf:
tmp_inifile = NamedTemporaryFile()
with open(tmp_inifile.name, "wb") as fh:
inifix.dump(conf, fh)
inifix.dump(conf, fh, sections="require")
inputfile = tmp_inifile.name
else:
inputfile = str(pinifile.relative_to(d.resolve()))
Expand Down
4 changes: 2 additions & 2 deletions src/idefix_cli/_commands/write.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def command(dest: str, source, force: bool = False) -> int:
return 1

try:
inifix.validate_inifile_schema(data)
inifix.validate_inifile_schema(data, sections="require")
except ValueError:
print_error("input is not Pluto inifile format compliant.")
return 1
Expand All @@ -50,6 +50,6 @@ def command(dest: str, source, force: bool = False) -> int:
return 1

with open(pdest, "wb") as fh:
inifix.dump(data, fh)
inifix.dump(data, fh, sections="require")

return 0
2 changes: 1 addition & 1 deletion src/idefix_cli/_theme.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Theme:


class ThemeRegistry:
def __init__(self):
def __init__(self) -> None:
self._registry: dict[str, Theme] = {}

def register(
Expand Down
11 changes: 7 additions & 4 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit eef407a

Please sign in to comment.