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

Can't set indentation when patching #79

Open
letmaik opened this issue May 28, 2018 · 7 comments
Open

Can't set indentation when patching #79

letmaik opened this issue May 28, 2018 · 7 comments

Comments

@letmaik
Copy link
Contributor

letmaik commented May 28, 2018

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.

@marshallward
Copy link
Owner

marshallward commented May 28, 2018

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

@letmaik
Copy link
Contributor Author

letmaik commented May 28, 2018

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

@marshallward
Copy link
Owner

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

@marshallward
Copy link
Owner

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.)

@letmaik
Copy link
Contributor Author

letmaik commented May 29, 2018

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

@marshallward
Copy link
Owner

marshallward commented May 30, 2018

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
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants