Skip to content

Commit 790a6bd

Browse files
committed
Bump loam version
1 parent 806a85b commit 790a6bd

File tree

8 files changed

+275
-205
lines changed

8 files changed

+275
-205
lines changed

docs/conf.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import sys
1414
import os
15+
from dataclasses import fields
1516
from pathlib import Path
1617
from textwrap import dedent
1718
from pkg_resources import get_distribution
@@ -120,7 +121,8 @@
120121
121122
These tables list configuration options.
122123
"""))
123-
for section in stagpy.conf.sections_():
124+
for sec_fld in fields(stagpy.conf):
125+
sec_name = sec_fld.name
124126
fid.write(dedent(
125127
"""
126128
.. list-table:: {}
@@ -129,14 +131,17 @@
129131
* - Name
130132
- Description
131133
- CLI, config file?
132-
""".format(section)))
133-
for opt, meta in stagpy.conf[section].defaults_():
134-
if meta.cmd_arg and meta.conf_arg:
134+
""".format(sec_name)))
135+
section = getattr(stagpy.conf, sec_name)
136+
for fld in fields(section):
137+
opt = fld.name
138+
entry = section.meta_(opt).entry
139+
if entry.in_cli and entry.in_file:
135140
c_f = 'both'
136-
elif meta.cmd_arg:
141+
elif entry.in_cli:
137142
c_f = 'CLI'
138143
else:
139144
c_f = 'config file'
140145
fid.write(' * - {}\n'.format(opt))
141-
fid.write(' - {}\n'.format(meta.help))
146+
fid.write(' - {}\n'.format(entry.doc))
142147
fid.write(' - {}\n'.format(c_f))

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ include_package_data = true
2929
packages =
3030
find:
3131
install_requires =
32-
loam>=0.5.2,<0.6.0
32+
loam>=0.6.0,<0.7.0
3333
f90nml>=1.3.1
3434
setuptools_scm>=6.3.2
3535
numpy>=1.19

stagpy/__init__.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import typing
2626

2727
from setuptools_scm import get_version
28-
from loam.manager import ConfigurationManager
2928

3029
from . import config, _styles
3130

@@ -67,7 +66,7 @@ def _check_config() -> None:
6766
if not uptodate:
6867
verfile.write_text(__version__)
6968
if not (uptodate and config.CONFIG_FILE.is_file()):
70-
conf.create_config_(update=True)
69+
conf.to_file_(config.CONFIG_FILE)
7170
for stfile in _iter_styles():
7271
stfile_conf = config.CONFIG_DIR / stfile
7372
if not (uptodate and stfile_conf.is_file()):
@@ -89,13 +88,12 @@ def _check_config() -> None:
8988
except ImportError:
9089
__version__ = "unknown"
9190

92-
_CONF_FILES = ([config.CONFIG_FILE, config.CONFIG_LOCAL]
93-
if not ISOLATED else [])
94-
conf = ConfigurationManager.from_dict_(config.CONF_DEF)
95-
conf.set_config_files_(*_CONF_FILES)
91+
conf = config.Config.default_()
9692
if not ISOLATED:
9793
_check_config()
98-
PARSING_OUT = conf.read_configs_()
94+
conf.update_from_file_(config.CONFIG_FILE)
95+
if config.CONFIG_LOCAL.is_file():
96+
conf.update_from_file_(config.CONFIG_LOCAL)
9997

10098
if not DEBUG:
10199
signal.signal(signal.SIGINT, _PREV_INT)

stagpy/args.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
import importlib.resources as imlr
77
import typing
88

9-
from loam.tools import set_conf_str, create_complete_files
9+
from loam.tools import create_complete_files
1010
from loam.cli import Subcmd, CLIManager
1111
import matplotlib.pyplot as plt
1212
import matplotlib.style as mpls
1313

1414
from . import __doc__ as doc_module
15-
from . import conf, PARSING_OUT, ISOLATED
15+
from . import conf, ISOLATED
1616
from . import (
1717
commands, config, field, rprof, time_series, refstate, plates, _styles,
1818
)
@@ -91,12 +91,6 @@ def parse_args(arglist: Optional[List[str]] = None) -> Callable[[], None]:
9191
if sub_cmd is None:
9292
return cmd_args.func
9393

