You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm building a developer tool that generates code. The code we want to generate should be formatted according to black. The only way I've found to do that until now has been to write the new file to disk and then call black executable to format the file. But this seems pretty unnecessary and wasteful in time and performance.
It could be much better if I could just call black through some python library/API function and provide it a string variable with the unformatted python code. I would expect it to return a formatted code. Is this something black implements already somehow? If not, this could be pretty useful for developer tools to interface with black directly without involving a disk write.
The text was updated successfully, but these errors were encountered:
Look at the functions in black/__init__.py, they can do what you want, e.g. see format_str. Just know that Black doesn't currently provide any backward compatibility guarantees for these APIs.
I'm building a developer tool that generates code. The code we want to generate should be formatted according to black. The only way I've found to do that until now has been to write the new file to disk and then call black executable to format the file. But this seems pretty unnecessary and wasteful in time and performance.
It could be much better if I could just call black through some python library/API function and provide it a string variable with the unformatted python code. I would expect it to return a formatted code. Is this something black implements already somehow? If not, this could be pretty useful for developer tools to interface with black directly without involving a disk write.
The text was updated successfully, but these errors were encountered: