19
19
from inspect import Parameter
20
20
from pathlib import Path
21
21
import sys
22
- import textwrap
22
+ import subprocess
23
+
23
24
24
25
# This line imports the installed copy of matplotlib, and not the local copy.
25
26
import numpy as np
@@ -151,10 +152,6 @@ def generate_function(name, called_fullname, template, **kwargs):
151
152
**kwargs
152
153
Additional parameters are passed to ``template.format()``.
153
154
"""
154
- text_wrapper = textwrap .TextWrapper (
155
- break_long_words = False , width = 70 ,
156
- initial_indent = ' ' * 8 , subsequent_indent = ' ' * 8 )
157
-
158
155
# Get signature of wrapped function.
159
156
class_name , called_name = called_fullname .split ('.' )
160
157
class_ = {'Axes' : Axes , 'Figure' : Figure }[class_name ]
@@ -175,9 +172,6 @@ def generate_function(name, called_fullname, template, **kwargs):
175
172
param .replace (default = value_formatter (param .default ))
176
173
if param .default is not param .empty else param
177
174
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 )
181
175
# How to call the wrapped function.
182
176
call = '(' + ', ' .join ((
183
177
# Pass "intended-as-positional" parameters positionally to avoid
@@ -189,9 +183,6 @@ def generate_function(name, called_fullname, template, **kwargs):
189
183
# Only pass the data kwarg if it is actually set, to avoid forcing
190
184
# third-party subclasses to support it.
191
185
'**({{"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 ' )
195
186
if param .name == "data" else
196
187
'{0}={0}'
197
188
if param .kind in [
@@ -205,9 +196,6 @@ def generate_function(name, called_fullname, template, **kwargs):
205
196
if param .kind is Parameter .VAR_KEYWORD else
206
197
None ).format (param .name )
207
198
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 ' , ' ' )
211
199
# Bail out in case of name collision.
212
200
for reserved in ('gca' , 'gci' , 'gcf' , '__ret' ):
213
201
if reserved in params :
@@ -395,6 +383,11 @@ def build_pyplot(pyplot_path):
395
383
pyplot .writelines (pyplot_orig )
396
384
pyplot .writelines (boilerplate_gen ())
397
385
386
+ # Run black to autoformat pyplot
387
+ subprocess .run (
388
+ [sys .executable , "-m" , "black" , "--line-length=79" , pyplot_path ]
389
+ )
390
+
398
391
399
392
### Methods for retrieving signatures from pyi stub files
400
393
0 commit comments