94-
if sub_cmd != 'config':
95-
commands.report_parsing_problems(PARSING_OUT)
96-
97-
if conf.common.set:
98-
set_conf_str(conf, conf.common.set)
99-
10094
if conf.common.config:
10195
commands.config_pp(climan.sections_list(sub_cmd))
10296

stagpy/commands.py

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
"""Definition of non-processing subcommands."""
22

33
from __future__ import annotations
4+
from dataclasses import fields
45
from itertools import zip_longest
56
from math import ceil
67
from shutil import get_terminal_size
78
from textwrap import indent, TextWrapper
8-
import sys
99
import typing
1010

1111
import loam.tools
1212
import pandas
1313

1414
from . import conf, phyvars, __version__
1515
from . import stagyydata
16-
from .config import CONFIG_FILE, CONFIG_LOCAL
16+
from .config import CONFIG_FILE
1717
from ._helpers import baredoc
1818

1919
if typing.TYPE_CHECKING:
2020
from typing import (Sequence, Tuple, Optional, Mapping, Callable, Union,
21-
Iterable, Any)
22-
from pathlib import Path
21+
Iterable)
22+
from loam.base import Section
2323
from .datatypes import Varf, Varr, Vart
2424

2525

@@ -131,7 +131,8 @@ def var_cmd() -> None:
131131
See :mod:`stagpy.phyvars` where the lists of variables organized by command
132132
are defined.
133133
"""
134-
print_all = not any(val for _, val in conf.var.opt_vals_())
134+
print_all = not any(getattr(conf.var, fld.name)
135+
for fld in fields(conf.var))
135136
if print_all or conf.var.field:
136137
print('field:')
137138
_layout(phyvars.FIELD, phyvars.FIELD_EXTRA)
@@ -162,22 +163,6 @@ def version_cmd() -> None:
162163
print(f'stagpy version: {__version__}')
163164

164165

165-
def report_parsing_problems(
166-
parsing_out: Tuple[Any, Sequence[Path], Sequence[Path]]) -> None:
167-
"""Output message about potential parsing problems."""
168-
_, empty, faulty = parsing_out
169-
if CONFIG_FILE in empty or CONFIG_FILE in faulty:
170-
print('Unable to read global config file', CONFIG_FILE,
171-
file=sys.stderr)
172-
print('Please run stagpy config --create',
173-
sep='\n', end='\n\n', file=sys.stderr)
174-
if CONFIG_LOCAL in faulty:
175-
print('Unable to read local config file', CONFIG_LOCAL,
176-
file=sys.stderr)
177-
print('Please run stagpy config --create_local',
178-
sep='\n', end='\n\n', file=sys.stderr)
179-
180-
181166
def config_pp(subs: Iterable[str]) -> None:
182167
"""Pretty print of configuration options.
183168
@@ -187,11 +172,14 @@ def config_pp(subs: Iterable[str]) -> None:
187172
print('(c|f): available only as CLI argument/in the config file',
188173
end='\n\n')
189174
for sub in subs:
175+
section: Section = getattr(conf, sub)
190176
hlp_lst = []
191-
for opt, meta in conf[sub].defaults_():
192-
if meta.cmd_arg ^ meta.conf_arg:
193-
opt += ' (c)' if meta.cmd_arg else ' (f)'
194-
hlp_lst.append((opt, meta.help))
177+
for fld in fields(section):
178+
opt = fld.name
179+
entry = section.meta_(opt).entry
180+
if entry.in_cli ^ entry.in_file:
181+
opt += ' (c)' if entry.in_cli else ' (f)'
182+
hlp_lst.append((opt, entry.doc))
195183
if hlp_lst:
196184
print(f'{sub}:')
197185
_pretty_print(hlp_lst, sep=' -- ',
@@ -206,7 +194,6 @@ def config_cmd() -> None:
206194
conf.config
207195
"""
208196
if not (conf.common.config or conf.config.create or
209-
conf.config.create_local or conf.config.update or
210-
conf.config.edit):
211-
config_pp(conf.sections_())
212-
loam.tools.config_cmd_handler(conf)
197+
conf.config.update or conf.config.edit):
198+
config_pp(sec.name for sec in fields(conf))
199+
loam.tools.config_cmd_handler(conf, conf.config, CONFIG_FILE)

0 commit comments

Comments
 (0)