f90nml icon indicating copy to clipboard operation
f90nml copied to clipboard

Can't set indentation when patching

Open letmaik opened this issue 7 years ago • 7 comments

The indentation option can currently only be set when constructing a Namelist object. However, for the case when you want to patch a file, then there's no way to set the indent option to be used for the ouput patch file.

letmaik avatar May 28 '18 10:05 letmaik

I'm confused about this comment, because f90nml.patch is for replacing name-value strings inside an existing file, meaning that it should not actually change or modify the whitespace or any indentation. Sometimes the substitution can look a bit odd, but that would not be addressed by the indentation of Namelist.

Can you show me what you're trying to do, and why you want to use patch and need to change the in

marshallward avatar May 28 '18 10:05 marshallward

With patch you can also add new keys, and for those it uses the default indentation.

letmaik avatar May 28 '18 11:05 letmaik

Right, thanks, that makes sense. Hopefully not too difficult to implement.

marshallward avatar May 29 '18 01:05 marshallward

I've added a patch which adds this feature. It should be added at the top (namelists) level:

patch = {
    'a_grp': {
        'x': 1,
        'y': 2,
    }
    '_indent': '\t'
}

Hopefully this should work for you.

I experimented a bit with also permitting it at the group level, but it wasn't clear how to fallback to the namelist level if unset. (Note: #81 would presumably address this, but not yet sure if it's worth implementing this idea.)

marshallward avatar May 29 '18 13:05 marshallward

Looks good! What happens if I include _indent in a version of f90nml that doesn't support this feature yet? Is it silently ignored?

letmaik avatar May 29 '18 18:05 letmaik

I haven't checked, but fairly sure it will create an empty group named _delete, which may or may not be ignored by the Fortran runtime.

In any case, I probably ought to do another pypi update soon, though it would be good to at least have a crack at the current outstanding issues around patching :).

marshallward avatar May 30 '18 01:05 marshallward

Actually, it seems it won't have any effect in older versions, since (as mentioned in #80) new content is simply ignored by patch.

marshallward avatar May 30 '18 01:05 marshallward