Skip to content

Cleanups #9125

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

Merged
merged 2 commits into from
Sep 1, 2017
Merged
Show file tree
Hide file tree
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
Next Next commit
rcParams always exist.
  • Loading branch information
anntzer committed Aug 30, 2017
commit ea89615810f8e00b13a7a8bb97e64da5f8a8718b
2 changes: 1 addition & 1 deletion lib/matplotlib/backends/backend_agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ def print_jpg(self, filename_or_obj, *args, **kwargs):
# The image is "pasted" onto a white background image to safely
# handle any transparency
image = Image.frombuffer('RGBA', size, buf, 'raw', 'RGBA', 0, 1)
rgba = mcolors.to_rgba(rcParams.get('savefig.facecolor', 'white'))
rgba = mcolors.to_rgba(rcParams['savefig.facecolor'])
color = tuple([int(x * 255.0) for x in rgba[:3]])
background = Image.new('RGB', size, color)
background.paste(image, image)
Expand Down
20 changes: 9 additions & 11 deletions lib/matplotlib/backends/backend_pgf.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
def get_texcommand():
"""Get chosen TeX system from rc."""
texsystem_options = ["xelatex", "lualatex", "pdflatex"]
texsystem = rcParams.get("pgf.texsystem", "xelatex")
texsystem = rcParams["pgf.texsystem"]
return texsystem if texsystem in texsystem_options else "xelatex"


Expand All @@ -68,7 +68,7 @@ def get_fontspec():
if texcommand != "pdflatex":
latex_fontspec.append("\\usepackage{fontspec}")

if texcommand != "pdflatex" and rcParams.get("pgf.rcfonts", True):
if texcommand != "pdflatex" and rcParams["pgf.rcfonts"]:
# try to find fonts from rc parameters
families = ["serif", "sans-serif", "monospace"]
fontspecs = [r"\setmainfont{%s}", r"\setsansfont{%s}",
Expand All @@ -86,10 +86,7 @@ def get_fontspec():

def get_preamble():
"""Get LaTeX preamble from rc."""
latex_preamble = rcParams.get("pgf.preamble", "")
if type(latex_preamble) == list:
latex_preamble = "\n".join(latex_preamble)
return latex_preamble
return "\n".join(rcParams["pgf.preamble"])

###############################################################################

Expand Down Expand Up @@ -223,13 +220,14 @@ def get_latex_manager():
latex_header = LatexManager._build_latex_header()
prev = LatexManagerFactory.previous_instance

# check if the previous instance of LatexManager can be reused
if prev and prev.latex_header == latex_header and prev.texcommand == texcommand:
if rcParams.get("pgf.debug", False):
# Check if the previous instance of LatexManager can be reused.
if (prev and prev.latex_header == latex_header
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

order of operations unclear here (and yes I know was unclear previously too), what about instead using parenthesis around each == pair?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is pretty well known that "and" and "or" have lower priority than comparison operators. Relying on this basically occurs everywhere throughout the codebase.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shrugs I never remember this stuff, but not gonna hold up the review over it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

explicit is better than implicit, but too many () can also make it confusing by adding to visual noise. In this case I think it is ok without ()

and prev.texcommand == texcommand):
if rcParams["pgf.debug"]:
print("reusing LatexManager")
return prev
else:
if rcParams.get("pgf.debug", False):
if rcParams["pgf.debug"]:
print("creating LatexManager")
new_inst = LatexManager()
LatexManagerFactory.previous_instance = new_inst
Expand Down Expand Up @@ -289,7 +287,7 @@ def __init__(self):
# store references for __del__
self._os_path = os.path
self._shutil = shutil
self._debug = rcParams.get("pgf.debug", False)
self._debug = rcParams["pgf.debug"]

# create a tmp directory for running latex, remember to cleanup
self.tmpdir = tempfile.mkdtemp(prefix="mpl_pgf_lm_")
Expand Down