1919from inspect import Parameter
2020from pathlib import Path
2121import sys
22- import textwrap
22+ import subprocess
23+
2324
2425# This line imports the installed copy of matplotlib, and not the local copy.
2526import numpy as np
@@ -151,10 +152,6 @@ def generate_function(name, called_fullname, template, **kwargs):
151152 **kwargs
152153 Additional parameters are passed to ``template.format()``.
153154 """
154- text_wrapper = textwrap .TextWrapper (
155- break_long_words = False , width = 70 ,
156- initial_indent = ' ' * 8 , subsequent_indent = ' ' * 8 )
157-
158155 # Get signature of wrapped function.
159156 class_name , called_name = called_fullname .split ('.' )
160157 class_ = {'Axes' : Axes , 'Figure' : Figure }[class_name ]
@@ -175,9 +172,6 @@ def generate_function(name, called_fullname, template, **kwargs):
175172 param .replace (default = value_formatter (param .default ))
176173 if param .default is not param .empty else param
177174 for param in params ]))
178- if len ('def ' + name + signature ) >= 80 and False :
179- # Move opening parenthesis before newline.
180- signature = '(\n ' + text_wrapper .fill (signature ).replace ('(' , '' , 1 )
181175 # How to call the wrapped function.
182176 call = '(' + ', ' .join ((
183177 # Pass "intended-as-positional" parameters positionally to avoid
@@ -189,9 +183,6 @@ def generate_function(name, called_fullname, template, **kwargs):
189183 # Only pass the data kwarg if it is actually set, to avoid forcing
190184 # third-party subclasses to support it.
191185 '**({{"data": data}} if data is not None else {{}})'
192- # Avoid linebreaks in the middle of the expression, by using \0 as a
193- # placeholder that will be substituted after wrapping.
194- .replace (' ' , '\0 ' )
195186 if param .name == "data" else
196187 '{0}={0}'
197188 if param .kind in [
@@ -205,9 +196,6 @@ def generate_function(name, called_fullname, template, **kwargs):
205196 if param .kind is Parameter .VAR_KEYWORD else
206197 None ).format (param .name )
207198 for param in params ) + ')'
208- MAX_CALL_PREFIX = 18 # len(' __ret = gca().')
209- if MAX_CALL_PREFIX + max (len (name ), len (called_name )) + len (call ) >= 80 :
210- call = '(\n ' + text_wrapper .fill (call [1 :]).replace ('\0 ' , ' ' )
211199 # Bail out in case of name collision.
212200 for reserved in ('gca' , 'gci' , 'gcf' , '__ret' ):
213201 if reserved in params :
@@ -395,6 +383,11 @@ def build_pyplot(pyplot_path):
395383 pyplot .writelines (pyplot_orig )
396384 pyplot .writelines (boilerplate_gen ())
397385
386+ # Run black to autoformat pyplot
387+ subprocess .run (
388+ [sys .executable , "-m" , "black" , "--line-length=79" , pyplot_path ]
389+ )
390+
398391
399392### Methods for retrieving signatures from pyi stub files
400393
0 commit comments