You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
matplotlibrc reader cannot handle rcparams with a hash #7089
The parser for the .mplstyle files is eager when identifying comments. A # always demarcates the beginning of a comment, therefore it cannot be part of an rcparam.
not json... and yaml brings in another dependency (but it isn't that
onoerous...). ConfigParser is now in the standard library, and it could
bring for us string interpolation features (which I have been wanting for a
while).
It doesn't look to me like ConfigParser provides facilities for gracefully handling the problem of an inline hash that starts a comment unless it is inside a string. YAML looks like a pretty big hammer. I think I would rather leave the existing restriction against having the hash in a value than introduce a new dependency and a new set of rules for matplotlibrc and style files.
It doesn't look to me like ConfigParser provides facilities for gracefully
handling the problem of an inline hash that starts a comment unless it is
inside a string. YAML looks like a pretty big hammer. I think I would
rather leave the existing restriction against having the hash in a value
than introduce a new dependency and a new set of rules for matplotlibrc and
style files.
I'm going to make a possibly not so popular but actually serious proposal: if we do decide to change the config format, simply switch to using python source files as style and config formats.
Pros:
No extra dependency, interpolation, inline comments (duh).
Basically anything you will ever need.
Cons:
AFAICT the main con I have heard about is the security issue. But the current parser is already unsafe (See link from OP in #6274 (Yes, I know that PR also proposes a custom PyParsing-based parser -- I guess that would be a pretty big hammer...)). Additionally, a number of prominent projects (e.g. IPython, Sphinx, Django) already use python for config files without this turning out to be a real problem.
Why not just make yaml an optional parser for the matplotlibrc reader, if installed? The amount of code to read into the rc system is minimal, and we could integrate them more closely over time if needed.
I've already made a basic parser for this type of data for use in a project, it seems to work fine for basic datasets:
YAML is a pretty standard config language for many projects, and trying to reinvent the wheel when a standard tool can be adapted to the system is unnecessary.
@anntzer: we don't have to support the entire feature-set of YAML or handle edge cases for it to be useful nonetheless
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!
Activity
tacaswell commentedon Sep 11, 2016
Maybe we should just use json or yaml for the style files?
WeatherGod commentedon Sep 11, 2016
not json... and yaml brings in another dependency (but it isn't that
onoerous...). ConfigParser is now in the standard library, and it could
bring for us string interpolation features (which I have been wanting for a
while).
On Sun, Sep 11, 2016 at 12:02 PM, Thomas A Caswell <notifications@github.com
[-]matplotlibrc reader cannot rcparams with a hash[/-][+]matplotlibrc reader cannot handle rcparams with a hash[/+]has2k1 commentedon Sep 11, 2016
Comparison of potential options.
Caveats
efiring commentedon Sep 11, 2016
It doesn't look to me like ConfigParser provides facilities for gracefully handling the problem of an inline hash that starts a comment unless it is inside a string. YAML looks like a pretty big hammer. I think I would rather leave the existing restriction against having the hash in a value than introduce a new dependency and a new set of rules for matplotlibrc and style files.
WeatherGod commentedon Sep 11, 2016
JSON can not support inline comments
On Sun, Sep 11, 2016 at 2:07 PM, Eric Firing notifications@github.com
wrote:
anntzer commentedon Sep 12, 2016
I'm going to make a possibly not so popular but actually serious proposal: if we do decide to change the config format, simply switch to using python source files as style and config formats.
Pros:
No extra dependency, interpolation, inline comments (duh).
Basically anything you will ever need.
Cons:
AFAICT the main con I have heard about is the security issue. But the current parser is already unsafe (See link from OP in #6274 (Yes, I know that PR also proposes a custom PyParsing-based parser -- I guess that would be a pretty big hammer...)). Additionally, a number of prominent projects (e.g. IPython, Sphinx, Django) already use python for config files without this turning out to be a real problem.
jenshnielsen commentedon Sep 12, 2016
This should also be coordinated with the traitlets work #4762 Afaik the IPython config files are traitlets based
davenquinn commentedon Apr 15, 2017
Why not just make yaml an optional parser for the matplotlibrc reader, if installed? The amount of code to read into the rc system is minimal, and we could integrate them more closely over time if needed.
I've already made a basic parser for this type of data for use in a project, it seems to work fine for basic datasets:
...which reads YAML configuration files as below into matplotlibrc.
A more bulletproof parser would probably take some effort, but I imagine not much. Happy to submit a pr if it seems like a good plan.
anntzer commentedon Apr 15, 2017
My personal opinion is that yaml is a far too complex language for any purpose (see e.g. http://stackoverflow.com/questions/3790454/in-yaml-how-do-i-break-a-string-over-multiple-lines).
WeatherGod commentedon Apr 16, 2017
anntzer commentedon Apr 16, 2017
This is just an example amongst others of the extreme complexity of the language. For example, would you know whether
is valid yaml? if so, what does it evaluate to? what about
?
davenquinn commentedon Apr 16, 2017
YAML is a pretty standard config language for many projects, and trying to reinvent the wheel when a standard tool can be adapted to the system is unnecessary.
@anntzer: we don't have to support the entire feature-set of YAML or handle edge cases for it to be useful nonetheless
github-actions commentedon Mar 29, 2023
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!
oscargus commentedon Apr 7, 2023
In #22589 support for quoted strings was introduced, which then allows including a hash. Will close this for now.