Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement from_namelist method #43

Merged
merged 28 commits into from
Jul 5, 2021
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
3791e8f
Introduce namelists in the accessor
malmans2 Jun 24, 2021
5375197
Merge branch 'namelists' of https://github.com/malmans2/pyDOMCFG into…
malmans2 Jun 24, 2021
76b1722
Untested, but the main implementation should be in good shape
malmans2 Jun 24, 2021
71d11e5
use class variable introduced
malmans2 Jun 24, 2021
e074650
add tests
malmans2 Jun 24, 2021
749c16a
accessor now handles 999999
malmans2 Jun 25, 2021
b1a3c0e
Update accessor.py
jdha Jun 25, 2021
0da64b5
Merge branch 'pyNEMO:main' into namelists
malmans2 Jun 28, 2021
8ac4c72
introduce _check_namelist_entries
malmans2 Jun 28, 2021
72f0434
typo
malmans2 Jun 28, 2021
4dc3417
tidy up namelist check
malmans2 Jun 28, 2021
82ca98d
add type hints
malmans2 Jun 28, 2021
2a1d06b
minor semplification
malmans2 Jun 29, 2021
c0dfd5c
add more checks
malmans2 Jul 1, 2021
52ac3fb
let Zco handle checks
malmans2 Jul 1, 2021
066adce
deprecate ldbletanh
malmans2 Jul 1, 2021
c68bdf7
fix comment
malmans2 Jul 1, 2021
a9ecfe5
better error print
malmans2 Jul 1, 2021
9f7e188
decorate __call__
malmans2 Jul 2, 2021
54e1b24
clean utils
malmans2 Jul 2, 2021
4b7578d
add tests
malmans2 Jul 2, 2021
2dc3e23
use None
malmans2 Jul 2, 2021
271d7cd
ready for review
malmans2 Jul 5, 2021
501c120
Merge branch 'pyNEMO:main' into namelists
malmans2 Jul 5, 2021
abdb9f2
fix doc and ci
malmans2 Jul 5, 2021
c485512
qqMerge branch 'namelists' of https://github.com/malmans2/pyDOMCFG in…
malmans2 Jul 5, 2021
18b82fa
better docs
malmans2 Jul 5, 2021
2165ab7
avoid numpy with type hint bug
malmans2 Jul 5, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 35 additions & 0 deletions pydomcfg/accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,39 @@ def _namelist_parser(
f" {mutually_exclusive}"
)

# Rudimentary checks on namelist entries
for key, val in chained.items():

# NB if there are duplicate keys in the namelist (within the same namblock)
# nmlf90 will represent this as a list of length 1
if hasattr(val, "__len__") and len(val)==1:
raise TypeError('Possible duplication of namelist variable '+key)
malmans2 marked this conversation as resolved.
Show resolved Hide resolved

item_switcher = {'ln': bool, 'nn': int, 'rn': float, 'cn': str,
'sn': [str, int, str, bool, bool, str, str, str, str]}
malmans2 marked this conversation as resolved.
Show resolved Hide resolved
key_prefix = key[0:2]
errmsg_mis = 'Mismatch in number of values provided for '+key
errmsg_val = 'Value does not match expected type for '+key

# Check the namelist key
try:
key_type = item_switcher.get(key_prefix)
except KeyError:
print('Namelist variable '+key+' not recognised')
malmans2 marked this conversation as resolved.
Show resolved Hide resolved

# Check number of values
if hasattr(val, "__len__") != hasattr(key_type, "__len__"):
raise TypeError(errmsg_mis)
malmans2 marked this conversation as resolved.
Show resolved Hide resolved

# Check number of values for sn
if key_prefix=='sn' and ( len(key_type) != len(val) ):
raise TypeError(errmsg_mis)

# Check type
if key_prefix=='sn':
if key_type != list(type(element) for element in val):
raise TypeError(errmsg_val)
elif key_type != type(val):
raise TypeError(errmsg_val)
malmans2 marked this conversation as resolved.
Show resolved Hide resolved

return chained