8000 Escape octothorpe characters in matplotlibrc by janniklasrose · Pull Request #19289 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Escape octothorpe characters in matplotlibrc #19289

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

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,24 @@ def _open_file_or_url(fname):
yield f


def strip_comment(line):
"""Strips comments at the end of the line.
Comments start with '#' but can be escaped ('\#').
"""
splitline = line.split('#')
escaped_line = []
for i, segment in enumerate(splitline):
escape_at_end = segment.endswith('\\')
if escape_at_end and len(splitline) > i:
# this segment ended with \#
segment = segment[:-1]+'#'
escaped_line.append(segment)
if not escape_at_end:
break
parsed = ''.join(escaped_line).strip()
return parsed


def _rc_params_in_file(fname, transform=lambda x: x, fail_on_error=False):
"""
Construct a `RcParams` instance from file *fname*.
Expand All @@ -773,7 +791,7 @@ def _rc_params_in_file(fname, transform=lambda x: x, fail_on_error=False):
try:
for line_no, line in enumerate(fd, 1):
line = transform(line)
strippedline = line.split('#', 1)[0].strip()
strippedline = strip_comment(line).strip()
if not strippedline:
continue
tup = strippedline.split(':', 1)
Expand Down
0