<commit_before>"""
Python module defining classes for creating more versatile figures

This code and information is provided 'as is' without warranty of any kind,
either express or implied, including, but not limited to, the implied
warranties of non-infringement, merchantability or fitness for a particular
purpose.
"""

from __future__ import division

import itertools
import logging
import os
import subprocess
from contextlib import contextmanager

import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
from matplotlib.figure import Figure
from six.moves import range

from . import style



GOLDEN_MEAN = 2/(np.sqrt(5) - 1)
INCHES_PER_PT = 1.0/72.27  # Convert pt to inch



def crop_pdf_file(file_input, file_output=None, silence_output=True):
    """ crops the pdf in the input file using the tool `pdfcrop`. If
    `file_output` is not given, the input file is overwritten. `silence_output`
    determines whether the output of the program is shown on the standard
    output
    """
    if file_output is None:
        file_output = file_input 
    
    cmd = ['pdfcrop', str(file_input), str(file_output)]
    
    if silence_output:
        try:
            from subprocess import DEVNULL  # py3k
        except ImportError:
            DEVNULL = open(os.devnull, 'wb')
        subprocess.check_call(cmd, stdout=DEVNULL, stderr=subprocess.STDOUT)
        
    else:
        subprocess.check_call(cmd)



class FigureBase(Figure):
    """ Extended version of a matplotlib figure """

    # factors used to determine the preferred number of ticks in each direction
    xtick_factor = 0.66
    ytick_factor = 1.

    def __init__(self, **kwargs):
        self.backend_old = None

        # read parameters
        self.transparent = kwargs.pop('transparent', None)
        self.verbose = kwargs.pop('verbose', False)
        self._logger = logging.getLogger(__name__)

        backend = kwargs.pop('backend', None)<commit_msg>Improved message when `pdfcrop` is not present<commit_after>"""
Python module defining classes for creating more versatile figures

This code and information is provided 'as is' without warranty of any kind,
either express or implied, including, but not limited to, the implied
warranties of non-infringement, merchantability or fitness for a particular
purpose.
"""

from __future__ import division

import itertools
import logging
import os
import subprocess
from contextlib import contextmanager

import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
from matplotlib.figure import Figure
from six.moves import range

from . import style



GOLDEN_MEAN = 2/(np.sqrt(5) - 1)
INCHES_PER_PT = 1.0/72.27  # Convert pt to inch



def crop_pdf_file(file_input, file_output=None, silence_output=True):
    """ crops the pdf in the input file using the tool `pdfcrop`. If
    `file_output` is not given, the input file is overwritten. `silence_output`
    determines whether the output of the program is shown on the standard
    output
    """
    if file_output is None:
        file_output = file_input
    
    cmd = ['pdfcrop', str(file_input), str(file_output)]
    
    if silence_output:
        try:
            from subprocess import DEVNULL  # py3k
        except ImportError:
            DEVNULL = open(os.devnull, 'wb')
        try:
            subprocess.check_call(cmd, stdout=DEVNULL, stderr=subprocess.STDOUT)
        except FileNotFoundError as err:
            msg = str(err)
            if 'pdfcrop' in msg:
                raise FileNotFoundError(
                    "`pdfcrop` does seem to be missing. This tool is for "
                    "instance contained in the `texlive-bin-extra` package "
                    "of macports. The original error was: " + msg)
            else:
                raise  # Unknown error has been raised
        
    else:
        subprocess.check_call(cmd)



class FigureBase(Figure):
    """ Extended version of a matplotlib figure """

    # factors used to determine the preferred number of ticks in each direction
    xtick_factor = 0.66
    ytick_factor = 1.

    def __init__(self, **kwargs):
        self.backend_old = None

        # read parameters
        self.transparent = kwargs.pop('transparent', None)
        self.verbose = kwargs.pop('verbose', False)
        self._logger = logging.getLogger(__name__)

        backend = kwargs.pop('backend', None)
{'fraction_non_alphanumeric': 0.07228915662650602, 'fraction_numerical': 0.006365082973403046, 'mean_word_length': 2.907637655417407, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1521199', 'n_tokens_mistral': 1277, 'n_tokens_neox': 1220, 'n_words': 450}